Example #1
0
        /// <summary>
        /// Advances the specified date using the underlying calendar locations.
        /// </summary>
        /// <param name="locationsAsArray">The locations range as an array.</param>
        /// <param name="date">The date.</param>
        /// <param name="dayType">The day type: cakendat or business.</param>
        /// <param name="periodInteval">The period inteval.</param>
        /// <param name="businessDayConvention">The business day convention.</param>
        /// <returns>The adjusted date.</returns>
        public DateTime Advance(Excel.Range locationsAsArray, DateTime date, string dayType, string periodInteval, string businessDayConvention)
        {
            List <string> unqVals = DataRangeHelper.StripRange(locationsAsArray);
            var           result  = CalendarService.Advance(unqVals.ToArray(), date, dayType, periodInteval, businessDayConvention);

            return(result);
        }
Example #2
0
        /// <summary>
        /// Gets the value.
        /// </summary>
        /// <param name="pt">The pt.</param>
        /// <param name="interpolationType">The interpolation.</param>
        /// <param name="extrapolation">if set to <c>true</c> [extrapolation].</param>
        /// <param name="times">A vetical array of times.</param>
        /// <param name="values">A vertical array of values.</param>
        /// <returns>The value at that point.</returns>
        public Double GetPointValue(Double pt, string interpolationType, bool extrapolation, Excel.Range times, Excel.Range values)
        {
            List <double> unqtimes  = DataRangeHelper.StripDoubleRange(times);
            List <double> unqvalues = DataRangeHelper.StripDoubleRange(values);

            return(CurveAnalytics.GetValue(pt, interpolationType, extrapolation, unqtimes.ToArray(), unqvalues.ToArray()));
        }
Example #3
0
        ///<summary>
        /// Sttrips a surface: expiry by strike, from a flattened cube, excluding the strike headers.
        ///</summary>
        ///<param name="inputRange">The input data range.</param>
        ///<param name="tenorFilter">The tenor string to filter on.</param>
        ///<param name="numTenors">The number of tenors.</param>
        ///<param name="strikeArray">The strike array.</param>
        ///<returns></returns>
        public double[,] FilterSurface(Excel.Range inputRange, String tenorFilter, int numTenors, Excel.Range strikeArray)
        {
            var values = inputRange.get_Value(System.Reflection.Missing.Value) as object[, ];
            var strike = DataRangeHelper.StripDoubleRange(strikeArray);

            return(DataRangeHelper.FilterSurface(values, tenorFilter, numTenors, strike.ToArray()));
        }
Example #4
0
        /// <summary>
        /// Determines whether the specified date is a business day.
        /// </summary>
        /// <param name="locationsAsArray">The locations range as an array.</param>
        /// <param name="date">The date.</param>
        /// <returns></returns>
        public Boolean IsBusinessDay(Excel.Range locationsAsArray, DateTime date)
        {
            List <string> unqVals = DataRangeHelper.StripRange(locationsAsArray);
            var           result  = CalendarService.IsBusinessDay(unqVals.ToArray(), date);

            return(result);
        }
Example #5
0
        ///<summary>
        /// Gets the interpolated value from the curve.
        ///</summary>
        ///<param name="baseDate">The based date.</param>
        ///<param name="targetDate">The target date.</param>
        /// <param name="interpolationType">The interpolation.</param>
        /// <param name="extrapolation">if set to <c>true</c> [extrapolation].</param>
        /// <param name="times">A vetical array of times.</param>
        /// <param name="values">A vertical array of values.</param>
        /// <returns>The value at that point.</returns>
        public Double GetDateValue(DateTime baseDate, DateTime targetDate, string interpolationType, bool extrapolation, Excel.Range times, Excel.Range values)
        {
            List <double> unqtimes  = DataRangeHelper.StripDoubleRange(times);
            List <double> unqvalues = DataRangeHelper.StripDoubleRange(values);
            IPoint        point     = new DateTimePoint1D(baseDate, targetDate);

            return(CurveAnalytics.GetDateValue(point, interpolationType, extrapolation, unqtimes.ToArray(), unqvalues.ToArray()));
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="xvalue"></param>
        /// <param name="xAsArray"></param>
        /// <param name="yAsArray"></param>
        /// <param name="interpType"></param>
        /// <returns></returns>
        public double InterpolateOnValues(double xvalue, Excel.Range xAsArray, Excel.Range yAsArray, string interpType)
        {
            //At this stage only linear interpolation is supported
            var x = DataRangeHelper.StripDoubleRange(xAsArray);
            var y = DataRangeHelper.StripDoubleRange(yAsArray);

            return(EquitiesLibrary.InterpolateOnValues(xvalue, x.ToArray(), y.ToArray(), interpType));
        }
Example #7
0
        /// <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);
        }
