forked from Okitrader/Ollie-Hooper-Trading-Bot-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
52 lines (39 loc) · 1.96 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
from universe_selection import FactorUniverseSelectionModel
from alpha_model import ValueAlphaModel
from portfolio_construction import OptimisationPortfolioConstructionModel
from execution import Execution
from charting import InitCharts, PlotPerformanceChart, PlotPosConcentrationChart
#new comment
class TradingBot(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2003, 1, 1)
self.SetCash(100000)
# Data resolution
self.UniverseSettings.Resolution = Resolution.Minute
# Universe selection model
self.securities = []
self.CustomUniverseSelectionModel = FactorUniverseSelectionModel(self)
self.AddUniverse(self.CustomUniverseSelectionModel.SelectCoarse, self.CustomUniverseSelectionModel.SelectFine)
# Alpha model
self.CustomAlphaModel = ValueAlphaModel()
# Portfolio construction model
self.CustomPortfolioConstructionModel = OptimisationPortfolioConstructionModel()
# Execution model
self.CustomExecution = Execution()
# Add SPY for trading days data
self.AddEquity('SPY', Resolution.Daily)
# Schedule rebalancing
self.Schedule.On(self.DateRules.EveryDay('SPY'), self.TimeRules.At(13, 0), Action(self.RebalancePortfolio))
# Init charting
InitCharts(self)
# Schedule charting
self.Schedule.On(self.DateRules.Every(DayOfWeek.Friday), self.TimeRules.BeforeMarketClose('SPY', 0), Action(self.PlotCharts))
def OnData(self, data):
pass
def RebalancePortfolio(self):
alpha_df = self.CustomAlphaModel.GenerateAlphaScores(self, self.securities)
portfolio = self.CustomPortfolioConstructionModel.GenerateOptimalPortfolio(self, alpha_df)
self.CustomExecution.ExecutePortfolio(self, portfolio)
def PlotCharts(self):
PlotPerformanceChart(self)
PlotPosConcentrationChart(self)