Hey everyone,
I've build this first algo of mine which is buying the underlying asset when the price is below the 200 EMA.
this algo only uses the top technology stocks.
It is not finished yet but i am struggling to understand the construction model.
I want my algo to execute a position using 10% of my overal portfolio. And i want it to STOP once i can't open another position of 10%. (portfolio is full and my algo has to stop trading until i hit a target which i have to program later)
But when i run my backtest it is executing some stocks good. however after holding some stocks it is making very small trades of 1 to 10 shares.. i don't know why my algo is making these trades.
Can someone explain this to me?
Thanks!!
Ryan Riordon
Hello Tijmen,
Would I be correct in saying that the "SetPortfolioConstruction" rebalances your portfolio every day? You told it to keep your portfolio at 10% of those selected, thus if one stock goes up and another goes down, they are no longer at 10% each. SetPortfolioConstruction will then sell some of the stock that went up to buy a little of the one that went down. I haven't used SetPortfolioConstruction yet but this is my understanding of how it works. When i searched the forums for SetPortfolioConstruction i see some posts asking how to rebalance every x days or x months, so I am assuming it must rebalance by default every day based on those posts.
Adam W
`SetPortfolioConstruction` simply attaches the Portfolio Model. However the `PortfolioModel.CreateTargets` method is called every time `AlphaModel.Update` emits Insights - which in this case looks like every timestep (daily) - so it is rebalancing every day to maintain the 10% portfolio weight per asset.
Ryan Riordon
Are the small trades the rebalancing back to 10% or are they something else?
Tijmen Kodden
aah! thanks a lot guys! I'm gonna check if i am already invested in the symbol and that probably fix it!
Tijmen Kodden
But actually i am also checking in my Alpha model if i am invested? Does the framework skips the Alpha model and goes straight into the Construction model?
Shile Wen
Hi Tijmen,
The rebalancing trades are caused by the Portfolio Construction Model, so we should put the check for .Invested there. I've shown this in the attached backtest.
Due to separation of concerns, the Alpha Model and the Portfolio Construction Model should not use Security.Invested. The AM should track the last direction and PCM should track active insights.
Best,
Shile Wen
Tijmen Kodden
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!