Example #8
0
        /// <summary>
        /// Gets the delta0 for a collection of coupon cashflows provided.
        /// </summary>
        /// <param name="paymentDiscountFactors">The discount factors.</param>
        /// <param name="yearFractions">The year fractions.</param>
        /// <param name="notionals">The notionals</param>
        /// <param name="fixedFlag">Delta0 is zero for fixed coupons.</param>
        /// <returns>The break even rate.</returns>
        public double Delta0(Excel.Range notionals, Excel.Range paymentDiscountFactors, Excel.Range yearFractions, bool fixedFlag)
        {
            var unqNotionals = DataRangeHelper.StripDoubleRange(notionals);
            var unqPaymentDiscountFactors = DataRangeHelper.StripDoubleRange(paymentDiscountFactors);
            var unqYearFractions          = DataRangeHelper.StripDoubleRange(yearFractions);

            return(SwapAnalytics.Delta0(unqNotionals.ToArray(), unqPaymentDiscountFactors.ToArray(), unqYearFractions.ToArray(), fixedFlag));
        }
Example #9
0
        /// <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);
        }
Example #10
0
        /// <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);
        }
Example #11
0
        /// <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);
        }
Example #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="valueDate"></param>
        /// <param name="datesAsArray"></param>
        /// <param name="amountsAsArray"></param>
        /// <param name="interpType"></param>
        /// <returns></returns>
        public double InterpolateOnDates(DateTime valueDate, Excel.Range datesAsArray, Excel.Range amountsAsArray, string interpType)
        {
            //At this stage only linear interpolation is supported
            var dates   = DataRangeHelper.StripDateTimeRange(datesAsArray);
            var amounts = DataRangeHelper.StripDoubleRange(amountsAsArray);

            return(EquitiesLibrary.InterpolateOnDates(valueDate, dates.ToArray(), amounts.ToArray(), interpType));
        }
Example #13
0
        /// <summary>
        /// Gets the delta0 for a collection of coupon cashflows provided.
        /// </summary>
        /// <param name="paymentDiscountFactors">The discount factors.</param>
        /// <param name="amounts">The amounts</param>
        /// <param name="curveYearFractions">The curve year fractions.</param>
        /// <param name="periodAsTimesPerYears">Delta1 compounding Frequency.</param>
        /// <returns>The break even rate.</returns>
        public double Delta1(Excel.Range amounts, Excel.Range paymentDiscountFactors,
                             Excel.Range curveYearFractions, double periodAsTimesPerYears)
        {
            var unqNotionals = DataRangeHelper.StripDoubleRange(amounts);
            var unqCouponPaymentDiscountFactors = DataRangeHelper.StripDoubleRange(paymentDiscountFactors);
            var unqYearFractions = DataRangeHelper.StripDoubleRange(curveYearFractions);

            return(SwapAnalytics.Delta1(unqNotionals.ToArray(), unqCouponPaymentDiscountFactors.ToArray(), unqYearFractions.ToArray(), periodAsTimesPerYears));
        }
Example #14
0
        /// <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);
        }
Example #15
0
        /// <summary>
        /// Gets the break even rate for a collection of coupon cashflows provided.
        /// </summary>
        /// <param name="paymentDiscountFactors">The discount factors.</param>
        /// <param name="yearFractions">The year fractions.</param>
        /// <param name="forwardRates">The forward rates.</param>
        /// <param name="notionals">The notionals</param>
        /// <returns>The break even rate.</returns>
        public double BreakEvenRate(Excel.Range notionals, Excel.Range forwardRates, Excel.Range paymentDiscountFactors, Excel.Range yearFractions)
        {
            var unqNotionals              = DataRangeHelper.StripDoubleRange(notionals);
            var unqForwardRates           = DataRangeHelper.StripDoubleRange(forwardRates);
            var unqPaymentDiscountFactors = DataRangeHelper.StripDoubleRange(paymentDiscountFactors);
            var unqYearFractions          = DataRangeHelper.StripDoubleRange(yearFractions);

            return(SwapAnalytics.BreakEvenRate(unqNotionals.ToArray(), unqForwardRates.ToArray(), unqPaymentDiscountFactors.ToArray(), unqYearFractions.ToArray()));
        }
