Hi Folks,

I am a beginner here. Have been running some simple algos to familarize myself. However i have run into an issue i dont seem to be quite "getting it". My Idea is a simple one, buy equal priced "SPY" and "BND". and if one of them goes up in price, sell a fraction and buy the other to bring both of them to an equal level. I am unable to figure out a method to convey this in an Alpha model. As i do not seem to know any idicator that already does this. My code thusfar. Appreciate any help or any pointers. Thanks

from QuantConnect import Market, Resolution, SecurityType, Symbol from QuantConnect.Algorithm import QCAlgorithm from QuantConnect.Orders.Fees import ConstantFeeModel from QuantConnect.Algorithm.Framework.Selection import ManualUniverseSelectionModel from QuantConnect.Algorithm.Framework.Portfolio import EqualWeightingPortfolioConstructionModel from QuantConnect.Algorithm.Framework.Execution import ImmediateExecutionModel from QuantConnect.Algorithm.Framework.Risk import MaximumDrawdownPercentPortfolio, MaximumDrawdownPercentPerSecurity from QuantConnect.Algorithm.Framework.Alphas import AlphaModel, Insight, InsightDirection from datetime import timedelta class MyAlphaModel(AlphaModel): def OnSecuritiesChanged(self, algorithm, changes): def Update(self, algorithm, data): class EqualPortfolio(QCAlgorithm): def Initialize(self): self.SetStartDate(2016, 1, 1) # Set Start Date self.SetCash(100000) # Set Strategy Cash _symbols = ["SPY", "BND"] #self.symbols = [ self.AddEquity(s, Resolution.Day).Symbols for s in _symbols ] #self.spy, self.tlt, self.gld = self.symbols[0], self.symbols[1], self.symbols[2] self.UniverseSettings.Resolution = Resolution.Daily symbols = [ Symbol.Create(s, SecurityType.Equity, Market.USA) for s in _symbols ] self.SetSecurityInitializer(lambda security: security.SetFeeModel(ConstantFeeModel(0))) self.SetUniverseSelection(ManualUniverseSelectionModel(symbols)) self.SetAlpha(MyAlphaModel()) self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel()) self.SetRiskManagement(MaximumDrawdownPercentPortfolio(0.02)) self.SetExecution(ImmediateExecutionModel())