Пример #1
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()));
        }
Пример #2
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()));
        }
Пример #3
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));
        }
Пример #4
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);
        }
Пример #5
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));
        }
Пример #6
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()));
        }
Пример #7
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));
        }
Пример #8
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);
        }
Пример #9
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);
        }
Пример #10
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));
        }
Пример #11
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()));
        }
Пример #12
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()));
        }
Пример #13
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()));
        }
Пример #14
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);
        }
Пример #15
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));
        }
Пример #16
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);
        }
Пример #17
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));
        }
Пример #18
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()));
        }
Пример #19
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);
        }
Пример #20
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="principalPaymentDiscountFactors">The dfs for the principal exchanges.</param>
        /// <param name="principalCurveYearFractions">The principal exchange curve year fractions.</param>
        /// <param name="compoundingFrequency">Delta1 compounding Frequency.</param>
        /// <param name="couponCurveYearsFractions">The coupon time to payments.</param>
        /// <param name="principalNotionals">The principal Exchanges.</param>
        /// <returns>The break even rate.</returns>
        public double Delta1WithExchanges(Excel.Range notionals, Excel.Range paymentDiscountFactors,
                                          Excel.Range yearFractions, Excel.Range couponCurveYearsFractions, Excel.Range principalNotionals,
                                          Excel.Range principalPaymentDiscountFactors, Excel.Range principalCurveYearFractions, double compoundingFrequency)
        {
            var unqNotionals = DataRangeHelper.StripDoubleRange(notionals);
            var unqCouponPaymentDiscountFactors = DataRangeHelper.StripDoubleRange(paymentDiscountFactors);
            var unqYearFractions                   = DataRangeHelper.StripDoubleRange(yearFractions);
            var unqCouponCurveYearsFractions       = DataRangeHelper.StripDoubleRange(couponCurveYearsFractions);
            var unqPrincipalNotionals              = DataRangeHelper.StripDoubleRange(principalNotionals);
            var unqPrincipalPaymentDiscountFactors = DataRangeHelper.StripDoubleRange(principalPaymentDiscountFactors);
            var unqPrincipalCurveYearFractions     = DataRangeHelper.StripDoubleRange(principalCurveYearFractions);

            return(SwapAnalytics.Delta1WithExchanges(unqNotionals.ToArray(), unqCouponPaymentDiscountFactors.ToArray(),
                                                     unqYearFractions.ToArray(), unqCouponCurveYearsFractions.ToArray(), unqPrincipalNotionals.ToArray(),
                                                     unqPrincipalPaymentDiscountFactors.ToArray(), unqPrincipalCurveYearFractions.ToArray(), compoundingFrequency));
        }
Пример #21
0
        ///<summary>
        /// The main function to calculate the adjusted forward.
        ///</summary>
        ///<param name="futuresPriceArray"> Vector of futures prices.</param>
        ///<param name="volatilityRange"> Vector of futures</param>
        ///<param name="correlationRange"> Correlation between forwards. Can be a
        /// scalar input or a correlation matrix.</param>
        ///<param name="shiftArray"> The shift parameters from the BGM
        /// calibration.</param>
        ///<param name="coverageArray"> The vector of time intervals between model
        /// time nodes.</param>
        ///<param name="timeNodesArray"> The model time nodes</param>
        ///<returns> Output, a 2-D array of ouput data. The first column is the
        /// vector of adjusted cash forwards. The second column is the error
        /// from the optimisation (the implied futures rate minus the market
        /// rate). The third column is the number of iterations taken by the
        /// optimisation routine to converge on each adjusted rate. In the first
        /// entry in the fourth and fifth column is the time taken to work
        /// through the whole set of time nodes, and the program version.</returns>
        public object[,] CalculateCashForward(Excel.Range futuresPriceArray,
                                              Excel.Range volatilityRange,
                                              Excel.Range correlationRange,
                                              Excel.Range shiftArray,
                                              Excel.Range coverageArray,
                                              Excel.Range timeNodesArray)
        {
            var futuresPrice = DataRangeHelper.StripDoubleRange(futuresPriceArray);
            var shift        = DataRangeHelper.StripDoubleRange(shiftArray);
            var coverage     = DataRangeHelper.StripDoubleRange(coverageArray);
            var timeNodes    = DataRangeHelper.StripDoubleRange(timeNodesArray);
            var volatility   = DataRangeHelper.ToMatrix <double>(volatilityRange);
            var correlation  = DataRangeHelper.ToMatrix <double>(correlationRange);
            var result       = CashForward.CalculateCashForward(futuresPrice.ToArray(), volatility,
                                                                correlation, shift.ToArray(), coverage.ToArray(), timeNodes.ToArray());

            return(DataRangeHelper.ToRange(result));
        }