Example #16
0
        ///<summary>
        ///</summary>
        ///<param name="ratedaysAsArray"></param>
        ///<param name="rateamtsAsArray"></param>
        ///<param name="divdaysAsArray"></param>
        ///<param name="divamtsAsArray"></param>
        ///<param name="voltimesAsArray"></param>
        ///<param name="volatilitiesAsRange"></param>
        ///<param name="spot"></param>
        ///<param name="callstrike"></param>
        ///<param name="putstrike"></param>
        ///<param name="maturity"></param>
        ///<param name="kappa"></param>
        ///<param name="theta"></param>
        ///<param name="sigma"></param>
        ///<param name="profiletimes"></param>
        ///<param name="confidence"></param>
        ///<param name="tstepSize"></param>
        ///<param name="simulations"></param>
        ///<param name="seed"></param>
        ///<returns></returns>
        public double[,] GetCollarPCE(Excel.Range ratedaysAsArray,
                                      Excel.Range rateamtsAsArray,
                                      Excel.Range divdaysAsArray,
                                      Excel.Range divamtsAsArray,
                                      Excel.Range voltimesAsArray,
                                      Excel.Range volatilitiesAsRange,
                                      double spot,
                                      double callstrike,
                                      double putstrike,
                                      double maturity,
                                      double kappa,
                                      double theta,
                                      double sigma,
                                      Excel.Range profiletimes,
                                      double confidence,
                                      double tstepSize,
                                      int simulations,
                                      int seed)
        {
            //Map Ranges
            var rateamts                     = DataRangeHelper.StripDoubleRange(rateamtsAsArray);
            var divamts                      = DataRangeHelper.StripDoubleRange(divamtsAsArray);
            var voltimes                     = DataRangeHelper.StripDoubleRange(voltimesAsArray);
            var divdays                      = DataRangeHelper.StripIntRange(divdaysAsArray);
            var ratedays                     = DataRangeHelper.StripIntRange(ratedaysAsArray);
            var profile                      = DataRangeHelper.StripDoubleRange(profiletimes);
            var volatilities                 = volatilitiesAsRange.Value[System.Reflection.Missing.Value] as object[, ];
            var volatilitiesAsDoubles        = RangeHelper.RangeToDoubleMatrix(volatilities);
            List <OrcWingParameters> volSurf = UnpackWing(volatilitiesAsDoubles, voltimes.ToArray(), spot, ratedays.ToArray(), rateamts.ToArray(), divdays.ToArray(), divamts.ToArray());

            CleanDivs(ref divdays, ref divamts);
            double[,] results = EquityPCEAnalytics.GetCollarPCE("CollarPCE",
                                                                ratedays.ToArray(),
                                                                rateamts.ToArray(),
                                                                divdays.ToArray(),
                                                                divamts.ToArray(),
                                                                volSurf,
                                                                spot,
                                                                callstrike,
                                                                putstrike,
                                                                maturity,
                                                                kappa,
                                                                theta,
                                                                sigma,
                                                                profile.ToArray(),
                                                                confidence,
                                                                tstepSize,
                                                                simulations,
                                                                seed);
            //int n = profiletimes.Length;
            //var lhs = new double[profiletimes.Length];
            //for (int i = 0; i < n; i++)
            //{
            //    lhs[i] = results[i, 1];
            //}
            return(results);
        }
Example #17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="spot"></param>
        /// <param name="strike"></param>
        /// <param name="vol"></param>
        /// <param name="paystyle"></param>
        /// <param name="today"></param>
        /// <param name="expiry"></param>
        /// <param name="zeroDatesAsArray"></param>
        /// <param name="zeroRatesAsArray"></param>
        /// <param name="q"></param>
        /// <returns></returns>
        public double BlackScholesPricerContDiv(double spot, double strike, double vol, string paystyle, DateTime today,
                                                DateTime expiry, Excel.Range zeroDatesAsArray, Excel.Range zeroRatesAsArray, double q)
        {
            var    zeroDates = DataRangeHelper.StripDateTimeRange(zeroDatesAsArray);
            var    zeroRates = DataRangeHelper.StripDoubleRange(zeroRatesAsArray);
            double pr        = EquitiesLibrary.BlackScholesPricerContDiv(spot, strike, vol, paystyle, today, expiry, zeroDates.ToArray(), zeroRates.ToArray(), q);

            return(pr);
        }
