* t status pep8 conversion * Minor tweaks and rebase * Various minor fixes --------- Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
This commit is contained in:
@@ -21,28 +21,28 @@ class SectorWeightingFrameworkAlgorithm(QCAlgorithm):
|
||||
'''This example algorithm defines its own custom coarse/fine fundamental selection model
|
||||
with sector weighted portfolio.'''
|
||||
|
||||
def Initialize(self):
|
||||
def initialize(self):
|
||||
|
||||
# Set requested data resolution
|
||||
self.UniverseSettings.Resolution = Resolution.Daily
|
||||
self.universe_settings.resolution = Resolution.DAILY
|
||||
|
||||
self.SetStartDate(2014, 4, 2)
|
||||
self.SetEndDate(2014, 4, 6)
|
||||
self.SetCash(100000)
|
||||
self.set_start_date(2014, 4, 2)
|
||||
self.set_end_date(2014, 4, 6)
|
||||
self.set_cash(100000)
|
||||
|
||||
# set algorithm framework models
|
||||
self.SetUniverseSelection(FineFundamentalUniverseSelectionModel(self.SelectCoarse, self.SelectFine))
|
||||
self.SetAlpha(ConstantAlphaModel(InsightType.Price, InsightDirection.Up, timedelta(1)))
|
||||
self.SetPortfolioConstruction(SectorWeightingPortfolioConstructionModel())
|
||||
self.set_universe_selection(FineFundamentalUniverseSelectionModel(self.select_coarse, self.select_fine))
|
||||
self.set_alpha(ConstantAlphaModel(InsightType.PRICE, InsightDirection.UP, timedelta(1)))
|
||||
self.set_portfolio_construction(SectorWeightingPortfolioConstructionModel())
|
||||
|
||||
def OnOrderEvent(self, orderEvent):
|
||||
if orderEvent.Status == OrderStatus.Filled:
|
||||
self.Debug(f"Order event: {orderEvent}. Holding value: {self.Securities[orderEvent.Symbol].Holdings.AbsoluteHoldingsValue}")
|
||||
def on_order_event(self, order_event):
|
||||
if order_event.status == OrderStatus.FILLED:
|
||||
self.debug(f"Order event: {order_event}. Holding value: {self.securities[order_event.symbol].holdings.absolute_holdings_value}")
|
||||
|
||||
def SelectCoarse(self, coarse):
|
||||
def select_coarse(self, coarse):
|
||||
# IndustryTemplateCode of AAPL, IBM and GOOG is N, AIG is I, BAC is B. SPY have no fundamentals
|
||||
tickers = ["AAPL", "AIG", "IBM"] if self.Time.date() < date(2014, 4, 4) else [ "GOOG", "BAC", "SPY" ]
|
||||
return [Symbol.Create(x, SecurityType.Equity, Market.USA) for x in tickers]
|
||||
tickers = ["AAPL", "AIG", "IBM"] if self.time.date() < date(2014, 4, 4) else [ "GOOG", "BAC", "SPY" ]
|
||||
return [Symbol.create(x, SecurityType.EQUITY, Market.USA) for x in tickers]
|
||||
|
||||
def SelectFine(self, fine):
|
||||
return [f.Symbol for f in fine]
|
||||
def select_fine(self, fine):
|
||||
return [f.symbol for f in fine]
|
||||
|
||||
Reference in New Issue
Block a user