public static AugmentedGreeks OptionModelWrapper(string modelName, string ticker, string optionType, double strike, MySqlConnection conn, DateTime calculationDate, double optionPrice = double.NaN, double impliedVol = double.NaN, double underlyingPrice = double.NaN, DateTime?interestRateDate = null) { if (interestRateDate == null) { interestRateDate = calculationDate; } AugmentedGreeks AugmentedGreeksOutput = new AugmentedGreeks(); string UnderlyingTicker = GetOptionUnderlying(ticker); if (double.IsNaN(underlyingPrice)) { DataTable UnderlyingDataFrame = GetPrice.GetFuturesPrice.getFuturesPrice4Ticker(ticker: UnderlyingTicker, dateTimeFrom: calculationDate, dateTimeTo: calculationDate, conn: conn); if (UnderlyingDataFrame.Rows.Count == 0) { return(AugmentedGreeksOutput); } underlyingPrice = (double)(UnderlyingDataFrame.Rows[0].Field <decimal>("close_price")); } ContractUtilities.ContractSpecs ContractSpecsOut = ContractUtilities.ContractMetaInfo.GetContractSpecs(ticker: UnderlyingTicker); string TickerHead = ContractSpecsOut.tickerHead; double ContractMultiplier = ContractUtilities.ContractMetaInfo.ContractMultiplier[TickerHead]; string ExerciseType = ContractUtilities.ContractMetaInfo.GetOptionExerciseType(TickerHead); DateTime ExpirationDate = (DateTime)Expiration.getExpirationFromDB(ticker: ticker, instrument: "options", conn: conn); double InterestRate = InterestCurve.RateFromStir.GetSimpleRate(asOfDate: (DateTime)interestRateDate, dateFrom: (DateTime)interestRateDate, dateTo: ExpirationDate, tickerHead: "ED", conn: conn); if (Double.IsNaN(InterestRate)) { return(AugmentedGreeksOutput); } else { Greeks GreeksOutput = QuantlibOptionModels.GetOptionOnFutureGreeks(underlyingPrice: underlyingPrice, strike: strike, riskFreeRate: InterestRate, expirationDate: ExpirationDate, calculationDate: calculationDate, optionType: optionType, exerciseType: ExerciseType, optionPrice: optionPrice, impliedVol: impliedVol); AugmentedGreeksOutput.OptionPrice = GreeksOutput.OptionPrice; AugmentedGreeksOutput.ImpliedVol = 100 * GreeksOutput.ImpliedVol; AugmentedGreeksOutput.Delta = GreeksOutput.Delta; AugmentedGreeksOutput.Vega = GreeksOutput.Vega; AugmentedGreeksOutput.Theta = GreeksOutput.Theta; AugmentedGreeksOutput.CalDte = GreeksOutput.CalDte; AugmentedGreeksOutput.Gamma = GreeksOutput.Gamma; AugmentedGreeksOutput.DollarVega = GreeksOutput.Vega * ContractMultiplier / 100; AugmentedGreeksOutput.DollarTheta = GreeksOutput.Theta * ContractMultiplier; AugmentedGreeksOutput.DollarGamma = GreeksOutput.Gamma * ContractMultiplier; AugmentedGreeksOutput.InterestRate = InterestRate; } return(AugmentedGreeksOutput); }
public static AugmentedGreeks OptionModelWrapper(string modelName,string ticker, string optionType, double strike,MySqlConnection conn, DateTime calculationDate,double optionPrice=double.NaN,double impliedVol=double.NaN,double underlyingPrice=double.NaN,DateTime? interestRateDate = null) { if (interestRateDate==null) { interestRateDate = calculationDate; } AugmentedGreeks AugmentedGreeksOutput = new AugmentedGreeks(); string UnderlyingTicker = GetOptionUnderlying(ticker); if (double.IsNaN(underlyingPrice)) { DataTable UnderlyingDataFrame = GetPrice.GetFuturesPrice.getFuturesPrice4Ticker(ticker: UnderlyingTicker, dateTimeFrom: calculationDate, dateTimeTo: calculationDate, conn: conn); if (UnderlyingDataFrame.Rows.Count == 0) { return AugmentedGreeksOutput; } underlyingPrice = (double)(UnderlyingDataFrame.Rows[0].Field<decimal>("close_price")); } ContractUtilities.ContractSpecs ContractSpecsOut = ContractUtilities.ContractMetaInfo.GetContractSpecs(ticker: UnderlyingTicker); string TickerHead = ContractSpecsOut.tickerHead; double ContractMultiplier = ContractUtilities.ContractMetaInfo.ContractMultiplier[TickerHead]; string ExerciseType = ContractUtilities.ContractMetaInfo.GetOptionExerciseType(TickerHead); DateTime ExpirationDate = (DateTime)Expiration.getExpirationFromDB(ticker: ticker, instrument: "options", conn: conn); double InterestRate = InterestCurve.RateFromStir.GetSimpleRate(asOfDate: (DateTime)interestRateDate, dateFrom: (DateTime)interestRateDate, dateTo: ExpirationDate, tickerHead: "ED", conn: conn); if (Double.IsNaN(InterestRate)) { return AugmentedGreeksOutput; } else { Greeks GreeksOutput = QuantlibOptionModels.GetOptionOnFutureGreeks(underlyingPrice: underlyingPrice, strike: strike, riskFreeRate: InterestRate, expirationDate: ExpirationDate, calculationDate: calculationDate, optionType: optionType, exerciseType: ExerciseType, optionPrice: optionPrice,impliedVol:impliedVol); AugmentedGreeksOutput.OptionPrice = GreeksOutput.OptionPrice; AugmentedGreeksOutput.ImpliedVol = 100*GreeksOutput.ImpliedVol; AugmentedGreeksOutput.Delta = GreeksOutput.Delta; AugmentedGreeksOutput.Vega = GreeksOutput.Vega; AugmentedGreeksOutput.Theta = GreeksOutput.Theta; AugmentedGreeksOutput.CalDte = GreeksOutput.CalDte; AugmentedGreeksOutput.Gamma = GreeksOutput.Gamma; AugmentedGreeksOutput.DollarVega = GreeksOutput.Vega*ContractMultiplier/100; AugmentedGreeksOutput.DollarTheta = GreeksOutput.Theta*ContractMultiplier; AugmentedGreeksOutput.DollarGamma = GreeksOutput.Gamma*ContractMultiplier; AugmentedGreeksOutput.InterestRate = InterestRate; } return AugmentedGreeksOutput; }