QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
analyticamericanmargrabeengine.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2010 Master IMAFA - Polytech'Nice Sophia - Université de Nice Sophia Antipolis
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20#include <ql/exercise.hpp>
21#include <ql/pricingengines/exotic/analyticamericanmargrabeengine.hpp>
22#include <ql/pricingengines/vanilla/bjerksundstenslandengine.hpp>
23#include <ql/quotes/simplequote.hpp>
24#include <ql/termstructures/volatility/equityfx/blackconstantvol.hpp>
25#include <ql/termstructures/yield/flatforward.hpp>
26#include <ql/time/calendars/nullcalendar.hpp>
27#include <utility>
28
29namespace QuantLib {
30
32 ext::shared_ptr<GeneralizedBlackScholesProcess> process1,
33 ext::shared_ptr<GeneralizedBlackScholesProcess> process2,
34 Real correlation)
35 : process1_(std::move(process1)), process2_(std::move(process2)), rho_(correlation) {
38 }
39
41
42 QL_REQUIRE(arguments_.exercise->type() == Exercise::American,
43 "not an American option");
44
45 ext::shared_ptr<AmericanExercise> exercise =
46 ext::dynamic_pointer_cast<AmericanExercise>(arguments_.exercise);
47 QL_REQUIRE(exercise, "not an American option");
48
49 ext::shared_ptr<NullPayoff> payoff0 =
50 ext::dynamic_pointer_cast<NullPayoff>(arguments_.payoff);
51 QL_REQUIRE(payoff0, "not a null payoff");
52
53 // The option can be priced as an American single-asset option
54 // with an adjusted process and payoff.
55
57
58 DayCounter rfdc = process1_->riskFreeRate()->dayCounter();
59 Time t = rfdc.yearFraction(process1_->riskFreeRate()->referenceDate(),
60 arguments_.exercise->lastDate());
61
62 Real s1 = process1_->stateVariable()->value();
63 Real s2 = process2_->stateVariable()->value();
64
65 ext::shared_ptr<SimpleQuote> spot(new SimpleQuote(arguments_.Q1*s1));
66
67 ext::shared_ptr<StrikedTypePayoff> payoff(
69
70 DiscountFactor dividendDiscount1 =
71 process1_->dividendYield()->discount(exercise->lastDate());
72 Rate q1 = -std::log(dividendDiscount1)/t;
73
74 DiscountFactor dividendDiscount2 =
75 process2_->dividendYield()->discount(exercise->lastDate());
76 Rate q2 = -std::log(dividendDiscount2)/t;
77
78 ext::shared_ptr<YieldTermStructure> qTS(
79 new FlatForward(today, q1, rfdc));
80
81 ext::shared_ptr<YieldTermStructure> rTS(
82 new FlatForward(today, q2, rfdc));
83
84 Real variance1 = process1_->blackVolatility()->blackVariance(
85 exercise->lastDate(), s1);
86 Real variance2 = process2_->blackVolatility()->blackVariance(
87 exercise->lastDate(), s2);
88 Real variance = variance1 + variance2
89 - 2*rho_*std::sqrt(variance1)*std::sqrt(variance2);
90 Volatility volatility = std::sqrt(variance/t);
91
92 ext::shared_ptr<BlackVolTermStructure> volTS(
93 new BlackConstantVol(today, NullCalendar(), volatility, rfdc));
94
95 ext::shared_ptr<BlackScholesMertonProcess> stochProcess(new
100
101 ext::shared_ptr<PricingEngine> engine(
102 new BjerksundStenslandApproximationEngine(stochProcess));
103
104 VanillaOption option(payoff, exercise);
105 option.setPricingEngine(engine);
106
107 results_.value = option.NPV();
108 }
109
110}
ext::shared_ptr< GeneralizedBlackScholesProcess > process2_
ext::shared_ptr< GeneralizedBlackScholesProcess > process1_
AnalyticAmericanMargrabeEngine(ext::shared_ptr< GeneralizedBlackScholesProcess > process1, ext::shared_ptr< GeneralizedBlackScholesProcess > process2, Real correlation)
Bjerksund and Stensland pricing engine for American options (1993)
Constant Black volatility, no time-strike dependence.
Merton (1973) extension to the Black-Scholes stochastic process.
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
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.
Definition: daycounter.hpp:128
Flat interest-rate curve.
Definition: flatforward.hpp:37
Shared handle to an observable.
Definition: handle.hpp:41
Real NPV() const
returns the net present value of the instrument.
Definition: instrument.hpp:167
void setPricingEngine(const ext::shared_ptr< PricingEngine > &)
set the pricing engine to be used.
Definition: instrument.cpp:35
Calendar for reproducing theoretical calculations.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
Plain-vanilla payoff.
Definition: payoffs.hpp:105
DateProxy & evaluationDate()
the date at which pricing is to be performed.
Definition: settings.hpp:147
market element returning a stored value
Definition: simplequote.hpp:33
static Settings & instance()
access to the unique instance
Definition: singleton.hpp:104
Vanilla option (no discrete dividends, no barriers) on a single asset.
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real DiscountFactor
discount factor between dates
Definition: types.hpp:66
Real Volatility
volatility
Definition: types.hpp:78
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
STL namespace.