예제 #1
0
            //* calibration of shift*/
            private double calibrationOfShift(double Rs)
            {
                if (Rs.IsNotEqual(tmpRs_))
                {
                    double initialGuess;
                    double N = 0;
                    double D = 0;
                    for (int i = 0; i < accruals_.Count; i++)
                    {
                        N += accruals_[i] * swapPaymentDiscounts_[i];
                        D += accruals_[i] * swapPaymentDiscounts_[i] * shapedSwapPaymentTimes_[i];
                    }
                    N           *= Rs;
                    D           *= Rs;
                    N           += accruals_.Last() * swapPaymentDiscounts_.Last() - objectiveFunction_.gFunctionWithShifts().discountAtStart_;
                    D           += accruals_.Last() * swapPaymentDiscounts_.Last() * shapedSwapPaymentTimes_.Last();
                    initialGuess = N / D;

                    objectiveFunction_.setSwapRateValue(Rs);
                    Newton solver = new Newton();
                    solver.setMaxEvaluations(1000);

                    // these boundaries migth not be big enough if the volatility
                    // of big swap rate values is too high . In this case the G function
                    // is not even integrable, so better to fix the vol than increasing
                    // these values
                    double lower = -20;
                    double upper = 20.0;

                    try
                    {
                        calibratedShift_ = solver.solve(objectiveFunction_, accuracy_, Math.Max(Math.Min(initialGuess, upper * .99), lower * .99), lower, upper);
                    }
                    catch (Exception e)
                    {
                        Utils.QL_FAIL("meanReversion: " + meanReversion_.link.value() + ", swapRateValue: " + swapRateValue_ + ", swapStartTime: " + swapStartTime_ + ", shapedPaymentTime: " + shapedPaymentTime_ + "\n error message: " + e.Message);
                    }
                    tmpRs_ = Rs;
                }
                return(calibratedShift_);
            }
예제 #2
0
            //* calibration of shift*/
            private double calibrationOfShift(double Rs) {
                if (Rs != tmpRs_) {
                    double initialGuess;
                    double N = 0;
                    double D = 0;
                    for (int i = 0; i < accruals_.Count; i++) {
                        N += accruals_[i] * swapPaymentDiscounts_[i];
                        D += accruals_[i] * swapPaymentDiscounts_[i] * shapedSwapPaymentTimes_[i];
                    }
                    N *= Rs;
                    D *= Rs;
                    N += accruals_.Last() * swapPaymentDiscounts_.Last() - objectiveFunction_.gFunctionWithShifts().discountAtStart_;
                    D += accruals_.Last() * swapPaymentDiscounts_.Last() * shapedSwapPaymentTimes_.Last();
                    initialGuess = N / D;

                    objectiveFunction_.setSwapRateValue(Rs);
                    Newton solver = new Newton();
                    solver.setMaxEvaluations(1000);

                    // these boundaries migth not be big enough if the volatility
                    // of big swap rate values is too high . In this case the G function
                    // is not even integrable, so better to fix the vol than increasing
                    // these values
                    double lower = -20;
                    double upper = 20.0;

                    try {
                        calibratedShift_ = solver.solve(objectiveFunction_, accuracy_, Math.Max(Math.Min(initialGuess, upper * .99), lower * .99), lower, upper);
                    } catch (Exception e) {
                        throw new ApplicationException("meanReversion: " + meanReversion_.link.value() + ", swapRateValue: " + swapRateValue_ + ", swapStartTime: " + swapStartTime_ + ", shapedPaymentTime: " + shapedPaymentTime_ + "\n error message: " + e.Message);
                    }
                    tmpRs_ = Rs;
                }
                return calibratedShift_;
            }