public static string GetOptionUnderlying(string ticker) { ContractUtilities.ContractSpecs ContSpecsOutput = ContractUtilities.ContractMetaInfo.GetContractSpecs(ticker); string TickerHead = ContSpecsOutput.tickerHead; int TickerYear = ContSpecsOutput.tickerYear; int TickerMonthNum = ContSpecsOutput.tickerMonthNum; int UnderlyingMonthNum; int UnderlyingYear; if (TickerHead == "E0") { TickerHead = "ED"; TickerYear = TickerYear + 1; } else if (TickerHead == "E2") { TickerHead = "ED"; TickerYear = TickerYear + 2; } else if (TickerHead == "E3") { TickerHead = "ED"; TickerYear = TickerYear + 3; } else if (TickerHead == "E4") { TickerHead = "ED"; TickerYear = TickerYear + 4; } else if (TickerHead == "E5") { TickerHead = "ED"; TickerYear = TickerYear + 5; } List <string> FuturesContractMonthsOutput = ContractUtilities.ContractMetaInfo.FuturesContractMonths[TickerHead]; List <int> ContractMonthNumbers = new List <int>(); foreach (string item in FuturesContractMonthsOutput) { ContractMonthNumbers.Add(ContractUtilities.ContractMetaInfo.fullLetterMonthList.FindIndex(x => x == item) + 1); } List <int> LeadingMonths = ContractMonthNumbers.Where(x => x >= TickerMonthNum).ToList(); if (LeadingMonths.Count > 0) { UnderlyingMonthNum = LeadingMonths[0]; UnderlyingYear = TickerYear; } else { UnderlyingMonthNum = ContractMonthNumbers[0]; UnderlyingYear = TickerYear + 1; } return(TickerHead + ContractUtilities.ContractMetaInfo.fullLetterMonthList[UnderlyingMonthNum - 1] + UnderlyingYear.ToString()); }
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 ContractSpecs GetContractSpecs(string ticker) { ContractSpecs specsOutput = new ContractSpecs(); specsOutput.tickerHead = ticker.Substring(0, ticker.Count() - 5); specsOutput.tickerYear = Convert.ToInt16(ticker.Substring(ticker.Count() - 4, 4)); specsOutput.tickerMonthStr = ticker.Substring(ticker.Count() - 5, 1); specsOutput.tickerMonthNum = fullLetterMonthList.FindIndex(x => x == specsOutput.tickerMonthStr) + 1; specsOutput.tickerClass = tickerClassDict[specsOutput.tickerHead]; specsOutput.contINDX = 100 * specsOutput.tickerYear + specsOutput.tickerMonthNum; return(specsOutput); }
public static ttapiTicker ConvertFromDbTicker2ttapiTicker(string dbTicker, string productType) { ttapiTicker ttapiTickerOut = new ttapiTicker(); string ProductType = productType.ToUpper(); string exchangeName; if (ProductType == "FUTURE") { ContractUtilities.ContractSpecs contractSpecsOut = ContractUtilities.ContractMetaInfo.GetContractSpecs(dbTicker); ttapiTickerOut.productName = TA.TickerheadConverters.ConvertFromDB2TT(contractSpecsOut.tickerHead); ttapiTickerOut.productType = "FUTURE"; exchangeName = ContractUtilities.ContractMetaInfo.GetExchange4Tickerhead(contractSpecsOut.tickerHead); ttapiTickerOut.SeriesKey = ConvertMonthFromDB2TT(contractSpecsOut.tickerMonthStr) + (contractSpecsOut.tickerYear % 100).ToString(); } else if (ProductType == "SPREAD") { string[] TickerList = dbTicker.Split(new char[] { '-' }); ContractUtilities.ContractSpecs contractSpecsOut = ContractUtilities.ContractMetaInfo.GetContractSpecs(TickerList[0]); ttapiTickerOut.productName = TA.TickerheadConverters.ConvertFromDB2TT(contractSpecsOut.tickerHead); ttapiTickerOut.productType = "SPREAD"; string SeriesKey; exchangeName = ContractUtilities.ContractMetaInfo.GetExchange4Tickerhead(contractSpecsOut.tickerHead); if (exchangeName == "CME") { SeriesKey = "Calendar: 1x" + ttapiTickerOut.productName + " " + ConvertMonthFromDB2TT(contractSpecsOut.tickerMonthStr) + (contractSpecsOut.tickerYear % 100).ToString(); for (int i = 1; i < TickerList.Length; i++) { contractSpecsOut = ContractUtilities.ContractMetaInfo.GetContractSpecs(TickerList[i]); SeriesKey = SeriesKey + ":-1x" + ConvertMonthFromDB2TT(contractSpecsOut.tickerMonthStr) + (contractSpecsOut.tickerYear % 100).ToString(); } } else if (exchangeName == "ICE") { SeriesKey = ttapiTickerOut.productName + " Spread " + ConvertMonthFromDB2TT(contractSpecsOut.tickerMonthStr) + (contractSpecsOut.tickerYear % 100).ToString(); for (int i = 1; i < TickerList.Length; i++) { contractSpecsOut = ContractUtilities.ContractMetaInfo.GetContractSpecs(TickerList[i]); SeriesKey = SeriesKey + "/" + ConvertMonthFromDB2TT(contractSpecsOut.tickerMonthStr) + (contractSpecsOut.tickerYear % 100).ToString(); } } else { SeriesKey = ""; } ttapiTickerOut.SeriesKey = SeriesKey; } else { return(ttapiTickerOut); } ttapiTickerOut.marketKey = ""; if (exchangeName == "ICE") { ttapiTickerOut.marketKey = "ICE_IPE"; } else if (exchangeName == "CME") { ttapiTickerOut.marketKey = "CME"; } ttapiTickerOut.instrumentName = ttapiTickerOut.marketKey + " " + ttapiTickerOut.productName + " " + ttapiTickerOut.SeriesKey; return(ttapiTickerOut); }
public static ContractSpecs GetContractSpecs(string ticker) { ContractSpecs specsOutput = new ContractSpecs(); specsOutput.tickerHead = ticker.Substring(0, ticker.Count() - 5); specsOutput.tickerYear = Convert.ToInt16(ticker.Substring(ticker.Count() - 4, 4)); specsOutput.tickerMonthStr = ticker.Substring(ticker.Count() - 5, 1); specsOutput.tickerMonthNum = fullLetterMonthList.FindIndex(x => x == specsOutput.tickerMonthStr) + 1; specsOutput.tickerClass = tickerClassDict[specsOutput.tickerHead]; specsOutput.contINDX = 100*specsOutput.tickerYear + specsOutput.tickerMonthNum; return specsOutput; }