Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backtest.py - neatgrid - Division by zero #344

Open
ilaykim opened this issue Jul 11, 2022 · 3 comments
Open

backtest.py - neatgrid - Division by zero #344

ilaykim opened this issue Jul 11, 2022 · 3 comments

Comments

@ilaykim
Copy link

ilaykim commented Jul 11, 2022

**Really weird, only managed to catch this on SOLUSDT on Neat Grid.

tried refreshing tick data, didn't work.
OHCLV - same issue
different json - same issue**

different symbol - works
short disabled - works
long disabled - DOESN'T WORK

python3 backtest.py D:\bot\psv57\configs\sol_655days.json -s SOLUSDT -b D:\bot\psv57\configs\backtest\sol_2M.hjson

using numba
using numba
using numba
fetching market_specific_settings...
linear perpetual

exchange binance
spot False
symbol SOLUSDT
market_type futures
starting_balance 1000
start_date 2022-05-09
end_date 2022-07-09
latency_simulation_ms 1000
base_dir backtests

2022-07-11T07:08:31 Loading cached tick data from backtests\binance\SOLUSDT\caches\2022-05-09_2022-07-09_ticks_cache.npy
{'config_name': 'neat_grid_SOLUSDT_655days',
'logging_level': 0,
'long': {'auto_unstuck_ema_dist': 0,
'auto_unstuck_wallet_exposure_threshold': 0,
'backwards_tp': True,
'ema_span_0': 120.62199728529626,
'ema_span_1': 34.76100179121808,
'enabled': True,
'eprice_exp_base': 1.1618608307844618,
'eqty_exp_base': 2.7802305422341758,
'grid_span': 0.17566515453113268,
'initial_eprice_ema_dist': -0.09535081461351516,
'initial_qty_pct': 0.014571840796302686,
'markup_range': 0.009421624486160773,
'max_n_entry_orders': 8,
'min_markup': 0.002,
'n_close_orders': 9,
'wallet_exposure_limit': 0.8},
'short': {'auto_unstuck_ema_dist': 0,
'auto_unstuck_wallet_exposure_threshold': 0,
'backwards_tp': True,
'ema_span_0': 4237.55904931995,
'ema_span_1': 9054.894470988955,
'enabled': True,
'eprice_exp_base': 1.161340927050355,
'eqty_exp_base': 3,
'grid_span': 0.4209059738318962,
'initial_eprice_ema_dist': -0.03917532734094498,
'initial_qty_pct': 0.04879303398638066,
'markup_range': 0.03261166232435841,
'max_n_entry_orders': 13,
'min_markup': 0.012619198687759918,
'n_close_orders': 17,
'wallet_exposure_limit': 0.2}}
n_days 61.0
starting_balance 1000
backtesting...
Traceback (most recent call last):
File "D:\bot\psv57\backtest.py", line 219, in
asyncio.run(main())
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 647, in run_until_complete
return future.result()
File "D:\bot\psv57\backtest.py", line 215, in main
plot_wrap(config, data)
File "D:\bot\psv57\backtest.py", line 68, in plot_wrap
fills_long, fills_short, stats = backtest(config, data, do_print=True)
File "D:\bot\psv57\backtest.py", line 47, in backtest
return backtest_neat_grid(
ZeroDivisionError: division by zero

@donewiththedollar
Copy link

Hey try a higher start balance in your backtest config. ie. 10000

That should solve the issue :)

@ilaykim
Copy link
Author

ilaykim commented Jul 11, 2022

That solves the issue.

btw I've been debugging this for a good 4 hours now, trying to figure it out :)

@ilaykim ilaykim closed this as completed Jul 11, 2022
@ilaykim
Copy link
Author

ilaykim commented Jul 11, 2022

@donewiththedollar

Quick catch and BAD BAD WORKAROUND the bug

line 42 in backtest.py

elif passivbot_mode == "neat_grid":

    try:
        return backtest_neat_grid(
        data,
        config["starting_balance"],
        config["latency_simulation_ms"],
        config["maker_fee"],
        **xk,)
    except ZeroDivisionError as err:
        print("ZeroDivisionError")
        config["starting_balance"] = config["starting_balance"] * 2
        print("changing starting_balance to", config["starting_balance"])
        try:
            return backtest_neat_grid(
            data,
            config["starting_balance"],
            config["latency_simulation_ms"],
            config["maker_fee"],
            **xk,)
        except ZeroDivisionError as err2:
            print("didnt work!")
            return None

@ilaykim ilaykim reopened this Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants