Inheritance: SwaptionVolatilityDiscrete
        public void testSwaptionVolMatrixCoherence()
        {
            //"Testing swaption volatility matrix...");

            CommonVars vars = new CommonVars();

            SwaptionVolatilityMatrix vol;
            string description;

            //floating reference date, floating market data
            description = "floating reference date, floating market data";
            vol = new SwaptionVolatilityMatrix(vars.conventions.calendar,
                                                vars.conventions.optionBdc,
                                                vars.atm.tenors.options,
                                                vars.atm.tenors.swaps,
                                                vars.atm.volsHandle,
                                                vars.conventions.dayCounter);

            vars.makeCoherenceTest(description, vol);

            //fixed reference date, floating market data
            description = "fixed reference date, floating market data";
            vol = new SwaptionVolatilityMatrix(Settings.evaluationDate(),
                                                vars.conventions.calendar,
                                                vars.conventions.optionBdc,
                                                vars.atm.tenors.options,
                                                vars.atm.tenors.swaps,
                                                vars.atm.volsHandle,
                                                vars.conventions.dayCounter);

            vars.makeCoherenceTest(description, vol);

            // floating reference date, fixed market data
            description = "floating reference date, fixed market data";
            vol = new SwaptionVolatilityMatrix(vars.conventions.calendar,
                                                vars.conventions.optionBdc,
                                                vars.atm.tenors.options,
                                                vars.atm.tenors.swaps,
                                                vars.atm.volsHandle,
                                                vars.conventions.dayCounter);

            vars.makeCoherenceTest(description, vol);

            // fixed reference date, fixed market data
            description = "fixed reference date, fixed market data";
            vol = new SwaptionVolatilityMatrix(Settings.evaluationDate(),
                                                vars.conventions.calendar,
                                                vars.conventions.optionBdc,
                                                vars.atm.tenors.options,
                                                vars.atm.tenors.swaps,
                                                vars.atm.volsHandle,
                                                vars.conventions.dayCounter);

            vars.makeCoherenceTest(description, vol);
        }
Beispiel #2
0
        public override void setParams(Vector parameters)
        {
            base.setParams(parameters);

            int k = covarProxy_.volatilityModel().parameters().Count;

            covarProxy_.volatilityModel().setParams(new List <Parameter>(arguments_.GetRange(0, k)));
            covarProxy_.correlationModel().setParams(new List <Parameter>(arguments_.GetRange(k, arguments_.Count - k)));

            swaptionVola = null;
        }
Beispiel #3
0
        public override void calculate()
        {
            if (!(arguments_.settlementType == Settlement.Type.Physical))
            {
                throw new ApplicationException("cash-settled swaptions not priced with Lfm engine");
            }

            double basisPoint = 1.0e-4;

            VanillaSwap    swap = arguments_.swap;
            IPricingEngine pe   = new DiscountingSwapEngine(discountCurve_);

            swap.setPricingEngine(pe);

            double correction = swap.spread *
                                Math.Abs(swap.floatingLegBPS() / swap.fixedLegBPS());
            double fixedRate = swap.fixedRate - correction;
            double fairRate  = swap.fairRate() - correction;

            SwaptionVolatilityMatrix volatility =
                model_.getSwaptionVolatilityMatrix();

            Date       referenceDate = volatility.referenceDate();
            DayCounter dayCounter    = volatility.dayCounter();

            double exercise = dayCounter.yearFraction(referenceDate,
                                                      arguments_.exercise.date(0));
            double swapLength =
                dayCounter.yearFraction(referenceDate,
                                        arguments_.fixedPayDates.Last())
                - dayCounter.yearFraction(referenceDate,
                                          arguments_.fixedResetDates[0]);

            Option.Type w = arguments_.type == VanillaSwap.Type.Payer ?
                            Option.Type.Call : Option.Type.Put;
            double vol = volatility.volatility(exercise, swapLength,
                                               fairRate, true);

            results_.value = (swap.fixedLegBPS() / basisPoint) *
                             Utils.blackFormula(w, fixedRate, fairRate, vol * Math.Sqrt(exercise));
        }
