27#ifndef quantlib_binomial_engine_hpp
28#define quantlib_binomial_engine_hpp
30#include <ql/methods/lattices/binomialtree.hpp>
31#include <ql/methods/lattices/bsmlattice.hpp>
32#include <ql/math/distributions/normaldistribution.hpp>
33#include <ql/pricingengines/vanilla/discretizedvanillaoption.hpp>
34#include <ql/pricingengines/greeks.hpp>
35#include <ql/processes/blackscholesprocess.hpp>
36#include <ql/termstructures/yield/flatforward.hpp>
37#include <ql/termstructures/volatility/equityfx/blackconstantvol.hpp>
59 QL_REQUIRE(timeSteps >= 2,
60 "at least 2 time steps required, "
61 << timeSteps <<
" provided");
67 ext::shared_ptr<GeneralizedBlackScholesProcess>
process_;
77 DayCounter rfdc = process_->riskFreeRate()->dayCounter();
78 DayCounter divdc = process_->dividendYield()->dayCounter();
79 DayCounter voldc = process_->blackVolatility()->dayCounter();
80 Calendar volcal = process_->blackVolatility()->calendar();
82 Real s0 = process_->stateVariable()->value();
83 QL_REQUIRE(s0 > 0.0,
"negative or null underlying given");
84 Volatility v = process_->blackVolatility()->blackVol(
85 arguments_.exercise->lastDate(), s0);
86 Date maturityDate = arguments_.exercise->lastDate();
87 Rate r = process_->riskFreeRate()->zeroRate(maturityDate,
89 Rate q = process_->dividendYield()->zeroRate(maturityDate,
91 Date referenceDate = process_->riskFreeRate()->referenceDate();
95 ext::shared_ptr<YieldTermStructure>(
98 ext::shared_ptr<YieldTermStructure>(
101 ext::shared_ptr<BlackVolTermStructure>(
104 ext::shared_ptr<PlainVanillaPayoff> payoff =
105 ext::dynamic_pointer_cast<PlainVanillaPayoff>(arguments_.payoff);
106 QL_REQUIRE(payoff,
"non-plain payoff given");
110 ext::shared_ptr<StochasticProcess1D> bs(
112 process_->stateVariable(),
113 flatDividends, flatRiskFree, flatVol));
115 TimeGrid grid(maturity, timeSteps_);
117 ext::shared_ptr<T> tree(
new T(bs, maturity, timeSteps_,
120 ext::shared_ptr<BlackScholesLattice<T> > lattice(
135 QL_ENSURE(va2.
size() == 3,
"Expect 3 nodes in grid at second step");
139 Real s2u = lattice->underlying(2, 2);
140 Real s2m = lattice->underlying(2, 1);
141 Real s2d = lattice->underlying(2, 0);
144 Real delta2u = (p2u - p2m)/(s2u-s2m);
145 Real delta2d = (p2m-p2d)/(s2m-s2d);
146 Real gamma = (delta2u - delta2d) / ((s2u-s2d)/2);
152 QL_ENSURE(va.
size() == 2,
"Expect 2 nodes in grid at first step");
155 Real s1u = lattice->underlying(1, 1);
156 Real s1d = lattice->underlying(1, 0);
158 Real delta = (p1u - p1d) / (s1u - s1d);
166 results_.delta = delta;
167 results_.gamma = gamma;
1-D array used in linear algebra.
Size size() const
dimension of the array
Pricing engine for vanilla options using binomial trees.
BinomialVanillaEngine(ext::shared_ptr< GeneralizedBlackScholesProcess > process, Size timeSteps)
void calculate() const override
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
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.
const Array & values() const
void initialize(const ext::shared_ptr< Lattice > &, Time t)
Flat interest-rate curve.
Generalized Black-Scholes stochastic process.
Shared handle to an observable.
@ NoFrequency
null frequency
Real Time
continuous quantity with 1-year units
Real Volatility
volatility
std::size_t Size
size of a container
Real blackScholesTheta(const ext::shared_ptr< GeneralizedBlackScholesProcess > &p, Real value, Real delta, Real gamma)
default theta calculation for Black-Scholes options