From 8061f8aedc7d85a2646f63fc48f62fcb39e3f8b6 Mon Sep 17 00:00:00 2001 From: Jed Meier Date: Mon, 19 Apr 2021 20:46:06 -0500 Subject: [PATCH] validation bug fix and pinning versions --- example_backtest.json | 75 ++++++++++++++++------- fast_trade/cli.py | 5 ++ fast_trade/transformers_map.py | 1 - fast_trade/validate_backtest.py | 2 + requirements.txt | 15 +---- run_example.py | 103 ++++++++++++++++++++++++-------- setup.py | 21 ++----- 7 files changed, 145 insertions(+), 77 deletions(-) diff --git a/example_backtest.json b/example_backtest.json index cc63dff..b507c60 100644 --- a/example_backtest.json +++ b/example_backtest.json @@ -1,29 +1,60 @@ { - "base_balance": 1000, - "chart_period": "5T", + "any_enter": [], + "any_exit": [], + "chart_period": "4H", "comission": 0.01, - "symbol": "BTCUSDT", "datapoints": [ - { - "args": [ - 30 - ], - "transformer": "sma", - "name": "sma_short" - }, - { - "args": [ - 90 - ], - "transformer": "sma", - "name": "sma_long" - } + { + "args": [ + 10 + ], + "name": "BTCUSD_rsi", + "transformer": "rsi" + }, + { + "args": [ + 10 + ], + "name": "fast_zlema", + "transformer": "zlema" + }, + { + "args": [ + 41.0 + ], + "name": "slow_zelma", + "transformer": "zlema" + }, + { + "args": [ + 10 + ], + "name": "BTCUSD_ema", + "transformer": "ema" + } ], "enter": [ - ["close", ">", "sma_long"], - ["close", ">", "sma_short"] + [ + "fast_zlema", + "<", + "close", + 0 + ], + [ + "BTCUSD_rsi", + "<", + 30.0, + 0 + ] ], - "exit": [["close", "<", "sma_short"]], - "trailing_stop_loss": 0.05, - "exit_on_end": false + "exit": [ + [ + "slow_zelma", + "<", + "close", + 0 + ] + ], + "exit_on_end": false, + "trailing_stop_loss": null } \ No newline at end of file diff --git a/fast_trade/cli.py b/fast_trade/cli.py index 4d7f129..08fc2a8 100644 --- a/fast_trade/cli.py +++ b/fast_trade/cli.py @@ -105,7 +105,12 @@ def main(): return if command == "validate": + print("args: ",args) backtest = open_strat_file(args["backtest"]) + if not backtest: + print("backtest not found! ") + return + print("backtest: ",backtest) backtest = {**backtest, **args} res = validate_backtest(backtest) diff --git a/fast_trade/transformers_map.py b/fast_trade/transformers_map.py index ab0e70f..aa4b3b7 100644 --- a/fast_trade/transformers_map.py +++ b/fast_trade/transformers_map.py @@ -74,7 +74,6 @@ "fish": TA.FISH, "ichimoku": TA.ICHIMOKU, "apz": TA.APZ, - "vr": TA.VR, "sqzmi": TA.SQZMI, "vpt": TA.VPT, "fve": TA.FVE, diff --git a/fast_trade/validate_backtest.py b/fast_trade/validate_backtest.py index 0540bd1..b1c353a 100644 --- a/fast_trade/validate_backtest.py +++ b/fast_trade/validate_backtest.py @@ -101,6 +101,7 @@ def validate_backtest(backtest): log not in indicator_keys and isinstance(log, str) and log not in [">", "=", "<"] + and not log.isnumeric() ): exit_errors.append( f'Datapoint "{log}" referenced in exit logic not found in datapoints. Check datapoints and logic.' @@ -115,6 +116,7 @@ def validate_backtest(backtest): log not in indicator_keys and isinstance(log, str) and log not in [">", "=", "<"] + and not log.isnumeric() ): enter_errors.append( f'Datapoint "{log}" referenced in enter logic not found in datapoints. Check datapoints and logic.' diff --git a/requirements.txt b/requirements.txt index 115f4f0..91e3a10 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,12 +1,3 @@ -cycler==0.10.0 -finta==1.2 -kiwisolver==1.3.1 -matplotlib==3.3.4 -numpy==1.20.1 -pandas==1.2.3 -Pillow==8.1.2 -pyparsing==2.4.7 -python-dateutil==2.8.1 -pytz==2021.1 -six==1.15.0 -python-binance==0.7.9 \ No newline at end of file +finta==1.3 +matplotlib==3.4.1 +python-binance== 0.7.10 \ No newline at end of file diff --git a/run_example.py b/run_example.py index 6ae4a22..09a798f 100644 --- a/run_example.py +++ b/run_example.py @@ -11,49 +11,100 @@ ds2 = "2020-07-10" s2 = 1594339200 ms2 = 1594339200000 + +# if(rsi > 70 | rsi < 30) : + +# result = myprediction(data) + +# switch(result): + +# case 0: hold + +# case 1: sell + +# case 2: buy +# backtest = { +# "any_enter": [], +# "any_exit": [], +# "chart_period": "1H", +# "comission": 0.00, +# "datapoints": [ +# { +# "args": [ + +# ], +# "name": "rsi_dp", +# "transformer": "rsi" +# } +# ], +# "enter": [ +# [ +# "rsi_dp", +# "<", +# 30, +# ] +# ], +# "exit": [ +# [ +# "rsi_dp", +# ">", +# 70, +# ] +# ], +# "exit_on_end": False, +# # "start": "2019-12-01 15:29:00", +# # "stop": "2021-03-08 15:29:00", +# "trailing_stop_loss": 0.05 # 5% stoploss +# } + backtest = { - "base_balance": 1000, - "chart_period": "5T", - "chart_start": "2020-08-30 18:00:00", - "chart_stop": "2020-09-06 16:39:00", - "comission": 0.01, + "any_enter": [], + "any_exit": [], + "chart_period": "15Min", + "comission": 0, "datapoints": [ { "args": [ - 30 + 14 ], - "transformer": "sma", - "name": "sma_shorst" + "name": "er", + "transformer": "er" }, { "args": [ - 90 + 13 ], - "transformer": "sma", - "name": "sma_long" - }, + "name": "zlema", + "transformer": "zlema" + } ], "enter": [ - ["close", ">", "sma_long_wrong"], - ["close", ">", "sma_short"] + [ + "zlema", + ">", + "close", + 1 + ] ], "exit": [ - ["close", "<", "sma_short"], - ["close", "<", 5] + [ + "er", + "<", + 0, + 1 + ] ], - "trailing_stop_loss": 0.05, "exit_on_end": False, + "start": "2021-01-01 22:30:00", + "stop": "2021-03-11 23:30:59", + "trailing_stop_loss": 0 } if __name__ == "__main__": # datafile = "./BTCUSDT.csv" - datafile = "./BTCUSDT.csv" - tmp_start = datetime.datetime.utcnow() - # backtest = generate_backtest() - # print("backtest: ",json.dumps(backtest, indent=2) + datafile = "./archive/BTCUSDT_2021.csv" # test = run_backtest(backtest, ohlcv_path=datafile, summary=True) - res = validate_backtest(backtest) - print(res) - # print(backtest["enter"]) - # print(test["trade_df"]) . - # print(json.dumps(test["summary"], indent=2)) + # print(test["summary"]) + errors = validate_backtest(backtest) + + print(errors) diff --git a/setup.py b/setup.py index 9aea96a..74fe769 100644 --- a/setup.py +++ b/setup.py @@ -7,8 +7,8 @@ setup( name="fast-trade", - version="0.2.0", - description="Analyze and backtest algorithmic trading strategies ohlcv data quickly and easily.", + version="0.2.1", + description="About low code backtesting library utilizing pandas and technical analysis indicators", long_description=README, long_description_content_type="text/markdown", url="https://github.com/jrmeier/fast-trade", @@ -44,19 +44,8 @@ packages=find_packages(include=["fast_trade"]), include_package_data=True, install_requires=[ - "cycler==0.10.0", - "finta", - "kiwisolver==1.3.1", - "matplotlib==3.3.4", - "numpy", - "pandas", - "Pillow==8.1.2", - "pyparsing==2.4.7", - "python-dateutil==2.8.1", - "pytz", - "six", - "python-binance", - 'service_identity', - 'pyasn1' + "finta==1.3", + "matplotlib==3.4.1", + "python-binance== 0.7.10", ], )