Example #18
0
        /// <summary>
        /// Returns the PV (as at the valueDate) of the payment stream.
        /// Only payments occuring on or between valueDate and finalDate are included in the sum.
        /// All other payments are ignored.
        /// </summary>
        /// <param name="valueDate">The date at which the PV is taken.</param>
        /// <param name="paymentDatesAsArray">The dates on which payments are made, in ascending order.</param>
        /// <param name="paymentAmountsAsArray">The amounds of payments.</param>
        /// <param name="zeroDatesAsArray">The dates corresponding to the ZCB discount curve, in ascending order.</param>
        /// <param name="zeroRatesAsArray">The rates corresponding to the ZCB discount curve.</param>
        /// <param name="finalDate">The final date on which payments are to be included.</param>
        /// <returns>A double representing the PV.</returns>
        public double PVofPaymentStream(DateTime valueDate, DateTime finalDate, Excel.Range paymentDatesAsArray, Excel.Range paymentAmountsAsArray,
                                        Excel.Range zeroDatesAsArray, Excel.Range zeroRatesAsArray)
        {
            var paymentDates   = DataRangeHelper.StripDateTimeRange(paymentDatesAsArray);
            var paymentAmounts = DataRangeHelper.StripDoubleRange(paymentAmountsAsArray);
            var zeroDates      = DataRangeHelper.StripDateTimeRange(zeroDatesAsArray);
            var zeroRates      = DataRangeHelper.StripDoubleRange(zeroRatesAsArray);

            return(EquitiesLibrary.PVofPaymentStream(valueDate, finalDate, paymentDates.ToArray(), paymentAmounts.ToArray(), zeroDates.ToArray(), zeroRates.ToArray()));
        }
Example #19
0
        /// <summary>
        /// Gets the ATM forward.
        /// </summary>
        /// <param name="spot"></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="today"></param>
        /// <param name="expiry"></param>
        /// <returns></returns>
        public double GetForward(DateTime today, DateTime expiry, double spot, Excel.Range zeroDatesAsArray, Excel.Range zeroRatesAsArray,
                                 Excel.Range divDatesAsArray, Excel.Range divAmsAsArray)
        {
            var zeroDates = DataRangeHelper.StripDateTimeRange(zeroDatesAsArray);
            var zeroRates = DataRangeHelper.StripDoubleRange(zeroRatesAsArray);
            var divDates  = DataRangeHelper.StripDateTimeRange(divDatesAsArray);
            var divAms    = DataRangeHelper.StripDoubleRange(divAmsAsArray);

            return(EquitiesLibrary.GetForward(today, expiry, spot, zeroDates.ToArray(), zeroRates.ToArray(), divDates.ToArray(), divAms.ToArray()));
        }
Example #20
0
        /// <summary>
        /// Pricers the specified style.
        /// </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="today"></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>
        /// <returns></returns>
        public double BinomialRelativePricer(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    divDates  = DataRangeHelper.StripDateTimeRange(divDatesAsArray);
            var    divAms    = DataRangeHelper.StripDoubleRange(divAmsAsArray);
            var    zeroDates = DataRangeHelper.StripDateTimeRange(zeroDatesAsArray);
            var    zeroRates = DataRangeHelper.StripDoubleRange(zeroRatesAsArray);
            double pr        = EquitiesLibrary.BinomialRelativePricer(style, spot, strike, vol, today, expiry, paystyle, zeroDates.ToArray(), zeroRates.ToArray(), divDates.ToArray(), divAms.ToArray(), gridsteps, smoo, flatFlag);

            return(pr);
        }
