Discard my previous post. I don't know how I had this shift. It was probably a wrong code because I can't reproduce it.
But I still have an issue about the price of an option.
I noticed that if an option is created at bar, the Close of the option is correct from bar but from 0 to bar-1 it's incorrect. From bar-1 to 0, it contains the value at the expiration, so 0 or abs(Close - strike).
Can you clarify your model because these values are incorrect.
Even if I don't need the past (bar-x), I also noticed that if at bar-1 the Close of the option was 0 ShortAtClose(bar) generates a Runtime Error (Position Entry cannot be zero) even if the Close of the option at bar is NOT zero.
CODE:
Please log in to see this code.
Here are the results if the option is created at bar=30 which is 1/30/2017
Date[30]=1/30/2017 12:00:00 AM
put.Symbol: !AAL_45.00_170317_PUT
Date Close put.Date put.Close
1/26/2017 12:00:00 AM 49.59 1/26/2017 12:00:00 AM 0
1/27/2017 12:00:00 AM 46.950001 1/27/2017 12:00:00 AM 0
1/30/2017 12:00:00 AM 44.900002 1/30/2017 12:00:00 AM 2.05577461567276
1/31/2017 12:00:00 AM 44.25 1/31/2017 12:00:00 AM 2.3698234854946
2/1/2017 12:00:00 AM 44.049999 2/1/2017 12:00:00 AM 2.44734183692847
As you can see Close[30]=2.05577461567276 but a ShortAtClose(bar) will generate a Runtime Error Position Entry cannot be zero.
You can reproduce it for any instrument.
Can you please check this issue?
Note:
I only checked Close but I guess the issue is the same for Open