41 {
42
43 DayCounter rfdc =
process_->riskFreeRate()->dayCounter();
44 DayCounter divdc =
process_->dividendYield()->dayCounter();
45 DayCounter voldc =
process_->blackVolatility()->dayCounter();
46 Calendar volcal =
process_->blackVolatility()->calendar();
47
49 QL_REQUIRE(s0 > 0.0, "negative or null underlying");
52 Rate riskFreeRate =
process_->riskFreeRate()->zeroRate(maturityDate, rfdc, Continuous, NoFrequency);
53 Rate q =
process_->dividendYield()->zeroRate(maturityDate, divdc, Continuous, NoFrequency);
54 Date referenceDate =
process_->riskFreeRate()->referenceDate();
55
56
57 Size i;
58 for (i = 0; i <
arguments_.dividends.size(); i++) {
59 if (
arguments_.dividends[i]->date() >= referenceDate)
60 s0 -=
62 }
63 QL_REQUIRE(s0 > 0.0, "negative value after subtracting dividends");
64
66 results_.additionalResults[
"maturityTime"] =
process_->riskFreeRate()->timeFromReference(maturityDate);
67 results_.additionalResults[
"riskFreeRate"] = riskFreeRate;
68 results_.additionalResults[
"dividendYield"] = q;
69 results_.additionalResults[
"equitySpot"] = s0;
70 results_.additionalResults[
"equityVol"] = v;
73 results_.additionalResults[
"maturitySurvivalProbability"] =
75 }
76
77
78 Handle<Quote> underlying(QuantLib::ext::shared_ptr<Quote>(new SimpleQuote(s0)));
79 Handle<YieldTermStructure> flatRiskFree(
80 QuantLib::ext::shared_ptr<YieldTermStructure>(new FlatForward(referenceDate, riskFreeRate, rfdc)));
81 Handle<YieldTermStructure> flatDividends(
82 QuantLib::ext::shared_ptr<YieldTermStructure>(new FlatForward(referenceDate, q, divdc)));
83 Handle<BlackVolTermStructure> flatVol(
84 QuantLib::ext::shared_ptr<BlackVolTermStructure>(new BlackConstantVol(referenceDate, volcal, v, voldc)));
85
86 QuantLib::ext::shared_ptr<PlainVanillaPayoff> payoff = QuantLib::ext::dynamic_pointer_cast<PlainVanillaPayoff>(
arguments_.payoff);
87 QL_REQUIRE(payoff, "non-plain payoff given");
88
89 Time maturity = rfdc.yearFraction(
arguments_.settlementDate, maturityDate);
90
91 QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess> bs(
92 new GeneralizedBlackScholesProcess(underlying, flatDividends, flatRiskFree, flatVol));
93 QuantLib::ext::shared_ptr<T> tree(
new T(bs, maturity,
timeSteps_, payoff->strike()));
94
95
96
97
98
99
100 QL_REQUIRE(!
referenceCurve_.empty(),
"BinomialConvertibleEngine::calculate(): empty reference curve");
101 Real referenceCurveRate =
referenceCurve_->zeroRate(maturityDate, rfdc, Continuous, NoFrequency);
102 Real defaultRate = 0.0, creditRate = 0.0, recRate = 0.0;
104
105 defaultRate = -std::log(
defaultCurve_->survivalProbability(maturityDate)) /
106 rfdc.yearFraction(
defaultCurve_->referenceDate(), maturityDate);
107 }
109
111 }
113
115 }
116
117 Real creditSpread = creditRate + (referenceCurveRate - riskFreeRate) + defaultRate * (1.0 - recRate);
118
119 QuantLib::ext::shared_ptr<Lattice> lattice(
120 new TsiveriotisFernandesLattice<T>(tree, riskFreeRate, maturity,
timeSteps_, creditSpread, v, q));
121
123 arguments_, bs, Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(creditSpread)), TimeGrid(maturity,
timeSteps_));
124
125 convertible.initialize(lattice, maturity);
126 convertible.rollback(0.0);
127 results_.value = convertible.presentValue();
128 QL_ENSURE(
results_.value < std::numeric_limits<Real>::max(),
"floating-point overflow on tree grid");
129}
const Instrument::results * results_
Swap::arguments * arguments_