Hi ,
i want to know whether there is need to buy a selled put in option at the time of expiry or it just automatically gets expired.also how to know the profit and loss while dealing with option.
Is there need to add huge cash in while selling a option because we deal with the premium.
It will be better if you can share some example to sell/buy put/call option daily expiring on that day itself.
Derek Melchin
Hi Akash,
When an option contract expires, it is automatically exercised. I've attached the backtest from our Covered Call options tutorial. Taking a look at the backtest orders log, we can see the tags which state "Automatic option exercise on expiration".
To track the profit and loss of our portfolio, our documentation shows that we can use
self.Portfolio.TotalUnrealizedProfit
The option premium is incurred by the option buyer, not the seller. Therefore, we do not need to had a lot of cash to deal with it.
I recommend reviewing our options tutorial series for more information and examples.
Best,
Derek Melchin
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.
Derek Melchin
Hi Harsh,
We can calculate the PNL after exiting an option trade by saving the options contract multiplier and setting up a `costs` dictionary in Initialize
self.optionMultiplier = option.ContractMultiplier self.costs = {}
Then in OnOrderEvent, we track the entry and exit costs for each trade to get the PNL
def OnOrderEvent(self, orderEvent): if orderEvent.Status == OrderStatus.Filled and orderEvent.Symbol.SecurityType == SecurityType.Option: q = orderEvent.FillQuantity p = orderEvent.FillPrice m = self.optionMultiplier cashflow = q * p * m if self.Portfolio[orderEvent.Symbol].Invested: self.costs[orderEvent.Symbol] = cashflow else: pnl = -(self.costs[orderEvent.Symbol] + cashflow)
See the attached algorithm for the full solution. Note that this calculation does not account for transaction fees and only works for trades that don't scale in/out of positions.
Best,
Derek Melchin
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.
Akash
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!