Beispiel #4
0
        public override void calculate()
        {
            Utils.QL_REQUIRE(arguments_.settlementMethod != Settlement.Method.ParYieldCurve, () =>
                             "cash-settled (ParYieldCurve) swaptions not priced with Lfm engine");

            VanillaSwap    swap = arguments_.swap;
            IPricingEngine pe   = new DiscountingSwapEngine(discountCurve_);

            swap.setPricingEngine(pe);

            double correction = swap.spread *
                                Math.Abs(swap.floatingLegBPS() / swap.fixedLegBPS());
            double fixedRate = swap.fixedRate - correction;
            double fairRate  = swap.fairRate() - correction;

            SwaptionVolatilityMatrix volatility =
                model_.link.getSwaptionVolatilityMatrix();

            Date       referenceDate = volatility.referenceDate();
            DayCounter dayCounter    = volatility.dayCounter();

            double exercise = dayCounter.yearFraction(referenceDate,
                                                      arguments_.exercise.date(0));
            double swapLength =
                dayCounter.yearFraction(referenceDate,
                                        arguments_.fixedPayDates.Last())
                - dayCounter.yearFraction(referenceDate,
                                          arguments_.fixedResetDates[0]);

            Option.Type w = arguments_.type == VanillaSwap.Type.Payer ?
                            Option.Type.Call : Option.Type.Put;
            double vol = volatility.volatility(exercise, swapLength,
                                               fairRate, true);

            results_.value = (swap.fixedLegBPS() / Const.BASIS_POINT) *
                             Utils.blackFormula(w, fixedRate, fairRate, vol * Math.Sqrt(exercise));
        }
Beispiel #5
0
        // calculating swaption volatility matrix using
        // Rebonatos approx. formula. Be aware that this
        // matrix is valid only for regular fixings and
        // assumes that the fix and floating leg have the
        // same frequency
        public SwaptionVolatilityMatrix getSwaptionVolatilityMatrix()
        {
            if (swaptionVola != null)
            {
                return(swaptionVola);
            }

            IborIndex index = process_.index();
            Date      today = process_.fixingDates()[0];

            int    size         = process_.size() / 2;
            Matrix volatilities = new Matrix(size, size);

            List <Date> exercises = new InitializedList <Date>(size);

            for (int i = 0; i < size; ++i)
            {
                exercises[i] = process_.fixingDates()[i + 1];
            }

            List <Period> lengths = new InitializedList <Period>(size);

            for (int i = 0; i < size; ++i)
            {
                lengths[i] = (i + 1) * index.tenor();
            }

            Vector f = process_.initialValues();

            for (int k = 0; k < size; ++k)
            {
                int    alpha   = k;
                double t_alpha = process_.fixingTimes()[alpha + 1];

                Matrix var = new Matrix(size, size);
                for (int i = alpha + 1; i <= k + size; ++i)
                {
                    for (int j = i; j <= k + size; ++j)
                    {
                        var[i - alpha - 1, j - alpha - 1] = var[j - alpha - 1, i - alpha - 1] =
                            covarProxy_.integratedCovariance(i, j, t_alpha, null);
                    }
                }

                for (int l = 1; l <= size; ++l)
                {
                    int    beta = l + k;
                    Vector w    = w_0(alpha, beta);

                    double sum = 0.0;
                    for (int i = alpha + 1; i <= beta; ++i)
                    {
                        for (int j = alpha + 1; j <= beta; ++j)
                        {
                            sum += w[i] * w[j] * f[i] * f[j] * var[i - alpha - 1, j - alpha - 1];
                        }
                    }
                    volatilities[k, l - 1] =
                        Math.Sqrt(sum / t_alpha) / S_0(alpha, beta);
                }
            }

            return(swaptionVola = new SwaptionVolatilityMatrix(today, exercises, lengths,
                                                               volatilities, index.dayCounter()));
        }
Beispiel #6
0
        public override void setParams( Vector parameters)
        {
            base.setParams(parameters);

            int k=covarProxy_.volatilityModel().parameters().Count;

            covarProxy_.volatilityModel().setParams(new List<Parameter>(arguments_.GetRange(0, k)));
            covarProxy_.correlationModel().setParams(new List<Parameter>(arguments_.GetRange(k, arguments_.Count-k)));

            swaptionVola = null;
        }
