Hi,
I am building an options strategy. A position has multiple legs (e.g. short and long leg for a put credit spread) and is entered as combo order. In the portfolio each leg is an individual holding (incl. individual unrealized PnL etc.). To evaluate take profit and stop loss, I need the unrealized PnL for the combo.
Is there a way to create "combo holdings" in the portfolio?
You can track the combos in a separate list/dataframe. Then you need to calculate values like unrealized PnL yourself. Since this seems a common task, I am wondering, if there is a common solution.
Thanks in advance
Mia Alissi
Yes, you can track the unrealized profit of a multi-legged options position (or combo) in QuantConnect. However, there isn't a built-in feature to create "combo holdings" in the portfolio. You would need to manually calculate the unrealized profit for the combined position.
To calculate the unrealized profit of the combined position, you can sum up the unrealized profit of each leg in the combo. Here is a Python code snippet that demonstrates this:
In this code,
self.order_tickets
is a list of order tickets for the legs in the combo. This code will give you the total unrealized profit for the combo.To determine the closest expiry of the contracts composing the OptionStrategy, you can use:
If you want to calculate the unrealized profit as a percentage, you can use the
UnrealizedPnLPercent
property that was added to holdings in LEAN. However, you would need to calculate the initial cost of the combo to use this property.Please note that these calculations should be done in the
OnData
method or in a scheduled event to ensure that they are updated regularly.For more complex strategies, you might need to implement a custom position manager or extend the
OptionStrategy
class to track the unrealized profit and other metrics for the combo.You can find more information about this in the QuantConnect forum and QuantConnect documentation.
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!