Example #21
0
        /// <summary>
        /// Evaluates the delta wrt the discount rate R.
        /// </summary>
        /// <param name="notionals">The notionals.</param>
        /// <param name="yearfractions">The daycount fractions.</param>
        /// <param name="rates">The rates.</param>
        /// <param name="paymentDiscountFactors">The payment discount factors.</param>
        /// <param name="periodAsTimesPerYears">The compounding year fractions.</param>
        /// <param name="curveYearFractions">The time to payment year fractions.</param>
        /// <returns></returns>
        public double Delta1Arrays2(Excel.Range notionals, Excel.Range yearfractions, Excel.Range rates,
                                    Excel.Range paymentDiscountFactors, Excel.Range curveYearFractions, double periodAsTimesPerYears)
        {
            var unqNotionals = DataRangeHelper.StripDoubleRange(notionals);
            var unqRates     = DataRangeHelper.StripDoubleRange(rates);
            var unqCouponPaymentDiscountFactors = DataRangeHelper.StripDoubleRange(paymentDiscountFactors);
            var unqYearFractions      = DataRangeHelper.StripDoubleRange(yearfractions);
            var unqCurveYearFractions = DataRangeHelper.StripDoubleRange(curveYearFractions);

            return(SwapAnalytics.Delta1Arrays(unqNotionals.ToArray(), unqYearFractions.ToArray(), unqRates.ToArray(),
                                              unqCouponPaymentDiscountFactors.ToArray(), unqCurveYearFractions.ToArray(), periodAsTimesPerYears));
        }
Example #22
0
        /// <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);
        }
Example #23
0
        /// <summary>
        /// Business days between a period.
        /// </summary>
        /// <param name="locationsAsArray">The locations range as an array.</param>
        /// <param name="startDate">The start date.</param>
        /// <param name="endDate">The end date.</param>
        /// <returns></returns>
        public object[,] BusinessDaysBetween(Excel.Range locationsAsArray, DateTime startDate, DateTime endDate)
        {
            List <string> unqVals = DataRangeHelper.StripRange(locationsAsArray);
            var           list    = CalendarService.BusinessDaysBetween(unqVals.ToArray(), startDate, endDate);
            var           resVals = new object[list.Count, 1];

            for (int idx = 0; idx < resVals.Length; ++idx)
            {
                resVals[idx, 0] = list[idx];
            }
            return(resVals);
        }
Example #24
0
        /// <summary>
        /// Gets the delta0 for a collection of coupon cashlows provided.
        /// </summary>
        /// <param name="paymentDiscountFactors">The discount factors.</param>
        /// <param name="yearFractions">The year fractions.</param>
        /// <param name="notionals">The notionals</param>
        /// <param name="principalPaymentDiscountFactors">The dfs for the principal exchanges.</param>
        /// <param name="fixedFlag">Delta0 is zero for fixed coupons.</param>
        /// <param name="principalNotionals">The principal Exchanges.</param>
        /// <returns>The break even rate.</returns>
        public double Delta0WithExchanges(Excel.Range notionals, Excel.Range paymentDiscountFactors, Excel.Range yearFractions,
                                          Excel.Range principalNotionals, Excel.Range principalPaymentDiscountFactors, Boolean fixedFlag)
        {
            var unqNotionals = DataRangeHelper.StripDoubleRange(notionals);
            var unqCouponPaymentDiscountFactors = DataRangeHelper.StripDoubleRange(paymentDiscountFactors);
            var unqYearFractions      = DataRangeHelper.StripDoubleRange(yearFractions);
            var unqPrincipalNotionals = DataRangeHelper.StripDoubleRange(principalNotionals);
            var unqPrincipalPaymentDiscountFactors = DataRangeHelper.StripDoubleRange(principalPaymentDiscountFactors);

            return(SwapAnalytics.Delta0WithExchanges(unqNotionals.ToArray(), unqCouponPaymentDiscountFactors.ToArray(), unqYearFractions.ToArray(),
                                                     unqPrincipalNotionals.ToArray(), unqPrincipalPaymentDiscountFactors.ToArray(), fixedFlag));
        }
