Hello QuantConnect Community,
I am currently working on implementing a trading strategy using the Algorithm Framework, specifically focusing on the Portfolio Construction Model. I've encountered an issue that I hope to get some guidance on.
Problem Description: I am using PortfolioTarget.Percent() within my Portfolio Construction Model to set portfolio targets based on the percentage of total portfolio value. However, I've noticed that even though targets are set as percentages, they are internally calculated into quantities (number of shares) at the time of target setting, using the current market prices available at that moment. This approach seems to lead to issues because the actual execution prices later on (when the Execution Model processes these targets) can be different due to price movements. Consequently, the executed quantities do not accurately reflect the intended portfolio percentages, sometimes rendering orders invalid or inconsistent with the strategic allocation decided by the PCM.
Specific Issues Faced:
- Orders sometimes exceed available capital due to price changes between target setting and order execution.
- The inaccuracy in quantity calculation from percentage targets due to real-time price fluctuations.
This situation undermines the separation of concerns intended by the Algorithm Framework, as I find myself needing to either:
- Manually track and adjust prices within the PCM, which seems counterintuitive to the frameworkâs design.
- Rewrite the Execution Model to dynamically adjust quantities at the time of order execution, which adds complexity.
Questions:
- Has anyone else encountered this issue with PortfolioTarget.Percent() and found a way to ensure that the targets set as a percentage of the portfolio are executed accurately reflecting current market prices?
- Are there recommended practices or modifications within the Execution Model to handle such discrepancies between target setting and order execution times?
- Any general advice on maintaining the integrity of percentage-based portfolio targets through market fluctuations?
I appreciate any insights or suggestions on how to address these challenges. Thank you in advance for your help!
Mia Alissi
Hello Eugene,
Your concerns are valid and it's great that you're thinking about these aspects while designing your algorithm. Let's address your questions one by one:
The
PortfolioTarget.Percent()
function indeed calculates the target quantity based on the current price of the security. This is done to ensure that the target quantity is an integer, as you cannot hold fractional shares of a stock. However, you're correct that this can lead to discrepancies due to price movements between the time of target setting and order execution. One way to handle this could be to use a limit order in your Execution Model, which would ensure that your orders are executed at a price that is close to the price at the time of target setting. However, this approach has its own trade-offs, as limit orders may not get filled if the price moves away from the limit price.Modifying the Execution Model to dynamically adjust quantities at the time of order execution could indeed be a solution. However, as you mentioned, this would add complexity to your algorithm. Another approach could be to use the
OnOrderEvent()
method to monitor the status of your orders and adjust your targets accordingly based on the actual fill prices. This would allow you to maintain the separation of concerns between the Portfolio Construction Model and the Execution Model.Maintaining the integrity of percentage-based portfolio targets through market fluctuations is indeed a challenge. One approach could be to rebalance your portfolio more frequently to ensure that your portfolio stays close to your target allocations. However, this could increase transaction costs. Another approach could be to use a more sophisticated risk management model that takes into account market volatility and adjusts your portfolio targets accordingly.
Here's an example of how you can create a
PortfolioTarget
based on a portfolio weight:And here's how you can access the
PortfolioTarget
objects for a Symbol:I hope this helps! Let me know if you have any other questions.
Sources:
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.
Papa Bear
Below is a custom FixedPercentagePortfolioConstructionModel that implements this solution:
In QCAlgorithm class:
Â
Eugene Buyakin
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!