-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbacktest.py
60 lines (49 loc) · 1.63 KB
/
backtest.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import datetime
from indicators.alligator import Alligator
import backtrader as bt
import backtrader.feeds as btfeed
from strategies.dip import BuyDip
from strategies.sma import SmaCross
from strategies.goldenCross import GoldenCross
from strategies.supertrendStrategy import SupertrendStrategy
from strategies.alligatorStrategy import AlligatorStrategy
from indicators.pivots import PivotPoint
from strategies.ArjunBhatiaFutures import ArjunBhatiaFutures
from strategies.StopOrderSubmit import StopOrderSubmit
from strategies.dipBuy import DipBuy
cerebro = bt.Cerebro()
cerebro.broker.set_cash(1000000)
data = btfeed.GenericCSVData(
dataname='./Data/Custom/BANKNIFTY.csv',
fromdate=datetime.datetime(2020, 1, 1),
todate=datetime.datetime(2020, 12, 31),
nullvalue=0.0,
dtformat=('%Y/%m/%d'),
tmformat=('%H:%M'),
timeframe=bt.TimeFrame.Minutes, compression=1,
sessionstart=datetime.time(9, 15), sessionend=datetime.time(15, 30),
datetime=1,
time=2,
high=4,
low=5,
open=3,
close=6,
volume=-1,
openinterest=-1
)
data2 = bt.feeds.YahooFinanceCSVData(
dataname = './Data/Yahoo/BTC-USD.csv',
fromdate=datetime.datetime(2018, 1, 4),
todate=datetime.datetime(2021, 9, 4),
reverse = False
)
# cerebro.adddata(data).plotinfo.plot=False
cerebro.resampledata(data,
timeframe=bt.TimeFrame.Minutes,
compression=15)
cerebro.resampledata(data,
timeframe=bt.TimeFrame.Days,
compression=1).plotinfo.plot=False
cerebro.addstrategy(DipBuy)
cerebro.run()
cerebro.plot(style='candle', barup='green')