public void Update(OptionType type, VolQuote volQuote) { if (type == OptionType.Call) { this.UpdateCall(volQuote); } else { this.UpdatePut(volQuote); } }
public void Update(DateTime expiryDate, double strike, OptionType type, VolQuote volQuote) { VolExpiry existingExpiry = null; if (this.VolExpiries.TryGetValue(expiryDate, out existingExpiry)) { existingExpiry.Update(strike, type, volQuote); } else { VolExpiry volExpiry = new VolExpiry(expiryDate); volExpiry.Update(strike, type, volQuote); this.VolExpiries[expiryDate] = volExpiry; } }
public void Update(double strike, OptionType type, VolQuote volQuote) { VolStrike existingStrike = null; if (this.VolStrikes.TryGetValue(strike, out existingStrike)) { existingStrike.Update(type, volQuote); } else { VolStrike volStrike = new VolStrike(strike); volStrike.Update(type, volQuote); this.VolStrikes[strike] = volStrike; } }
private void UpdatePut(VolQuote volQuote) { this.VolPutQuote = volQuote; }
private void UpdateCall(VolQuote volQuote) { this.VolCallQuote = volQuote; }
private VolSurface GetVolSurface(SortedDictionary<DateTime, RiskFreeRate> riskFreeRates, OrderBook underlyingOrderBook, List<OptionMarketData> optionsMarketData) { double businessDaysInTheYear = 252; VolSurface volSurface = new VolSurface(); double spot = underlyingOrderBook.GetPriceMid(); foreach (OptionMarketData option in optionsMarketData) { RiskFreeRate riskFreeRate = null; riskFreeRates.TryGetValue(option.OptionInfo.ExpiryDate, out riskFreeRate); double timeToMaturity = riskFreeRate.BusinessDays / businessDaysInTheYear; double bid = (option.OrderBook.Bid != null) ? option.OrderBook.Bid.Value : 0.00; double bidSize = (option.OrderBook.BidSize != null) ? option.OrderBook.BidSize.Value : 0.00; ; double ask = (option.OrderBook.Ask != null) ? option.OrderBook.Ask.Value : 0.00; ; double askSize = (option.OrderBook.AskSize != null) ? option.OrderBook.AskSize.Value : 0.00; ; BlackScholes bs = new BlackScholes(); double bidImpliedVolatility = 0.00; double askImpliedVolatility = 0.00; if (bid > 0.00 && bidSize > 0.00) bidImpliedVolatility = bs.GetImpliedVolatility(option.OptionInfo.Type, bid, spot, option.OptionInfo.Strike, riskFreeRate.Rate, timeToMaturity); if (ask > 0.00 && askSize > 0.00) askImpliedVolatility = bs.GetImpliedVolatility(option.OptionInfo.Type, ask, spot, option.OptionInfo.Strike, riskFreeRate.Rate, timeToMaturity); if (!(bidImpliedVolatility > 0.0000)) bidImpliedVolatility = 0.00; if (!(askImpliedVolatility > 0.0000)) askImpliedVolatility = 0.00; VolQuote volQuote = new VolQuote(bidSize, askSize, bidImpliedVolatility, askImpliedVolatility); volSurface.Update(option.OptionInfo.ExpiryDate, option.OptionInfo.Strike, option.OptionInfo.Type, volQuote); } return volSurface; }