24#ifndef quantlib_binomial_double_barrier_engine_hpp
25#define quantlib_binomial_double_barrier_engine_hpp
49 template <
class T,
class D = DiscretizedDoubleBarrierOption>
56 "timeSteps must be positive, " << timeSteps <<
63 ext::shared_ptr<GeneralizedBlackScholesProcess>
process_;
70 template <
class T,
class D>
73 DayCounter rfdc = process_->riskFreeRate()->dayCounter();
74 DayCounter divdc = process_->dividendYield()->dayCounter();
75 DayCounter voldc = process_->blackVolatility()->dayCounter();
76 Calendar volcal = process_->blackVolatility()->calendar();
78 Real s0 = process_->stateVariable()->value();
79 QL_REQUIRE(s0 > 0.0,
"negative or null underlying given");
80 Volatility v = process_->blackVolatility()->blackVol(
81 arguments_.exercise->lastDate(), s0);
82 Date maturityDate = arguments_.exercise->lastDate();
83 Rate r = process_->riskFreeRate()->zeroRate(maturityDate,
85 Rate q = process_->dividendYield()->zeroRate(maturityDate,
87 Date referenceDate = process_->riskFreeRate()->referenceDate();
91 ext::shared_ptr<YieldTermStructure>(
94 ext::shared_ptr<YieldTermStructure>(
97 ext::shared_ptr<BlackVolTermStructure>(
100 ext::shared_ptr<StrikedTypePayoff>
payoff =
101 ext::dynamic_pointer_cast<StrikedTypePayoff>(arguments_.payoff);
106 ext::shared_ptr<StochasticProcess1D> bs(
108 process_->stateVariable(),
109 flatDividends, flatRiskFree, flatVol));
111 TimeGrid grid(maturity, timeSteps_);
113 ext::shared_ptr<T> tree(
new T(bs, maturity, timeSteps_,
116 ext::shared_ptr<BlackScholesLattice<T> > lattice(
119 D option(arguments_, *process_, grid);
120 option.initialize(lattice, maturity);
128 option.rollback(grid[2]);
129 Array va2(option.values());
130 QL_ENSURE(va2.
size() == 3,
"Expect 3 nodes in grid at second step");
134 Real s2u = lattice->underlying(2, 2);
135 Real s2m = lattice->underlying(2, 1);
136 Real s2d = lattice->underlying(2, 0);
139 Real delta2u = (p2u - p2m)/(s2u-s2m);
140 Real delta2d = (p2m-p2d)/(s2m-s2d);
141 Real gamma = (delta2u - delta2d) / ((s2u-s2d)/2);
145 option.rollback(grid[1]);
146 Array va(option.values());
147 QL_ENSURE(va.
size() == 2,
"Expect 2 nodes in grid at first step");
150 Real s1u = lattice->underlying(1, 1);
151 Real s1d = lattice->underlying(1, 0);
153 Real delta = (p1u - p1d) / (s1u - s1d);
156 option.rollback(0.0);
157 Real p0 = option.presentValue();
165 results_.theta = (p2m - p0) / grid[2];
Black constant volatility, no time dependence, no strike dependence.
Binomial trees under the BSM model.
const Instrument::results * results_
1-D array used in linear algebra.
Size size() const
dimension of the array
Pricing engine for double barrier options using binomial trees.
void calculate() const override
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
BinomialDoubleBarrierEngine(ext::shared_ptr< GeneralizedBlackScholesProcess > process, Size timeSteps)
Constant Black volatility, no time-strike dependence.
Simple binomial lattice approximating the Black-Scholes model.
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
Double-Barrier-option engine base class
Flat interest-rate curve.
Generalized Black-Scholes stochastic process.
Shared handle to an observable.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
discretized double barrier option
#define QL_ENSURE(condition, message)
throw an error if the given post-condition is not verified
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
flat forward rate term structure
@ NoFrequency
null frequency
Real Time
continuous quantity with 1-year units
Real Volatility
volatility
std::size_t Size
size of a container
ext::shared_ptr< QuantLib::Payoff > payoff
normal, cumulative and inverse cumulative distributions
ext::shared_ptr< YieldTermStructure > q
ext::shared_ptr< YieldTermStructure > r
ext::shared_ptr< BlackVolTermStructure > v