29 ext::shared_ptr<GeneralizedBlackScholesProcess> process,
int series)
30 : process_(
std::move(process)), series_(series) {
36 ext::shared_ptr<PlainVanillaPayoff>
payoff =
37 ext::dynamic_pointer_cast<PlainVanillaPayoff>(
arguments_.payoff);
40 "strike must be positive");
44 QL_REQUIRE(
S > 0.0,
"negative or null underlying given");
50 "only KnockIn and KnockOut options supported");
54 Real K_up = std::min(H, K);
55 Real K_down = std::max(L, K);
62 Real mu = rd - rf - vol*vol/2.0;
63 Real sgn = mu > 0 ? 1.0 :(mu < 0 ? -1.0: 0.0);
70 ext::shared_ptr<PricingEngine> analyticEuropeanEngine =
71 ext::make_shared<AnalyticEuropeanEngine>(
process_);
73 Real european = europeanOption.
NPV();
78 Real d1 =
D(
S/H*std::pow(L/H, 2.0*
n), vol*vol+mu, vol,
T);
79 Real d2 = d1 - vol*std::sqrt(
T);
80 Real g1 =
D(H/
S*std::pow(L/H, 2.0*
n - 1.0), vol*vol+mu, vol,
T);
81 Real g2 = g1 - vol*std::sqrt(
T);
82 Real h1 =
D(
S/H*std::pow(L/H, 2.0*
n - 1.0), vol*vol+mu, vol,
T);
83 Real h2 = h1 - vol*std::sqrt(
T);
84 Real k1 =
D(L/
S*std::pow(L/H, 2.0*
n - 1.0), vol*vol+mu, vol,
T);
85 Real k2 = k1 - vol*std::sqrt(
T);
86 Real d1_down =
D(
S/K_down*std::pow(L/H, 2.0*
n), vol*vol+mu, vol,
T);
87 Real d2_down = d1_down - vol*std::sqrt(
T);
88 Real d1_up =
D(
S/K_up*std::pow(L/H, 2.0*
n), vol*vol+mu, vol,
T);
89 Real d2_up = d1_up - vol*std::sqrt(
T);
90 Real k1_down =
D((H*H)/(K_down*
S)*std::pow(L/H, 2.0*
n), vol*vol+mu, vol,
T);
91 Real k2_down = k1_down - vol*std::sqrt(
T);
92 Real k1_up =
D((H*H)/(K_up*
S)*std::pow(L/H, 2.0*
n), vol*vol+mu, vol,
T);
93 Real k2_up = k1_up - vol*std::sqrt(
T);
96 barrierOut += std::pow(L/H, 2.0 *
n * mu/(vol*vol))*
97 (df*
S*std::pow(L/H, 2.0*
n)*(
f_(d1_down)-
f_(d1))
98 -dd*K*(
f_(d2_down)-
f_(d2))
99 -df*std::pow(L/H, 2.0*
n)*H*H/
S*std::pow(H/
S, 2.0*mu/(vol*vol))*(
f_(k1_down)-
f_(k1))
100 +dd*K*std::pow(H/
S,2.0*mu/(vol*vol))*(
f_(k2_down)-
f_(k2)));
103 barrierOut += std::pow(L/H, 2.0 *
n * mu/(vol*vol))*
104 (dd*K*(
f_(h2)-
f_(d2_up))
105 -df*
S*std::pow(L/H, 2.0*
n)*(
f_(h1)-
f_(d1_up))
106 -dd*K*std::pow(H/
S,2.0*mu/(vol*vol))*(
f_(g2)-
f_(k2_up))
107 +df*std::pow(L/H, 2.0*
n)*H*H/
S*std::pow(H/
S, 2.0*mu/(vol*vol))*(
f_(g1)-
f_(k1_up)));
110 QL_FAIL(
"option type not recognized");
113 Real v1 =
D(H/
S*std::pow(H/L, 2.0*
n), -mu, vol,
T);
114 Real v2 =
D(H/
S*std::pow(H/L, 2.0*
n), mu, vol,
T);
115 Real v3 =
D(
S/L*std::pow(H/L, 2.0*
n), -mu, vol,
T);
116 Real v4 =
D(
S/L*std::pow(H/L, 2.0*
n), mu, vol,
T);
117 rebateIn += dd * R_H * sgn * (std::pow(L/H, 2.0*
n*mu/(vol*vol)) *
f_(sgn * v1) - std::pow(H/
S, 2.0*mu/(vol*vol)) *
f_(-sgn * v2))
118 + dd * R_L * sgn * (std::pow(L/
S, 2.0*mu/(vol*vol)) *
f_(-sgn * v3) - std::pow(H/L, 2.0*
n*mu/(vol*vol)) *
f_(sgn * v4));
134 ext::shared_ptr<PlainVanillaPayoff>
payoff =
135 ext::dynamic_pointer_cast<PlainVanillaPayoff>(
arguments_.payoff);
167 return (std::log(X) + lambda *
T)/(
sigma * std::sqrt(
T));
Analytic European engine.
DoubleBarrier::Type barrierType
bool triggered(Real underlying) const
European option on a single asset.
DoubleBarrierOption::results results_
DoubleBarrierOption::arguments arguments_
std::map< std::string, ext::any > additionalResults
Real NPV() const
returns the net present value of the instrument.
void setPricingEngine(const ext::shared_ptr< PricingEngine > &)
set the pricing engine to be used.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
SuoWangDoubleBarrierEngine(ext::shared_ptr< GeneralizedBlackScholesProcess > process, int series=5)
CumulativeNormalDistribution f_
Time residualTime() const
Volatility volatility() const
DiscountFactor dividendDiscount() const
Real D(Real X, Real lambda, Real sigma, Real T) const
void calculate() const override
Rate riskFreeRate() const
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
Rate dividendYield() const
DiscountFactor riskFreeDiscount() const
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
European option on a single asset.
Option exercise classes and payoff function.
@ NoFrequency
null frequency
Real Time
continuous quantity with 1-year units
Real DiscountFactor
discount factor between dates
Real Volatility
volatility
ext::shared_ptr< QuantLib::Payoff > payoff
Wulin Suo, Yong Wang double-barrier option engine.