-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.py
35 lines (27 loc) · 1.08 KB
/
test.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
import datetime
import backtrader
# from strategies import TestStrategy
from _strategies.ADXMomentum import ADXMomentum
from matplotlib.dates import (HOURS_PER_DAY, MIN_PER_HOUR, SEC_PER_MIN,
MONTHS_PER_YEAR, DAYS_PER_WEEK,
SEC_PER_HOUR, SEC_PER_DAY,
num2date, rrulewrapper, YearLocator,
MicrosecondLocator)
cerebro = backtrader.Cerebro()
cerebro.broker.set_cash(1000000)
data = backtrader.feeds.YahooFinanceCSVData(
dataname="C:\Divyam Projects\Avalor\BackTrader\BAJAJFINSV.NS.csv",
# Do not pass values before this date
fromdate=datetime.datetime(2005, 1, 1),
# Do not pass values after this date
todate=datetime.datetime(2021, 12, 31),
reverse=False)
# for i in data:
# print(i)
cerebro.adddata(data)
cerebro.addstrategy(ADXMomentum)
cerebro.addsizer(backtrader.sizers.FixedSize, stake=1000)
print('Starting porfolio value: %.2f' %cerebro.broker.getvalue())
cerebro.run()
print('Final porfolio value: %.2f' %cerebro.broker.getvalue())
cerebro.plot()