/// <summary> /// Generates a notional schedule. /// </summary> /// <param name="initialValue">The initial value of the schedule to be generated.</param> /// <param name="step">The step value.</param> /// <param name="applyStepToEachNthCashflow">The frequency to apply the step.</param> /// <param name="totalNumberOfCashflows">The number of cashflows in the array.</param> /// <returns>A vertical array of notionals.</returns> public object[,] GetNotionalSchedule(double initialValue, double step, int applyStepToEachNthCashflow, int totalNumberOfCashflows) { var notionalSchedule = NotionalScheduleGenerator.GetNotionalSchedule(initialValue, step, applyStepToEachNthCashflow, totalNumberOfCashflows); var result = RangeHelper.ConvertArrayToRange(notionalSchedule); return(result); }
/// <summary> /// Values a digital option with greeks. /// </summary> /// <param name="callFlag"></param> /// <param name="fwdPrice"></param>. /// <param name="strike"></param> /// <param name="vol"></param> /// <param name="t"></param> /// <returns>value, d_dfwdPrice, d2_dfwdPrice2, d_dvol, d_dstrike, d2_dstrike2, d_dt</returns> public object[,] DigitalWithGreeks(bool callFlag, double fwdPrice, double strike, double vol, double t) { var unqVals = OptionAnalytics.DigitalWithGreeks(callFlag, fwdPrice, strike, vol, t); var result = RangeHelper.ConvertArrayToRange(unqVals); return(result); }
/// <summary> /// The supported day counters as a list. /// </summary> /// <returns></returns> public object[,] SupportedDayCounters() { var indices = Enum.GetValues(typeof(DayCountFractionEnum)).Cast <DayCountFractionEnum>().Select(DayCountFractionScheme.GetEnumString).Where(index => index != null).ToList(); var result = RangeHelper.ConvertArrayToRange(indices); return(result); }
/// <summary> /// Gets the unadjusted dates from effective date. /// </summary> /// <param name="effectiveDate">The effective date.</param> /// <param name="terminationDate">The termination date.</param> /// <param name="periodInterval">The period interval.</param> /// <param name="rollConvention">The roll convention.</param> /// <param name="firstRegularPeriodStartDate">The first regular period start date.</param> /// <param name="lastRegularPeriodEndDate">The last regular period end date.</param> /// <returns>A vertical arrray of dates.</returns> public object[,] UnadjustedDatesFromEffectiveDate(DateTime effectiveDate, DateTime terminationDate, string periodInterval, string rollConvention, out DateTime firstRegularPeriodStartDate, out DateTime lastRegularPeriodEndDate) { var dates = DateScheduler.UnadjustedDatesFromEffectiveDate(effectiveDate, terminationDate, periodInterval, rollConvention, out firstRegularPeriodStartDate, out lastRegularPeriodEndDate); var result = RangeHelper.ConvertArrayToRange(dates); return(result); }
/// <summary> /// Valuation of a regular chooser option: /// The pricing model values this as the sum of a call option of expiry tL /// and strike strike, plus a put option of expiry tS and strike strike * df(tS,tL) /// where df(tS,tL) is the discount function between dates tS and tL. /// </summary> /// <param name="fwdPrice">Outright: to pay now for assured delivery of asset at tL</param> /// <param name="vol">Volatility</param> /// <param name="tS">Time to date where choice has to be made (years)</param> /// <param name="tL">Time to expiry of underlying option (years; must be greater than tS)</param> /// <param name="strike">strike of option</param> /// <param name="rL">exp(-rL.tL) is DF from now to time tL</param> /// <returns>An array of calculated doubles: Premium, delta, gamma, vega, rhoL, thetal, thetaS.</returns> public object[,] ChooserOpt(double fwdPrice, double vol, double tS, double tL, double strike, double rL) { var unqVals = OptionAnalytics.ChooserOpt(fwdPrice, vol, tS, tL, strike, rL); var result = RangeHelper.ConvertArrayToRange(unqVals); return(result); }
/// <summary> /// A function to return the list of valid indices, which may or may not have been impletented. /// </summary> /// <returns>A range object</returns> public object[,] SupportedCentralBanks() { //var names = Enum.GetNames(typeof(FloatingRateIndexEnum)); var indices = Enum.GetNames(typeof(CentralBanks)); var result = RangeHelper.ConvertArrayToRange(indices); return(result); }
/// <summary> /// /// </summary> /// <param name="rateAsArray"></param> /// <param name="compoundingFrequency"></param> /// <returns></returns> public object[,] ConvToContinuousRate(Excel.Range rateAsArray, string compoundingFrequency) { var rate = DataRangeHelper.StripDoubleRange(rateAsArray); var retArray = EquitiesLibrary.ConvToContinuousRate(rate.ToArray(), compoundingFrequency); var result = RangeHelper.ConvertArrayToRange(retArray); return(result); }
/// <summary> /// A function to return the list of valid FpML calendars. /// </summary> /// <returns>A range object</returns> public object[,] SupportedBusinessCenters() { var cals = (from BusinessCenterEnum item in Enum.GetValues(typeof(BusinessCenterEnum)) select BusinessCenterScheme.GetEnumString(item) into bc where bc != null select bc).ToList(); //var names = Enum.GetNames(typeof(BusinessCenterEnum)); var result = RangeHelper.ConvertArrayToRange(cals); return(result); }
/// <summary> /// Adds the period to an array of dates. /// </summary> /// <param name="dateArray">The dates as an array.</param> /// <param name="dayType">The day type.</param> /// <param name="periodInterval">The period interval.</param> /// <param name="businessDayConvention">The business day convention.</param> /// <param name="location">The calendar. </param> /// <returns>A range of dates.</returns> public object[,] AddPeriods1(Excel.Range dateArray, string dayType, string periodInterval, string businessDayConvention, string location) { List <DateTime> dateVals = DataRangeHelper.StripDateTimeRange(dateArray); List <DateTime> periods = CalendarService.AddPeriods(dateVals.ToArray(), dayType, periodInterval, businessDayConvention, new[] { location }); var resVals = RangeHelper.ConvertArrayToRange(periods); return(resVals); }
/// <summary> /// Adds the period to an array of dates. /// </summary> /// <param name="baseDate">The base dates.</param> /// <param name="dayType">The day type.</param> /// <param name="periodArray">The period interval array.</param> /// <param name="businessDayConvention">The business day convention.</param> /// <param name="location">The calendar. </param> /// <returns>A range of dates.</returns> public object[,] AddManyPeriods(DateTime baseDate, string dayType, Excel.Range periodArray, string businessDayConvention, string location) { List <string> periodVals = DataRangeHelper.StripRange(periodArray); List <DateTime> periods = CalendarService.AddPeriods(baseDate, dayType, periodVals.ToArray(), businessDayConvention, new[] { location }); var resVals = RangeHelper.ConvertArrayToRange(periods); return(resVals); }
/// <summary> /// Gets the Last trading day by year. This takes an array of years. /// </summary> /// <param name="exchangeCommodityName">Name of the exchange commodity.</param> /// <param name="yearsArray">The array of years as integers.</param> /// <param name="mainCycle">if set to <c>true</c> [main cycle].</param> /// <returns>A range of dates.</returns> public object[,] LastTradingDayByYear(string exchangeCommodityName, Excel.Range yearsArray, Boolean mainCycle) { List <int> unqVals = DataRangeHelper.StripIntRange(yearsArray); var dates = LastTradingDayHelper.GetLastTradingDays(exchangeCommodityName, unqVals.ToArray(), mainCycle); var resVals = RangeHelper.ConvertArrayToRange(dates); return(resVals); }
/// <summary> /// Creates the datatime vector for the request Central Bank. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="validCentralBank">The requested central bank.</param> /// <param name="centralBankDateRuleMonths">The rules.</param> /// <param name="lastDate">The last date required.</param> /// <returns>An aray of relevant dates.</returns> public object[,] GetCentralBankDates(DateTime baseDate, string validCentralBank, int centralBankDateRuleMonths, DateTime lastDate) { var result = CentralBanksHelper.GetCBDates(baseDate, validCentralBank, centralBankDateRuleMonths, lastDate); var resVals = RangeHelper.ConvertArrayToRange(result); return(resVals); }
/// <summary> /// To value and work out sensitivities for an option where the forward value of the asset /// is fwdPrice.exp(corr.vol1.vol2.t) /// </summary> /// <param name="callFlag"></param> /// <param name="fwdPrice"></param> /// <param name="strike"></param> /// <param name="vol1"></param> /// <param name="vol2"></param> /// <param name="corr"></param> /// <param name="t"></param> /// <returns>value, d_dfwdPrice, d2_dfwdPrice2, d_dvol1, d_dvol2, d_dcorr, d_dt, </returns> public object[,] QOptWithGreeks(Boolean callFlag, double fwdPrice, double strike, double vol1, double vol2, double corr, double t) { var unqVals = OptionAnalytics.QOptWithGreeks(callFlag, fwdPrice, strike, vol1, vol2, corr, t); var result = RangeHelper.ConvertArrayToRange(unqVals); return(result); }
/// <summary> /// Gets the Last trading based on a given month. /// </summary> /// <param name="exchangeCommodityName">Name of the exchange commodity.</param> /// <param name="monthsArray">The array of months.</param> /// <param name="yearsArray">The array of years as integers.</param> /// <returns></returns> public object[,] LastTradingDayByMonth(string exchangeCommodityName, Excel.Range monthsArray, Excel.Range yearsArray) { List <int> unqMonths = DataRangeHelper.StripIntRange(monthsArray); List <int> unqYears = DataRangeHelper.StripIntRange(yearsArray); List <DateTime> dates = LastTradingDayHelper.GetLastTradingDays(exchangeCommodityName, unqMonths.ToArray(), unqYears.ToArray()); var resVals = RangeHelper.ConvertArrayToRange(dates); return(resVals); }
/// <summary> /// Gets the unadjusted calculation period start dates. /// </summary> /// <param name="effectiveDate">The effective date.</param> /// <param name="terminationDate">The termination date.</param> /// <param name="periodInterval">The period interval.</param> /// <param name="rollConvention">The roll convention.</param> /// <param name="firstRegularPeriodDate">The first regular period date.</param> /// <param name="stubPeriodType">Type of the stub period.</param> /// <returns>A vertival range of dates.</returns> public object[,] GetUnadjustedCalculationPeriodDates(DateTime effectiveDate, DateTime terminationDate, string periodInterval, string rollConvention, DateTime firstRegularPeriodDate, string stubPeriodType) { var dates = DateScheduler.GetUnadjustedCalculationPeriodDates(effectiveDate, terminationDate, periodInterval, rollConvention, firstRegularPeriodDate, stubPeriodType); var result = RangeHelper.ConvertArrayToRange(dates); return(result); }
/// <summary> /// Adjusteds the dates from effective date. /// </summary> /// <param name="effectiveDate">The effective date.</param> /// <param name="terminationDate">The termination date.</param> /// <param name="periodInterval">The period interval.</param> /// <param name="rollConvention">The roll convention.</param> /// <param name="businessCenters">The business centers.</param> /// <param name="dateAdjustmentConvention">The date adjustment convention.</param> /// <returns>A vertical arrray of dates.</returns> public object[,] AdjustedDatesFromEffectiveDate(DateTime effectiveDate, DateTime terminationDate, string periodInterval, string rollConvention, string businessCenters, string dateAdjustmentConvention) { BusinessCenters centers = BusinessCentersHelper.Parse(businessCenters); IBusinessCalendar calendar = Engine.ToBusinessCalendar(centers); var adjustments = EnumHelper.Parse <BusinessDayConventionEnum>(dateAdjustmentConvention); var adjustedDateSchedule = AdjustedDateScheduler.AdjustedDatesFromEffectiveDate(effectiveDate, terminationDate, periodInterval, rollConvention, calendar, adjustments); var result = RangeHelper.ConvertArrayToRange(adjustedDateSchedule); return(result); }
/// <summary> /// Gets the greeks. /// </summary> /// <param name="style">The style.</param> /// <param name="spot">The spot.</param> /// <param name="strike">The strike.</param> /// <param name="vol">The vol.</param> /// <param name="expiry"></param> /// <param name="paystyle">The paystyle.</param> /// <param name="zeroDatesAsArray"></param> /// <param name="zeroRatesAsArray">The zero curve.</param> /// <param name="divDatesAsArray"></param> /// <param name="divAmsAsArray">The div curve.</param> /// <param name="gridsteps">The gridsteps.</param> /// <param name="smoo">The smoo.</param> /// <param name="flatFlag">if set to <c>true</c> [flat flag].</param> /// <param name="today"></param> /// <returns></returns> public object[,] BinomialRelativeGetGreeks(string style, double spot, double strike, double vol, DateTime today, DateTime expiry, string paystyle, Excel.Range zeroDatesAsArray, Excel.Range zeroRatesAsArray, Excel.Range divDatesAsArray, Excel.Range divAmsAsArray, double gridsteps, string smoo, bool flatFlag) { var zeroDates = DataRangeHelper.StripDateTimeRange(zeroDatesAsArray); var zeroRates = DataRangeHelper.StripDoubleRange(zeroRatesAsArray); var divDates = DataRangeHelper.StripDateTimeRange(divDatesAsArray); var divAms = DataRangeHelper.StripDoubleRange(divAmsAsArray); var retArray = EquitiesLibrary.BinomialRelativeGetGreeks(style, spot, strike, vol, today, expiry, paystyle, zeroDates.ToArray(), zeroRates.ToArray(), divDates.ToArray(), divAms.ToArray(), gridsteps, smoo, flatFlag); var result = RangeHelper.ConvertArrayToRange(retArray); return(result); }
/// <summary> /// Returns the unadjusted the calculation dates /// </summary> /// <param name="effectiveDate">The effective date.</param> /// <param name="terminationDate">The termination date.</param> /// <param name="intervalToFirstRegularPeriodStart">The interval to first regular period start.</param> /// <param name="periodInterval">The period interval.</param> /// <param name="rollConvention">The roll convention.</param> /// <param name="stubPeriodType">Type of the stub period.</param> /// <returns>A vertical arrray of dates.</returns> public object[,] UnadjustedCalculationDatesFromFirstRegularInterval(DateTime effectiveDate, DateTime terminationDate, string intervalToFirstRegularPeriodStart, string periodInterval, string rollConvention, string stubPeriodType) { var dates = DateScheduler.UnadjustedCalculationDatesFromFirstRegularInterval(effectiveDate, terminationDate, intervalToFirstRegularPeriodStart, periodInterval, rollConvention, stubPeriodType); var result = RangeHelper.ConvertArrayToRange(dates); return(result); }
/// <summary> /// Gets the adjusted calculation period start dates. /// </summary> /// <param name="effectiveDate">The effective date.</param> /// <param name="terminationDate">The termination date.</param> /// <param name="periodInterval">The period interval.</param> /// <param name="rollConvention">The roll convention.</param> /// <param name="firstRegularPeriodDate">The first regular period date.</param> /// <param name="stubPeriodType">Type of the stub period.</param> /// <param name="calendars">The holiday array.</param> /// <param name="businessDayConvention">The business day convention.</param> /// <returns>A vertival range of dates.</returns> public object[,] GetAdjustedCalculationPeriodDates(DateTime effectiveDate, DateTime terminationDate, string periodInterval, string rollConvention, DateTime firstRegularPeriodDate, string stubPeriodType, Excel.Range calendars, string businessDayConvention) { List <string> unqVals = DataRangeHelper.StripRange(calendars); IBusinessCalendar businessCalendar = CalendarService.GetCalendar(unqVals.ToArray()); var dates = AdjustedDateScheduler.GetAdjustedCalculationPeriodDates(effectiveDate, terminationDate, periodInterval, rollConvention, firstRegularPeriodDate, stubPeriodType, businessCalendar, businessDayConvention); var result = RangeHelper.ConvertArrayToRange(dates); return(result); }
/// <summary> /// /// </summary> /// <param name="baseAmount"></param> /// <param name="valueDate"></param> /// <param name="finalDatesAsArray"></param> /// <param name="paymentDatesAsArray"></param> /// <param name="paymentAmountsAsArray"></param> /// <param name="zeroDatesAsArray"></param> /// <param name="zeroRatesAsArray"></param> /// <returns></returns> public object[,] DivYield(double baseAmount, DateTime valueDate, Excel.Range finalDatesAsArray, Excel.Range paymentDatesAsArray, Excel.Range paymentAmountsAsArray, Excel.Range zeroDatesAsArray, Excel.Range zeroRatesAsArray) { var finalDates = DataRangeHelper.StripDateTimeRange(finalDatesAsArray); var paymentDates = DataRangeHelper.StripDateTimeRange(paymentDatesAsArray); var paymentAmounts = DataRangeHelper.StripDoubleRange(paymentAmountsAsArray); var zeroDates = DataRangeHelper.StripDateTimeRange(zeroDatesAsArray); var zeroRates = DataRangeHelper.StripDoubleRange(zeroRatesAsArray); var retArray = EquitiesLibrary.DivYield(baseAmount, valueDate, finalDates.ToArray(), paymentDates.ToArray(), paymentAmounts.ToArray(), zeroDates.ToArray(), zeroRates.ToArray()); var result = RangeHelper.ConvertArrayToRange(retArray); return(result); }
/// <summary> /// Gets a dates schedule. /// </summary> /// <param name="metaScheduleDefinitionRange">This must have 3 columns: interval, interval, rollconventionenum.</param> /// <param name="startDate">The start date of the schedule to be generated.</param> /// <param name="calendar">The relevant calendar.</param> /// <param name="businessDayAdjustment">The business day adjustments.</param> /// <returns>A vertical arrray of dates.</returns> public object[,] GetMetaDatesSchedule(Excel.Range metaScheduleDefinitionRange, DateTime startDate, string calendar, string businessDayAdjustment) { var values = metaScheduleDefinitionRange.Value[System.Reflection.Missing.Value] as object[, ]; List <ThreeStringsRangeItem> metaScheduleDefinition = ObjectToArrayOfPropertiesConverter.CreateListFromHorizontalArrayRange <ThreeStringsRangeItem>(values); BusinessCenters centers = BusinessCentersHelper.Parse(calendar); IBusinessCalendar businessCalendar = Engine.ToBusinessCalendar(centers); var metaSchedule = AdjustedDatesMetaSchedule.GetMetaDatesSchedule(metaScheduleDefinition, startDate, businessCalendar, calendar, businessDayAdjustment); var result = RangeHelper.ConvertArrayToRange(metaSchedule); return(result); }
/// <summary> /// Returns the calculated year fraction for the dates provided. /// </summary> /// <param name="startDateArray">The start date array.</param> /// <param name="endDateArray">The end date arrray.</param> /// <param name="dayCountType">The day count fraction type, eg Actual/365.</param> /// <returns>The year fractions as a range of decimals.</returns> public object[,] YearFractions(Excel.Range startDateArray, Excel.Range endDateArray, string dayCountType) { var unqStartDateVals = DataRangeHelper.StripDateTimeRange(startDateArray); var unqEndDateVals = DataRangeHelper.StripDateTimeRange(endDateArray); int count = unqStartDateVals.Count; if (count != unqEndDateVals.Count) { throw new ArgumentException("Size of startDates and endDates arrays must match"); } IDayCounter dayCounter = DayCounterHelper.Parse(dayCountType); var yearFractions = new List <double>(); for (int i = 0; i < count; i++) { yearFractions.Add(dayCounter.YearFraction(unqStartDateVals[i], unqEndDateVals[i])); } return(RangeHelper.ConvertArrayToRange(yearFractions)); }
/// <summary> /// SpreadOptWithGreeks /// </summary> /// <param name="nSteps"></param> /// <param name="fwdPrice1">price fixable now for purchase of asset 1 at time t</param> /// <param name="fwdPrice2">price fixable now for purchase of asset 2 at time t</param> /// <param name="strike">strike</param> /// <param name="vol1">volatility of asset 1</param> /// <param name="vol2">volatility of asset 2</param> /// <param name="corr">correlation coefficient</param> /// <param name="t">time to option expiry in years</param> /// <returns>delta1, delta2, gamma11, gamma22, /// gamma12, vega1, vega2, corrSens, theta and the nsteps</returns> public object[,] SpreadOptWithGreeks(long nSteps, double fwdPrice1, // price fixable now for purchase of asset 1 at time t double fwdPrice2, // price fixable now for purchase of asset 2 at time t double strike, // strike double vol1, // volatility of asset 1 double vol2, // volatility of asset 2 double corr, // correlation coefficient double t) // time to option expiry in years { var unqVals = OptionAnalytics.SpreadOptWithGreeks(nSteps, fwdPrice1, // price fixable now for purchase of asset 1 at time t fwdPrice2, // price fixable now for purchase of asset 2 at time t strike, // strike vol1, // volatility of asset 1 vol2, // volatility of asset 2 corr, // correlation coefficient t); var result = RangeHelper.ConvertArrayToRange(unqVals); return(result); }
/// <summary> /// A simple basket option model. /// </summary> /// <param name="nSteps"></param> /// <param name="fwdPrice1">Price fixable now for purchase of asset 1 at time t</param> /// <param name="fwdPrice2">Price fixable now for purchase of asset 2 at time t</param> /// <param name="strike">Strike</param> /// <param name="vol1">Volatility of asset 1</param> /// <param name="vol2">Volatility of asset 2</param> /// <param name="corr">Correlation coefficient</param> /// <param name="t">Time to option expiry in years</param> /// <returns>A vector of value and greeks.</returns> public object[,] BasketOption( long nSteps, double fwdPrice1, double fwdPrice2, double strike, double vol1, double vol2, double corr, double t) { var unqVals = OptionAnalytics.BasketOption( nSteps, fwdPrice1, fwdPrice2, strike, vol1, vol2, corr, t); var result = RangeHelper.ConvertArrayToRange(unqVals); return(result); }