示例#1
0
 public Fj_Helper(double kappa, double theta, double sigma,
                  double v0, double s0, double rho,
                  ComplexLogFormula cpxLog,
                  double term,
                  double strike,
                  double ratio,
                  int j)
 {
     j_      = j;
     kappa_  = kappa;
     theta_  = theta;
     sigma_  = sigma;
     v0_     = v0;
     cpxLog_ = cpxLog;
     term_   = term;
     x_      = Math.Log(s0);
     sx_     = Math.Log(strike);
     dd_     = x_ - Math.Log(ratio);
     sigma2_ = sigma_ * sigma_;
     rsigma_ = rho * sigma_;
     t0_     = kappa - ((j == 1) ? rho * sigma : 0);
     b_      = 0;
     g_km1_  = 0;
     engine_ = null;
 }
示例#2
0
        // Constructor giving full control
        // over the Fourier integration algorithm
        public AnalyticHestonEngine(HestonModel model, ComplexLogFormula cpxLog, Integration integration)
            : base(model)
        {
            evaluations_ = 0;
            cpxLog_      = cpxLog;
            integration_ = integration; // TODO check

            Utils.QL_REQUIRE(cpxLog_ != ComplexLogFormula.BranchCorrection ||
                             !integration.isAdaptiveIntegration(), () =>
                             "Branch correction does not work in conjunction with adaptive integration methods");
        }
示例#3
0
        public static void doCalculation(double riskFreeDiscount,
                                         double dividendDiscount,
                                         double spotPrice,
                                         double strikePrice,
                                         double term,
                                         double kappa, double theta, double sigma, double v0, double rho,
                                         TypePayoff type,
                                         Integration integration,
                                         ComplexLogFormula cpxLog,
                                         AnalyticHestonEngine enginePtr,
                                         ref double?value,
                                         ref int evaluations)
        {
            double ratio = riskFreeDiscount / dividendDiscount;

            double c_inf = Math.Min(10.0, Math.Max(0.0001,
                                                   Math.Sqrt(1.0 - (Math.Pow(rho, 2))) / sigma))
                           * (v0 + kappa * theta * term);

            evaluations = 0;
            double p1 = integration.calculate(c_inf,
                                              new Fj_Helper(kappa, theta, sigma, v0, spotPrice, rho, enginePtr,
                                                            cpxLog, term, strikePrice, ratio, 1).value) / Const.M_PI;

            evaluations += integration.numberOfEvaluations();

            double p2 = integration.calculate(c_inf,
                                              new Fj_Helper(kappa, theta, sigma, v0, spotPrice, rho, enginePtr,
                                                            cpxLog, term, strikePrice, ratio, 2).value) / Const.M_PI;

            evaluations += integration.numberOfEvaluations();

            switch (type.optionType())
            {
            case Option.Type.Call:
                value = spotPrice * dividendDiscount * (p1 + 0.5) - strikePrice * riskFreeDiscount * (p2 + 0.5);
                break;

            case Option.Type.Put:
                value = spotPrice * dividendDiscount * (p1 - 0.5) - strikePrice * riskFreeDiscount * (p2 - 0.5);
                break;

            default:
                Utils.QL_FAIL("unknown option type");
                break;
            }
        }
示例#4
0
 public Fj_Helper(VanillaOption.Arguments arguments,
                  HestonModel model,
                  AnalyticHestonEngine engine,
                  ComplexLogFormula cpxLog,
                  double term, double ratio, int j)
 {
     j_      = j; //arg_(arguments),
     kappa_  = model.kappa();
     theta_  = model.theta();
     sigma_  = model.sigma();
     v0_     = model.v0();
     cpxLog_ = cpxLog;
     term_   = term;
     x_      = Math.Log(model.process().s0().link.value());
     sx_     = Math.Log(((StrikedTypePayoff)(arguments.payoff)).strike());
     dd_     = x_ - Math.Log(ratio);
     sigma2_ = sigma_ * sigma_;
     rsigma_ = model.rho() * sigma_;
     t0_     = kappa_ - ((j_ == 1) ? model.rho() * sigma_ : 0);
     b_      = 0;
     g_km1_  = 0;
     engine_ = engine;
 }