-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtesting.py
40 lines (29 loc) · 1.1 KB
/
testing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import json
import time
from bot import TradingBot
from pipelines.thm_pipeline import THMPipeline
from backtest import Backtester
from exchange.bybit_exchange import BybitExchange
from strategies.thm_strategy import THMStrategy
def test_pipeline(load_file='', optimise=False, train_test_split=0.5, num_candles=1000, interval="5"):
optimise = False
n_candles = num_candles
strat = THMStrategy()
if load_file != '':
with open(load_file, 'r') as f:
data = json.load(f)
else:
exch = BybitExchange(test=False)
data = exch.get_klines(symbol="BTCUSD", interval=interval, limit=n_candles)
print(f"Loaded data.")
strat.load_klines(data)
print(f"Added indicators and signals.")
bt = Backtester(strategy=strat, pyramiding=15, stake_percent=0.05, leverage=5.0)
if optimise:
optimiser = THMPipeline(backtester=bt, num_candles=n_candles, train_test_split=train_test_split)
optimiser.run_pipeline()
else:
bt.run_backtest(start_index=0)
bt.print_report()
if __name__ == '__main__':
test_pipeline(num_candles=2880)