コード例 #1
0
        protected override PathPricer <IPath> pathPricer()
        {
            PlainVanillaPayoff payoff = this.arguments_.payoff as PlainVanillaPayoff;

            Utils.QL_REQUIRE(payoff != null, () => "non-plain payoff given");

            HestonProcess process = this.process_ as HestonProcess;

            Utils.QL_REQUIRE(process != null, () => "Heston process required");

            return(new EuropeanHestonPathPricer(payoff.optionType(),
                                                payoff.strike(),
                                                process.riskFreeRate().link.discount(this.timeGrid().Last())));
        }
コード例 #2
0
        protected override PathPricer <IPath> pathPricer()
        {
            PlainVanillaPayoff payoff = (PlainVanillaPayoff)(this.arguments_.payoff);

            Utils.QL_REQUIRE(payoff != null, () => "non-plain payoff given");

            EuropeanExercise exercise = (EuropeanExercise)this.arguments_.exercise;

            Utils.QL_REQUIRE(exercise != null, () => "wrong exercise given");

            return((PathPricer <IPath>) new ArithmeticAPOPathPricer(
                       payoff.optionType(),
                       payoff.strike(),
                       this.process_.riskFreeRate().link.discount(this.timeGrid().Last()),
                       this.arguments_.runningAccumulator.GetValueOrDefault(),
                       this.arguments_.pastFixings.GetValueOrDefault()));
        }
コード例 #3
0
        protected override PathPricer <IPath> controlPathPricer()
        {
            PlainVanillaPayoff payoff = (PlainVanillaPayoff)this.arguments_.payoff;

            Utils.QL_REQUIRE(payoff != null, () => "non-plain payoff given");

            EuropeanExercise exercise = (EuropeanExercise)this.arguments_.exercise;

            Utils.QL_REQUIRE(exercise != null, () => "wrong exercise given");

            // for seasoned option the geometric strike might be rescaled
            // to obtain an equivalent arithmetic strike.
            // Any change applied here MUST be applied to the analytic engine too
            return((PathPricer <IPath>) new GeometricAPOPathPricer(
                       payoff.optionType(),
                       payoff.strike(),
                       this.process_.riskFreeRate().link.discount(this.timeGrid().Last())));
        }
コード例 #4
0
ファイル: T_BasketOption.cs プロジェクト: tzhdingli/qlnet
 public void REPORT_FAILURE_2(String greekName, BasketType basketType, PlainVanillaPayoff payoff, Exercise exercise,
                              double s1, double s2, double q1, double q2, double r, Date today, double v1, double v2, double rho,
                              double expected, double calculated, double error, double tolerance)
 {
     Assert.Fail(Utilities.exerciseTypeToString(exercise) + " "
                 + payoff.optionType() + " option on "
                 + basketTypeToString(basketType)
                 + " with " + Utilities.payoffTypeToString(payoff) + " payoff:\n"
                 + "1st underlying value: " + s1 + "\n"
                 + "2nd underlying value: " + s2 + "\n"
                 + "              strike: " + payoff.strike() + "\n"
                 + "  1st dividend yield: " + q1 + "\n"
                 + "  2nd dividend yield: " + q2 + "\n"
                 + "      risk-free rate: " + r + "\n"
                 + "      reference date: " + today + "\n"
                 + "            maturity: " + exercise.lastDate() + "\n"
                 + "1st asset volatility: " + v1 + "\n"
                 + "2nd asset volatility: " + v2 + "\n"
                 + "         correlation: " + rho + "\n\n"
                 + "    expected   " + greekName + ": " + expected + "\n"
                 + "    calculated " + greekName + ": " + calculated + "\n"
                 + "    error:            " + error + "\n"
                 + "    tolerance:        " + tolerance);
 }
コード例 #5
0
        public override void calculate()
        {
            DayCounter rfdc   = process_.riskFreeRate().link.dayCounter();
            DayCounter divdc  = process_.dividendYield().link.dayCounter();
            DayCounter voldc  = process_.blackVolatility().link.dayCounter();
            Calendar   volcal = process_.blackVolatility().link.calendar();

            double s0 = process_.x0();

            Utils.QL_REQUIRE(s0 > 0.0, () => "negative or null underlying");
            double v             = process_.blackVolatility().link.blackVol(arguments_.exercise.lastDate(), s0);
            Date   maturityDate  = arguments_.exercise.lastDate();
            double riskFreeRate  = process_.riskFreeRate().link.zeroRate(maturityDate, rfdc, Compounding.Continuous, Frequency.NoFrequency).value();
            double q             = process_.dividendYield().link.zeroRate(maturityDate, divdc, Compounding.Continuous, Frequency.NoFrequency).value();
            Date   referenceDate = process_.riskFreeRate().link.referenceDate();

            // substract dividends

            ConvertibleBond.option.Arguments args = arguments_ as ConvertibleBond.option.Arguments;

            for (int i = 0; i < args.dividends.Count; i++)
            {
                if (args.dividends[i].date() >= referenceDate)
                {
                    s0 -= args.dividends[i].amount() * process_.riskFreeRate().link.discount(args.dividends[i].date());
                }

                Utils.QL_REQUIRE(s0 > 0.0, () => "negative value after substracting dividends");
            }

            // binomial trees with constant coefficient

            Handle <Quote> underlying = new Handle <Quote>(new SimpleQuote(s0));
            Handle <YieldTermStructure> flatRiskFree =
                new Handle <YieldTermStructure>(new FlatForward(referenceDate, riskFreeRate, rfdc));
            Handle <YieldTermStructure> flatDividends =
                new Handle <YieldTermStructure>(new FlatForward(referenceDate, q, divdc));
            Handle <BlackVolTermStructure> flatVol =
                new Handle <BlackVolTermStructure>(new BlackConstantVol(referenceDate, volcal, v, voldc));
            PlainVanillaPayoff payoff = args.payoff as PlainVanillaPayoff;

            Utils.QL_REQUIRE(payoff != null, () => " non-plain payoff given ");

            double maturity = rfdc.yearFraction(args.settlementDate, maturityDate);
            GeneralizedBlackScholesProcess bs =
                new GeneralizedBlackScholesProcess(underlying, flatDividends, flatRiskFree, flatVol);

            T Tree = new T().factory(bs, maturity, timeSteps_, payoff.strike());

            double creditSpread = args.creditSpread.link.value();

            TsiveriotisFernandesLattice <T> lattice = new TsiveriotisFernandesLattice <T>(Tree, riskFreeRate,
                                                                                          maturity, timeSteps_, creditSpread, v, q);
            DiscretizedConvertible convertible = new DiscretizedConvertible(args, bs, new TimeGrid(maturity, timeSteps_));

            convertible.initialize(lattice, maturity);
            convertible.rollback(0.0);
            results_.value = convertible.presentValue();

            Utils.QL_REQUIRE(results_.value < double.MaxValue, () => "floating-point overflow on tree grid");
        }