1)COuld you please guidde me how can i see my profit/loss that i have made using sell/buy put/call of a option.I have gone throught the provided algorithms like iron condor given in option tutorial series but i am not able to find how to ge the exact aggregate profit once the expiry happens for a option.
2)What should be taken as premium like ask price,bid price,etc?
It will be helpfull if you can use iron condor(or any) as a example to help in understanding.
Rahul Chowdhury
Hey Akash,1.
We can find the profit for a security by accessing
self.Portfolio[security.Symbol].Profit
and the total profit of our portfolio with
self.Portfolio.TotalProfit
Let's calculate the profit when an option exercise order is submitted by the algorithm. We can detect this in the OnOrderEvent method, which fires each time there is a new order or an order is updated.
def OnOrderEvent(self, orderEvent): order = self.Transactions.GetOrderById(orderEvent.OrderId) if order.Type == OrderType.OptionExercise: self.Debug(f"{orderEvent.Symbol} Profit: {self.Portfolio[orderEvent.Symbol].Profit}, Total Profit: {self.Portfolio.TotalProfit}")
I've attached a backtest which demonstrates this using the iron condor template from the tutorial.
2. You can use the last close price to calculate the premium. Lean assumes all orders are completely filled at the current market price. You can learn more about fill models in the documentation.
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!