Example #25
0
        /// <summary>
        /// Advances the specified date using the underlying calendar locations.
        /// </summary>
        /// <param name="locationsAsArray">The locations range as an array.</param>
        /// <param name="dateRange">The date.</param>
        /// <param name="dayType">The day type: cakendat or business.</param>
        /// <param name="periodInteval">The period inteval.</param>
        /// <param name="businessDayConvention">The business day convention.</param>
        /// <returns>The vertical range of adjusted dates.</returns>
        public object[,] AdvanceDateRange(Excel.Range locationsAsArray, Excel.Range dateRange, string dayType, string periodInteval, string businessDayConvention)
        {
            List <string>   unqVals  = DataRangeHelper.StripRange(locationsAsArray);
            List <DateTime> unqDates = DataRangeHelper.StripDateTimeRange(dateRange);
            List <DateTime> result   = unqDates.Select(element => CalendarService.Advance(unqVals.ToArray(), element, dayType, periodInteval, businessDayConvention)).ToList();
            var             resVals  = new object[result.Count, 1];

            for (int idx = 0; idx < resVals.Length; ++idx)
            {
                resVals[idx, 0] = result[idx];
            }
            return(resVals);
        }
Example #26
0
        /// <summary>
        /// Gets the npv for a collection of coupons and principal exchanges provided.
        /// </summary>
        /// <param name="couponPaymentDiscountFactors">The discount factors.</param>
        /// <param name="yearFractions">The year fractions.</param>
        /// <param name="forwardRates">The forward rates.</param>
        /// <param name="couponNotionals">The notionals of the coupons.</param>
        /// <param name="principalNotionals">The principal exchange notionals.</param>
        /// <param name="principalPaymentDiscountFactors">The payment discount factors for the principal exchanges.</param>
        /// <returns>The break even rate.</returns>
        public double NPVWithExchanges(Excel.Range couponNotionals, Excel.Range forwardRates, Excel.Range couponPaymentDiscountFactors,
                                       Excel.Range yearFractions, Excel.Range principalNotionals, Excel.Range principalPaymentDiscountFactors)
        {
            var unqCouponNotionals = DataRangeHelper.StripDoubleRange(couponNotionals);
            var unqForwardRates    = DataRangeHelper.StripDoubleRange(forwardRates);
            var unqCouponPaymentDiscountFactors = DataRangeHelper.StripDoubleRange(couponPaymentDiscountFactors);
            var unqYearFractions      = DataRangeHelper.StripDoubleRange(yearFractions);
            var unqPrincipalNotionals = DataRangeHelper.StripDoubleRange(principalNotionals);
            var unqPrincipalPaymentDiscountFactors = DataRangeHelper.StripDoubleRange(principalPaymentDiscountFactors);

            return(SwapAnalytics.NPVWithExchanges(unqCouponNotionals.ToArray(), unqForwardRates.ToArray(), unqCouponPaymentDiscountFactors.ToArray(), unqYearFractions.ToArray(),
                                                  unqPrincipalNotionals.ToArray(), unqPrincipalPaymentDiscountFactors.ToArray()));
        }
Example #27
0
        /// <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);
        }
Example #28
0
        /// <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);
        }
Example #29
0
        public string CreateCalendar(Excel.Range propertiesRange, Excel.Range dateArray)
        {
            var properties = propertiesRange.Value[System.Reflection.Missing.Value] as object[, ];

            properties = (object[, ])DataRangeHelper.TrimNulls(properties);
            var namedValueSet = properties.ToNamedValueSet();
            var dates         = DataRangeHelper.StripDateTimeRange(dateArray);
            var identifier    = namedValueSet.GetValue <string>("UniqueIdentifier", true);
            var calendar      = BusinessCalendarHelper.CreateCalendar(namedValueSet, dates);

            Engine.Cache.SaveObject(calendar, NameSpace + "." + identifier, namedValueSet);
            Engine.Logger.LogDebug("Loaded business center holiday dates: {0}", identifier);
            return(identifier);
        }
Example #30
0
        /// <summary>
        /// Determines whether [is valid calendar] [the specified rule profile].
        /// </summary>
        /// <param name="locationsAsArray">The locations as an array.</param>
        /// <returns></returns>
        public object[,] IsValidCalendar(Excel.Range locationsAsArray)
        {
            List <string> unqVals = DataRangeHelper.StripRange(locationsAsArray);
            IDictionary <string, Boolean> calendars = CalendarService.IsValidCalendar(unqVals.ToArray());
            var collectionResult = calendars.Values;
            var resVals          = new object[collectionResult.Count, 1];
            var idx = 0;

            foreach (var result in collectionResult)
            {
                resVals[idx, 0] = result;
                idx++;
            }
            return(resVals);
        }