def Initialize(self): # Set requested data resolution self.UniverseSettings.Resolution = Resolution.Minute self.SetStartDate(2013, 10, 7) #Set Start Date self.SetEndDate(2013, 10, 11) #Set End Date self.SetCash(100000) #Set Strategy Cash self.symbols = [ Symbol.Create(x, SecurityType.Equity, Market.USA) for x in ['AIG', 'BAC', 'IBM', 'SPY'] ] optimizer = UnconstrainedMeanVariancePortfolioOptimizer() # set algorithm framework models self.SetUniverseSelection( CoarseFundamentalUniverseSelectionModel(self.coarseSelector)) self.SetAlpha(HistoricalReturnsAlphaModel(resolution=Resolution.Daily)) self.SetPortfolioConstruction( BlackLittermanOptimizationPortfolioConstructionModel( optimizer=optimizer)) self.SetExecution(ImmediateExecutionModel()) self.SetRiskManagement(NullRiskManagementModel())
def Initialize(self): ## Set requested data resolution and variables to help with Universe Selection control self.UniverseSettings.Resolution = Resolution.Daily self.month = -1 ## Declare single variable to be passed in multiple places -- prevents issue with conflicting start dates declared in different places self.SetStartDate(2018, 1, 1) self.SetCash(100000) ## SPDR Small Cap ETF is a better benchmark than the default SP500 self.SetBenchmark('IJR') ## Set Universe Selection Model self.SetUniverseSelection( FineFundamentalUniverseSelectionModel(self.CoarseSelectionFunction, self.FineSelectionFunction)) self.SetSecurityInitializer( lambda security: security.SetFeeModel(ConstantFeeModel(0))) ## Set CCA Alpha Model self.SetAlpha(ContingentClaimsAnalysisAlphaModel()) ## Set Portfolio Construction Model self.SetPortfolioConstruction( EqualWeightingPortfolioConstructionModel()) ## Set Execution Model self.SetExecution(ImmediateExecutionModel()) ## Set Risk Management Model self.SetRiskManagement(NullRiskManagementModel())
def Initialize(self): self.SetStartDate(2013,10,7) self.SetEndDate(2013,10,11) bac = self.AddEquity("BAC") aig = self.AddEquity("AIG") self.SetUniverseSelection(ManualUniverseSelectionModel(self.Securities.Keys)) self.SetAlpha(PairsTradingAlphaModel(bac.Symbol, aig.Symbol)) self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel()) self.SetExecution(ImmediateExecutionModel()) self.SetRiskManagement(NullRiskManagementModel())
def Initialize(self): self.UniverseSettings.Resolution = Resolution.Minute self.SetStartDate(2013, 10, 7) self.SetEndDate(2013, 10, 11) self.SetCash(100000) # set framework models self.SetUniverseSelection(FrontMonthFutureUniverseSelectionModel(self.SelectFutureChainSymbols)) self.SetAlpha(ConstantFutureContractAlphaModel(InsightType.Price, InsightDirection.Up, timedelta(1))) self.SetPortfolioConstruction(SingleSharePortfolioConstructionModel()) self.SetExecution(ImmediateExecutionModel()) self.SetRiskManagement(NullRiskManagementModel())
def Initialize(self): self.UniverseSettings.Resolution = Resolution.Minute self.SetStartDate(2014, 6, 5) self.SetEndDate(2014, 6, 6) self.SetCash(100000) # set framework models self.SetUniverseSelection(EarliestExpiringWeeklyAtTheMoneyPutOptionUniverseSelectionModel(self.SelectOptionChainSymbols)) self.SetAlpha(ConstantOptionContractAlphaModel(InsightType.Price, InsightDirection.Up, timedelta(hours = 0.5))) self.SetPortfolioConstruction(SingleSharePortfolioConstructionModel()) self.SetExecution(ImmediateExecutionModel()) self.SetRiskManagement(NullRiskManagementModel())
def Initialize(self): self.SetStartDate(2013, 10, 7) self.SetEndDate(2013, 10, 11) self.SetUniverseSelection( ManualUniverseSelectionModel( Symbol.Create('AIG', SecurityType.Equity, Market.USA), Symbol.Create('BAC', SecurityType.Equity, Market.USA), Symbol.Create('IBM', SecurityType.Equity, Market.USA), Symbol.Create('SPY', SecurityType.Equity, Market.USA))) self.SetAlpha( PearsonCorrelationPairsTradingAlphaModel(252, Resolution.Daily)) self.SetPortfolioConstruction( EqualWeightingPortfolioConstructionModel()) self.SetExecution(ImmediateExecutionModel()) self.SetRiskManagement(NullRiskManagementModel())
def Initialize(self): self.SetStartDate(2015, 7, 12) self.SetEndDate(2018, 7, 27) self.SetCash(100000) symbols = [ Symbol.Create("EURUSD", SecurityType.Forex, Market.Oanda), Symbol.Create("EURGBP", SecurityType.Forex, Market.Oanda), Symbol.Create("EURAUD", SecurityType.Forex, Market.Oanda), Symbol.Create("EURCHF", SecurityType.Forex, Market.Oanda), Symbol.Create("EURJPY", SecurityType.Forex, Market.Oanda), Symbol.Create("EURCHF", SecurityType.Forex, Market.Oanda), Symbol.Create("USDJPY", SecurityType.Forex, Market.Oanda), Symbol.Create("USDCHF", SecurityType.Forex, Market.Oanda), Symbol.Create("USDCAD", SecurityType.Forex, Market.Oanda), Symbol.Create("AUDUSD", SecurityType.Forex, Market.Oanda), Symbol.Create("AUDJPY", SecurityType.Forex, Market.Oanda), Symbol.Create("GBPJPY", SecurityType.Forex, Market.Oanda), Symbol.Create("GBPUSD", SecurityType.Forex, Market.Oanda), Symbol.Create("NZDUSD", SecurityType.Forex, Market.Oanda) ] # Initializes the class that provides DailyFx News self.AddData(DailyFx, "DFX", Resolution.Minute, TimeZones.Utc) # Set Our Universe self.UniverseSettings.Resolution = Resolution.Minute self.SetUniverseSelection(ManualUniverseSelectionModel(symbols)) # Set to use our FxCalendar Alpha Model self.SetAlpha(FxCalendarTrigger()) # Equally weigh securities in portfolio, based on insights self.SetPortfolioConstruction( EqualWeightingPortfolioConstructionModel()) # Set Immediate Execution Model self.SetExecution(ImmediateExecutionModel()) # Set Null Risk Management Model self.SetRiskManagement(NullRiskManagementModel())
def Initialize(self): # Set requested data resolution self.UniverseSettings.Resolution = Resolution.Minute # Order margin value has to have a minimum of 0.5% of Portfolio value, allows filtering out small trades and reduce fees. # Commented so regression algorithm is more sensitive #self.Settings.MinimumOrderMarginPortfolioPercentage = 0.005 self.SetStartDate(2013,10,7) #Set Start Date self.SetEndDate(2013,10,11) #Set End Date self.SetCash(100000) #Set Strategy Cash self.symbols = [ Symbol.Create(x, SecurityType.Equity, Market.USA) for x in [ 'AIG', 'BAC', 'IBM', 'SPY' ] ] optimizer = UnconstrainedMeanVariancePortfolioOptimizer() # set algorithm framework models self.SetUniverseSelection(CoarseFundamentalUniverseSelectionModel(self.coarseSelector)) self.SetAlpha(HistoricalReturnsAlphaModel(resolution = Resolution.Daily)) self.SetPortfolioConstruction(BlackLittermanOptimizationPortfolioConstructionModel(optimizer = optimizer)) self.SetExecution(ImmediateExecutionModel()) self.SetRiskManagement(NullRiskManagementModel())
def Initialize(self): self.SetStartDate(2013,10,7) #Set Start Date self.SetEndDate(2013,10,11) #Set End Date self.SetCash(100000) #Set Strategy Cash # even though we're using a framework algorithm, we can still add our securities # using the AddEquity/Forex/Crypto/ect methods and then pass them into a manual # universe selection model using Securities.Keys self.AddEquity("SPY") self.AddEquity("IBM") self.AddEquity("BAC") self.AddEquity("AIG") # define a manual universe of all the securities we manually registered self.SetUniverseSelection(ManualUniverseSelectionModel(self.Securities.Keys)) # define alpha model as a composite of the rsi and ema cross models self.SetAlpha(CompositeAlphaModel(RsiAlphaModel(), EmaCrossAlphaModel())) # default models for the rest self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel()) self.SetExecution(ImmediateExecutionModel()) self.SetRiskManagement(NullRiskManagementModel())