-
Notifications
You must be signed in to change notification settings - Fork 0
/
tester.py
45 lines (26 loc) · 849 Bytes
/
tester.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
import backtrader as bt
import datetime
import matplotlib
from backtrader.sizers.fixedsize import FixedSize
from strategies import TestStrategy
cerebro = bt.Cerebro()
#setting the cash
cerebro.broker.set_cash(1000000)
data = bt.feeds.YahooFinanceCSVData(
dataname = "ADANIGREEN.csv",
# Do not pass values before this date
fromdate=datetime.datetime(2020, 1, 1),
# Do not pass values after this date
todate=datetime.datetime(2021, 1, 1),
reverse=False)
#setting up the data
cerebro.adddata(data)
#adding strategy to cerebro
cerebro.addstrategy(TestStrategy)
#adding sizer
cerebro.addsizer(bt.sizers.SizerFix, stake=1000)
print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())
cerebro.run()
print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
#plotting the results
cerebro.plot()