public bool SimpleImpliedVolatilityTest() { OptionType type = OptionType.Call; double strike = 31.21; double spot = 31.525; double volatility = 0.25116165; double riskFreeRate = 0.085209; double ttm = (double)35 / 365; EquityOptionStaticData staticData = new EquityOptionStaticData(type, strike, spot, volatility, riskFreeRate, ttm); IPriceable priceable = staticData.BuildPriceable(); double price = priceable.Price(); BlackScholes bs = new BlackScholes(); double volGuess = 0.25; double relTolerance = 0.00001; int maxAttempts = 10; price = 1.28; double impliedVol = bs.GetImpliedVolatility(type, price, spot, strike, riskFreeRate, ttm, volGuess, relTolerance, maxAttempts); double relDiff = Math.Abs(impliedVol - volatility) / volatility; if (relDiff <= relTolerance) { return(true); } else { return(false); } }
public double CallPrice() { OptionType type = OptionType.Call; double strike = 29.14; double spot = 27.04; double volatility = 0.47; double riskFreeRate = 0.1413; double ttm = 11 / 252; EquityOptionStaticData staticData = new EquityOptionStaticData(type, strike, spot, volatility, riskFreeRate, ttm); IPriceable priceable = staticData.BuildPriceable(); double price = priceable.Price(); return(price); }