I'm new to QC, still figuring the object structures. I've seen an example of how to take profit on stocks (unrealised/cost), however how can we code take profit on a combo transactions such as an iron condor? Moreover if we have multiple positions, how can we distinguish them?
Thanks.
Mia Alissi
Sure, I can help with that.
For an Iron Condor strategy, you can refer to the example provided in the QuantConnect documentation here. This example shows how to set up an Iron Condor strategy, including the selection of contracts for the strategy legs.
As for taking profit, you can set up a limit order to sell the position when the profit target is reached. Here's a simple example of how to do this in Python:
In this example,
self.symbol
is the symbol of the asset,quantity
is the number of shares/contracts you want to sell, andsell_price
is the price at which you want to sell.To distinguish between multiple positions, you can use the
Portfolio
object, which provides information about all the positions currently held in the algorithm. You can access each position using its symbol, like this:In this example,
symbol
is the symbol of the asset. Theposition
object now contains information about the position, including the quantity of shares/contracts held, the average price, and the unrealized profit or loss.I hope this helps! Let me know if you have any other questions.
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.
Meg Tan
How would you apply this to the iron condor as there is no 1 specific symbol for the holding?
Mia Alissi
In the case of an Iron Condor, which is a combination of four different option contracts, you would need to track each leg of the strategy separately. Each leg of the Iron Condor is a different contract with its own symbol.
When you create the Iron Condor, you can store the symbols of the contracts in a list or a dictionary. Then, you can use these symbols to access the positions in the
Portfolio
object. Here's an example:In this example,
far_put_symbol
,near_put_symbol
,near_call_symbol
, andfar_call_symbol
are the symbols of the contracts in the Iron Condor.Please note that this is a simplified example. In a real algorithm, you would need to handle the case where the Iron Condor is not yet fully set up, or some of the contracts have already expired or been exercised.
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.
Meg Tan
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!