QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
analyticcontinuousfixedlookback.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2006 Warren Chou
5 Copyright (C) 2007 StatPro Italia srl
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21#include <ql/exercise.hpp>
22#include <ql/pricingengines/lookback/analyticcontinuousfixedlookback.hpp>
23#include <utility>
24
25namespace QuantLib {
26
28 ext::shared_ptr<GeneralizedBlackScholesProcess> process)
29 : process_(std::move(process)) {
31 }
32
34
35 ext::shared_ptr<PlainVanillaPayoff> payoff =
36 ext::dynamic_pointer_cast<PlainVanillaPayoff>(arguments_.payoff);
37 QL_REQUIRE(payoff, "Non-plain payoff given");
38
39 QL_REQUIRE(process_->x0() > 0.0, "negative or null underlying");
40
41 Real strike = payoff->strike();
42
43 switch (payoff->optionType()) {
44 case Option::Call:
45 QL_REQUIRE(payoff->strike()>=0.0,
46 "Strike must be positive or null");
47 if (strike <= minmax())
48 results_.value = A(1) + C(1);
49 else
50 results_.value = B(1);
51 break;
52 case Option::Put:
53 QL_REQUIRE(payoff->strike()>0.0,
54 "Strike must be positive");
55 if (strike >= minmax())
56 results_.value = A(-1) + C(-1);
57 else
58 results_.value = B(-1);
59 break;
60 default:
61 QL_FAIL("Unknown type");
62 }
63 }
64
65
67 return process_->x0();
68 }
69
71 ext::shared_ptr<PlainVanillaPayoff> payoff =
72 ext::dynamic_pointer_cast<PlainVanillaPayoff>(arguments_.payoff);
73 QL_REQUIRE(payoff, "Non-plain payoff given");
74 return payoff->strike();
75 }
76
78 return process_->time(arguments_.exercise->lastDate());
79 }
80
82 return process_->blackVolatility()->blackVol(residualTime(), strike());
83 }
84
86 return volatility() * std::sqrt(residualTime());
87 }
88
90 return process_->riskFreeRate()->zeroRate(residualTime(), Continuous,
92 }
93
95 const {
96 return process_->riskFreeRate()->discount(residualTime());
97 }
98
100 return process_->dividendYield()->zeroRate(residualTime(),
102 }
103
105 const {
106 return process_->dividendYield()->discount(residualTime());
107 }
108
110 return arguments_.minmax;
111 }
112
114 Volatility vol = volatility();
115 Real lambda = 2.0*(riskFreeRate() - dividendYield())/(vol*vol);
116 Real ss = underlying()/minmax();
117 Real d1 =
118 std::log(ss)/stdDeviation() + 0.5*(lambda+1.0)*stdDeviation();
119 Real N1 = f_(eta*d1);
120 Real N2 = f_(eta*(d1-stdDeviation()));
121 Real N3 = f_(eta*(d1-lambda*stdDeviation()));
122 Real N4 = f_(eta*d1);
123 Real powss = std::pow(ss, -lambda);
124 return eta*(underlying() * dividendDiscount() * N1 -
125 minmax() * riskFreeDiscount() * N2 -
127 (powss * N3 - dividendDiscount()* N4/riskFreeDiscount())/
128 lambda);
129 }
130
132 Volatility vol = volatility();
133 Real lambda = 2.0*(riskFreeRate() - dividendYield())/(vol*vol);
134 Real ss = underlying()/strike();
135 Real d1 =
136 std::log(ss)/stdDeviation() + 0.5*(lambda+1.0)*stdDeviation();
137 Real N1 = f_(eta*d1);
138 Real N2 = f_(eta*(d1-stdDeviation()));
139 Real N3 = f_(eta*(d1-lambda*stdDeviation()));
140 Real N4 = f_(eta*d1);
141 Real powss = std::pow(ss, -lambda);
142 return eta*(underlying() * dividendDiscount() * N1 -
143 strike() * riskFreeDiscount() * N2 -
145 (powss * N3 - dividendDiscount()* N4/riskFreeDiscount())/
146 lambda);
147 }
148
150 return eta*(riskFreeDiscount()*(minmax() - strike()));
151 }
152
153}
154
AnalyticContinuousFixedLookbackEngine(ext::shared_ptr< GeneralizedBlackScholesProcess > process)
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
@ NoFrequency
null frequency
Definition: frequency.hpp:37
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.