- ago
I am trying to calculate a "theoretical options" premium for long calls and puts, based on possible changes in price (aka what would the price of the option be if the underlying is at a certain price, at a certain day (from expiration), at a certain implied volatility. Right now, my only data sources are Medved Trader extension (Schwab and Fidelity), and of course WealthData and the OptionSynthetic methods. IV was manually assigned.

What would be a possible way to calculate a theoretical option price in this manner? I tried using code such as:
CODE:
Optprice = MedvedHistorical.Instance.CalculateOptionPrice(OptSymSynth, IV, underlying);
(trying to mimic the example of using IBKR from https://www.wealth-lab.com/blog/backtest-auto-trade-options ), but I don't have IBKRpro or Tradier.
I couldn't find the a spot Option price calculation function with the OptionSynthetic or OptionsHelper methods (unless I missed it).
I also tried overwriting the bars.Close[bars.Count-1] with a manual number, and then re-creating a new synthetic bar history for option price and reading the last bar of that, without the right response.
I found an old WL6.9 post about Black-Scholes calculation which seems to be not applicable to WL8, also didn't work.

Am I just missing something obvious (poor debugging skills)? If I bought the IBKR or Tradier extension (without opening the relevant brokerage account), would that work to load the function to calculate a theoretical options price?

Thanks guys. Sorry, been wracking my head for hours trying to get something that seemed to be so simple, but frustratingly elusive.

-bd
0
534
Solved
5 Replies

Reply

Bookmark

Sort
Cone8
 ( 4.92% )
- ago
#1
CalculateOptionPrice() returns double.NaN if it's not implemented by the historical provider. afaik, this particular function is only implemented by the IB Provider.

QUOTE:
I couldn't find the a spot Option price calculation function with the OptionSynthetic or OptionsHelper methods (unless I missed it).
Just create an OptionSynthetic BarHistory and use the last value. There are examples in the QuickRef too. If you have more questions, let me know.



Tip: You can use the HV indicator to estimate IV, but just make sure to divide HV by 100.0 to get a percentage...

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript6 {    public class SyntheticOptionBars : UserStrategyBase    {       public override void Initialize(BarHistory bars)       {                   _hv = new HV(bars.Close, 21, 252);          _iv = _hv / 100.0;          PlotTimeSeries(_iv, "IV from HV", "IV", WLColor.FromArgb(255,140,140,140), PlotStyle.Line);                    // ATM Call          string symbol = OptionSynthetic.GetOptionsSymbol(bars, OptionType.Call, bars.Close.LastValue, bars.EndDate, 3);                    // get the synthetic history and plot it - here we use the _iv series, not just one value          _osyn = OptionSynthetic.GetHistory(bars, symbol, _iv);          PlotBarHistory(_osyn, "OSYN", WLColor.LightCyan);       }       public override void Execute(BarHistory bars, int idx)       { }       BarHistory _osyn; // the option's BarHistory       IndicatorBase _hv;       TimeSeries _iv;       // IV estimate    } }
0
Cone8
 ( 4.92% )
- ago
#2
Here's an expanded example that compares the Synthetic pricing (light cyan) to the actual midpoint prices (green/red) in a 30 minute chart.

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; using WealthLab.InteractiveBrokers; namespace WealthScript6 {    public class SyntheticOptionBars : UserStrategyBase    {       public override void Initialize(BarHistory bars)       {                   if (bars.Scale.IsIntraday)          {             BarHistory dbars = WLHost.Instance.GetHistory(bars.Symbol, HistoryScale.Daily, DateTime.MinValue, DateTime.Now, 0, null);             _hv = new HV(dbars.Close, 21, 252);             _iv = TimeSeriesSynchronizer.Synchronize(_hv, bars.Close) / 100;          }          else          {             _hv = new HV(bars.Close, 21, 252);             _iv = _hv / 100.0;          }                          // ATM Call          string symbol = OptionSynthetic.GetOptionsSymbol(bars, OptionType.Call, bars.Close.LastValue, bars.EndDate, 3);                    // get the synthetic history and plot it - here we use the _iv series, not just one value          _osyn = OptionSynthetic.GetHistory(bars, symbol, _iv);          PlotBarHistory(_osyn, "OSYN", WLColor.LightCyan);          // compare with the true historical midpoint from IB          string ibSym = OptionsHelper.ConvertSymbol(symbol, 1);          BarHistory ibBars = GetHistory(bars, ibSym);          PlotBarHistory(ibBars, "OSYN");          PlotTimeSeries(_iv, "IV from HV", "IV", WLColor.FromArgb(255, 140, 140, 140), PlotStyle.Line);       }       public override void Execute(BarHistory bars, int idx)       { }       BarHistory _osyn; // the option's BarHistory       IndicatorBase _hv;       TimeSeries _iv;       // IV estimate    } }

0
Best Answer
- ago
#3
Thanks Cone for the code.
I had actually tried that without the expected results.
Essentially I want to see what the option price would be if the underlying price hypothetically changed to various levels. I tried using the gethistory function (trying to recalculate it in a loop every time I changed the hypothetical changed price) with various price changes on the bar history.
To test the validity of the underlying bar history price change affecting the calculated option price change, I set the price ridiculously high or low at which point the Delta should in theory approach 0 or 1 and option price would approach 0 or the value of (underlying-strike). Doing so only changes the calculated option price marginally.

Contemplating opening a concierge request to have you help me with my code, unless you think I just need to pay for an ibkrpro account to access the IBKR tools to calculate this type of hypothetical option price.
0
Cone8
 ( 4.92% )
- ago
#4
QUOTE:
Essentially I want to see what the option price would be if the underlying price hypothetically changed to various levels.
I can probably add another method to OptionSynthetic for that. Could be interesting.
0
- ago
#5
That would be amazing! Thanks Cone. I think that sort of method on OptionSynthetic would be an immensely powerful tool to allow calculation of gains for expected moves.

(PS I saw Glitch's post about meeting to brainstorm ways to improve another strategy. Having that hypothetical OptionSynthetic method could turbocharge that other algo (although seems like it was block-coded and there are no blocks for options).)
0

Reply

Bookmark

Sort