LEAN is the open source
algorithmic trading engine powering QuantConnect. Founded in 2013 LEAN has been built by a
global community of 80+ engineers and powers more than a dozen hedge funds today.
Alpha League Competition: $1,000 Weekly Prize Pool
Qualifying Alpha Streams Reentered Weekly Learn
more
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.
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.
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.
Ryan Riordon
1k
,
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.
0
Adam W
3.3k
,
`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.
0
Ryan Riordon
1k
,
Are the small trades the rebalancing back to 10% or are they something else?
0
Tijmen Kodden
595
,
aah! thanks a lot guys! I'm gonna check if i am already invested in the symbol and that probably fix it!
0
Tijmen Kodden
595
,
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?
0
Shile Wen
63.4k
,
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.
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.
Loading...
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!