protected override void FillStrikeInfo(IOptionStrike optionStrike, StrikeInfo stInfo) { switch (optionStrike.StrikeType) { case StrikeType.Call: stInfo.Call = optionStrike.FinInfo.Ask ?? Constants.NaN; break; case StrikeType.Put: stInfo.Put = optionStrike.FinInfo.Ask ?? Constants.NaN; break; default: return; } }
protected override IEnumerable <Double2> Calculate(IOptionStrike[] strikes) { var bidList = new List <Double2>(); var finArray = new Dictionary <double, StrikeInfo>(); foreach (var optionStrike in strikes) { if (!finArray.ContainsKey(optionStrike.Strike)) { var lastUpdate = optionStrike.FinInfo.LastUpdate; if (lastUpdate == DateTime.MinValue) { continue; } var stInfo = new StrikeInfo { ExpDate = OptionUtils.YearsBetweenDates(optionStrike.ExpirationDate, lastUpdate), BasePrice = optionStrike.UnderlyingAsset.FinInfo.LastPrice ?? 0 }; FillStrikeInfo(optionStrike, stInfo); finArray.Add(optionStrike.Strike, stInfo); } else { var key = optionStrike.Strike; var stInfo = finArray[key]; FillStrikeInfo(optionStrike, stInfo); } } // выход, пустой список if (finArray.Count == 0) { return(bidList); } // расчет волатильностей foreach (var strikeInfo in finArray) { double precision; var callSigma = (strikeInfo.Value.Call != 0.0) ? FinMath.GetOptionSigma(strikeInfo.Value.BasePrice, strikeInfo.Key, strikeInfo.Value.ExpDate, strikeInfo.Value.Call, 0.0, true, out precision) : 0; var putSigma = (strikeInfo.Value.Put != 0.0) ? FinMath.GetOptionSigma(strikeInfo.Value.BasePrice, strikeInfo.Key, strikeInfo.Value.ExpDate, strikeInfo.Value.Put, 0.0, false, out precision) : 0; strikeInfo.Value.CallSigma = callSigma; strikeInfo.Value.PutSigma = putSigma; if (putSigma == 0 && callSigma == 0) { continue; } // добавим значение bidList.Add(new Double2 { V1 = strikeInfo.Key, V2 = Math.Max(callSigma, putSigma) * 100.0 }); } return(bidList); }
protected abstract void FillStrikeInfo(IOptionStrike optionStrike, StrikeInfo stInfo);