Skip to content

Commit

Permalink
validation bug fix and pinning versions
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmeier committed Apr 20, 2021
1 parent 7eb807c commit 8061f8a
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 77 deletions.
75 changes: 53 additions & 22 deletions example_backtest.json
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 5 additions & 0 deletions fast_trade/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion fast_trade/transformers_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions fast_trade/validate_backtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand All @@ -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.'
Expand Down
15 changes: 3 additions & 12 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
finta==1.3
matplotlib==3.4.1
python-binance== 0.7.10
103 changes: 77 additions & 26 deletions run_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
21 changes: 5 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
],
)

0 comments on commit 8061f8a

Please sign in to comment.