Пример #22
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="today"></param>
        /// <param name="spot"></param>
        /// <param name="strike"></param>
        /// <param name="sig"></param>
        /// <param name="dexp"></param>
        /// <param name="sPay"></param>
        /// <param name="sStyle"></param>
        /// <param name="nGrid"></param>
        /// <param name="tStep"></param>
        /// <param name="iNum"></param>
        /// <param name="divamsAsArray"></param>
        /// <param name="divdatesAsArray"></param>
        /// <param name="zeramsAsArray"></param>
        /// <param name="zerdatesAsArray"></param>
        /// <returns></returns>
        public double GetEquityGreeks(DateTime today,
                                      double spot,
                                      double strike,
                                      double sig,
                                      DateTime dexp,
                                      string sPay,
                                      string sStyle,
                                      int nGrid,
                                      double tStep,
                                      int iNum,
                                      Excel.Range divamsAsArray,
                                      Excel.Range divdatesAsArray,
                                      Excel.Range zeramsAsArray,
                                      Excel.Range zerdatesAsArray
                                      )
        {
            //Map the ranges
            var divams   = DataRangeHelper.StripDoubleRange(divamsAsArray);
            var divdates = DataRangeHelper.StripDateTimeRange(divamsAsArray);
            var zerams   = DataRangeHelper.StripDoubleRange(zeramsAsArray);
            var zerdates = DataRangeHelper.StripDateTimeRange(zerdatesAsArray);
            //set up the DivList
            int nd    = divdates.Count; //GetUpperBound(0) + 1;
            var myDiv = new DivList {
                Divpoints = nd
            };

            myDiv.MakeArrays();
            for (int idx = 0; idx != nd; idx++)
            {
                double   r  = divams[idx];
                DateTime dp = divdates[idx];
                TimeSpan ts = dp - today;
                myDiv.SetD(idx, r, ts.Days / 365.0);
            }
            //set up the zero
            int nz     = zerdates.Count;//GetUpperBound(0) + 1;
            var myZero = new ZeroCurve {
                Ratepoints = nz
            };

            myZero.MakeArrays();
            for (int idx = 0; idx != nz; idx++)
            {
                double   r  = zerams[idx];
                DateTime dp = zerdates[idx];
                TimeSpan ts = dp - today;
                myZero.SetR(idx, r, ts.Days / 365.0);
            }
            //compute the discounted dividends to  expiry and work out continuous
            TimeSpan tsE  = dexp - today;
            double   texp = tsE.Days / 365.0;

            for (int idx = 0; idx != nd; idx++)
            {
                if (myDiv.GetT(idx) <= texp)
                {
                    double d = myDiv.GetD(idx) * Math.Exp(-myDiv.GetT(idx) * myZero.LinInterp(myDiv.GetT(idx)));
                }
            }
            //double qc = -Math.Log((spot - sum) / spot) / texp;
            //double rc = myZero.linInterp(texp);
            var myG = new Grid
            {
                XL     = Math.Log(spot) - 8.0 * sig * Math.Sqrt(texp),
                Xu     = Math.Log(spot) + 8.0 * sig * Math.Sqrt(texp),
                Steps  = nGrid,
                Strike = strike,
                Spot   = spot,
                SPay   = sPay,
                SStyle = sStyle,
                T      = texp
            };

            myG.NTsteps = Convert.ToInt32(myG.T / tStep);
            myG.Sig     = sig;
            var    greeks = new double[4];
            double price  = myG.Pricer(myZero, myDiv, ref greeks, true);

            myG.Sig += 0.01;
            double priceUp = myG.Pricer(myZero, myDiv, ref greeks, false);

            greeks[3] = priceUp - price;
            return(greeks[iNum]);
        }