Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 0 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 |
from datetime import timedelta class BasicTemplateFrameworkAlgorithm(QCAlgorithmFramework): def Initialize(self): # Set requested data resolution self.UniverseSettings.Resolution = Resolution.Minute self.SetStartDate(2018, 8, 28) #Set Start Date self.SetEndDate(2019, 2, 28) #Set End Date self.SetCash(100000) #Set Strategy Cash self.SetUniverseSelection(CoarseFundamentalUniverseSelectionModel(self.CoarseSelectionFunction)) self.SetAlpha(CustomAlphaModel()) self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel()) self.SetExecution(ImmediateExecutionModel()) self.SetRiskManagement(NullRiskManagementModel()) # sort the data by daily dollar volume and take the top '5' def CoarseSelectionFunction(self, coarse): # sort descending by daily dollar volume sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True) # return the symbol objects of the top entries from our sorted collection return [ x.Symbol for x in sortedByDollarVolume[:5] ] class CustomAlphaModel: ''' This is where you might design a custom Alpha Model that will interact with the SymbolData class you create below''' def __init__(self): self.symbolDataBySymbol = {} def Update(self, algorithm, data): insights = [] ## this is where you can evaluate technical indicators, etc. to generate insights return insights def OnSecuritiesChanged(self, algorithm, changes): symbols = [ x.Symbol for x in changes.AddedSecurities ] for symbol in symbols: ## Create SymbolData objects for any new assets symbolData = SymbolData(algorithm, symbol) ## Assign object to a dictionary so you can access it later in the Update() method self.symbolDataBySymbol[symbol] = symbolData class SymbolData: def __init__(self, algorithm, symbol): self.Symbol = symbol self.five_consolidator = TradeBarConsolidator(timedelta(days = 5)) ## 5-period TradeBar Consolidator self.five_consolidator.DataConsolidated += self.FiveMinuteConsolidator ## Add fuction to do what you want every 5-minutes with your data self.fifteen_consolidator = TradeBarConsolidator(timedelta(days = 15)) ## 5-period TradeBar Consolidator self.fifteen_consolidator.DataConsolidated += self.FifteenMinuteConsolidator ## Add fuction to do what you want every 5-minutes with your data algorithm.SubscriptionManager.AddConsolidator(symbol, self.five_consolidator) ## Register consolidator algorithm.SubscriptionManager.AddConsolidator(symbol, self.fifteen_consolidator) ## Register consolidator def FiveMinuteConsolidator(self, sender, bar): #algorithm.Log('New 5 minute Bar for ' + str(self.Symbol) + '!') pass def FifteenMinuteConsolidator(self, sender, bar): #algorithm.Log('New 15 minute Bar for ' + str(self.Symbol) + '!') pass