private void LoadData() { string riskFreeRatesFile = @"C:\Users\Rubens\Google Drive\Mestrado\Projeto_Pesquisa\vols3\cdi_20161124_154509.csv"; this.RiskFreeRates = this.GetRiskFreeRates(riskFreeRatesFile); string underlyingMarketDataFile = @"C:\Users\Rubens\Google Drive\Mestrado\Projeto_Pesquisa\vols3\underlying_20161124_154509.csv"; this.UnderlyingOrderBook = this.GetUnderlyingMarketData(underlyingMarketDataFile); string optionsMarketDataFile = @"C:\Users\Rubens\Google Drive\Mestrado\Projeto_Pesquisa\vols3\options_20161124_154509.csv"; this.OptionsMarketData = this.GetOptionsMarketData(optionsMarketDataFile); this.VolSurface = this.GetVolSurface(this.RiskFreeRates, this.UnderlyingOrderBook, this.OptionsMarketData); }
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; }