-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
67 lines (42 loc) · 1.24 KB
/
main.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
61
62
63
64
65
66
67
import backtrader as bt
import os
import pandas as pd
from VIXStrategy import VIXStrategy
cerebro = bt.Cerebro()
cerebro.broker.setcash(100000)
class SPYVIXData(bt.feeds.GenericCSVData):
lines = ('vixopen' , 'vixhigh' , 'vixlow' , 'vixclose',)
params = (
('dtformat', '%Y-%m-%d'),
('date' , 0),
('spyopen' , 1),
('spyhigh' , 2),
('spylow' , 3),
('spyclose' , 4),
('spyadjclose' , 5),
('spyvolume' , 6),
('vixopen' , 7),
('vixhigh' , 8),
('vixlow' , 9),
('vixclose' , 10)
)
class VIXData(bt.feeds.GenericCSVData):
params = (
('dtformat', '%m/%d/%Y'),
('date', 0),
('vixopen', 1),
('vixhigh', 2),
('vixlow', 3),
('vixclose', 4),
('volume', -1),
('openinterest', -1)
)
spy_vix_csv_file = os.path.dirname(os.path.realpath(__file__)) + "/spy_vix.csv"
vix_csv_file = os.path.dirname(os.path.realpath(__file__)) + "/vix.csv"
spyVixDataFeed = SPYVIXData(dataname = spy_vix_csv_file)
vixDataFeed = VIXData(dataname = vix_csv_file)
cerebro.adddata(spyVixDataFeed)
cerebro.adddata(vixDataFeed)
cerebro.addstrategy(VIXStrategy)
cerebro.run()
cerebro.plot(volume = False)