Beispiel #7
0
        // calculating swaption volatility matrix using
        // Rebonatos approx. formula. Be aware that this
        // matrix is valid only for regular fixings and
        // assumes that the fix and floating leg have the
        // same frequency
        public SwaptionVolatilityMatrix getSwaptionVolatilityMatrix()
        {
            if (swaptionVola!=null) {
                return swaptionVola;
            }

            IborIndex index = process_.index();
            Date today = process_.fixingDates()[0];

            int size=process_.size()/2;
            Matrix volatilities=new Matrix(size, size);

            List<Date> exercises = new InitializedList<Date>(size);
            for (int i = 0; i < size; ++i){
                exercises[i]=process_.fixingDates()[i+1];
            }

            List<Period> lengths = new InitializedList<Period>(size);
            for (int i=0; i < size; ++i) {
                lengths[i] = (i+1)*index.tenor();
            }

            Vector f = process_.initialValues();
            for (int k=0; k < size; ++k) {
                int alpha  =k;
                double t_alpha=process_.fixingTimes()[alpha+1];

                Matrix var=new Matrix(size, size);
                for (int i=alpha+1; i <= k+size; ++i) {
                    for (int j=i; j <= k+size; ++j) {
                        var[i-alpha-1,j-alpha-1] = var[j-alpha-1,i-alpha-1] =
                            covarProxy_.integratedCovariance(i, j, t_alpha,null);
                    }
                }

                for (int l=1; l <= size; ++l) {
                    int beta =l + k;
                    Vector w = w_0(alpha, beta);

                    double sum=0.0;
                    for (int i=alpha+1; i <= beta; ++i) {
                        for (int j=alpha+1; j <= beta; ++j) {
                            sum+=w[i]*w[j]*f[i]*f[j]*var[i-alpha-1,j-alpha-1];
                        }
                    }
                    volatilities[k,l-1] =
                        Math.Sqrt(sum/t_alpha)/S_0(alpha, beta);
                }
            }

            return swaptionVola = new SwaptionVolatilityMatrix( today, exercises, lengths,
                                                                volatilities,index.dayCounter());
        }
        public void testSwaptionVolMatrixObservability()
        {
            //"Testing swaption volatility matrix observability...");

            CommonVars vars=new CommonVars();

            SwaptionVolatilityMatrix vol;
            string description;

            //floating reference date, floating market data
            description = "floating reference date, floating market data";
            vol = new SwaptionVolatilityMatrix( vars.conventions.calendar,
                                                vars.conventions.optionBdc,
                                                vars.atm.tenors.options,
                                                vars.atm.tenors.swaps,
                                                vars.atm.volsHandle,
                                                vars.conventions.dayCounter);

            vars.makeObservabilityTest(description, vol, true, true);

            //fixed reference date, floating market data
            description = "fixed reference date, floating market data";
            vol = new SwaptionVolatilityMatrix( Settings.evaluationDate(),
                                                vars.conventions.calendar,
                                                vars.conventions.optionBdc,
                                                vars.atm.tenors.options,
                                                vars.atm.tenors.swaps,
                                                vars.atm.volsHandle,
                                                vars.conventions.dayCounter);
            vars.makeObservabilityTest(description, vol, true, false);

            // floating reference date, fixed market data
            description = "floating reference date, fixed market data";
            vol = new SwaptionVolatilityMatrix( vars.conventions.calendar,
                                                vars.conventions.optionBdc,
                                                vars.atm.tenors.options,
                                                vars.atm.tenors.swaps,
                                                vars.atm.volsHandle,
                                                vars.conventions.dayCounter);
            vars.makeObservabilityTest(description, vol, false, true);

            // fixed reference date, fixed market data
            description = "fixed reference date, fixed market data";
            vol = new SwaptionVolatilityMatrix( Settings.evaluationDate(),
                                                vars.conventions.calendar,
                                                vars.conventions.optionBdc,
                                                vars.atm.tenors.options,
                                                vars.atm.tenors.swaps,
                                                vars.atm.volsHandle,
                                                vars.conventions.dayCounter);
            vars.makeObservabilityTest(description, vol, false, false);

               // fixed reference date and fixed market data, option dates
                //SwaptionVolatilityMatrix(const Date& referenceDate,
                //                         const std::vector<Date>& exerciseDates,
                //                         const std::vector<Period>& swapTenors,
                //                         const Matrix& volatilities,
                //                         const DayCounter& dayCounter);
        }