QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
analyticcontinuousfloatinglookback.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/analyticcontinuousfloatinglookback.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<FloatingTypePayoff> payoff =
36 ext::dynamic_pointer_cast<FloatingTypePayoff>(arguments_.payoff);
37 QL_REQUIRE(payoff, "Non-floating payoff given");
38
39 QL_REQUIRE(process_->x0() > 0.0, "negative or null underlying");
40
41 switch (payoff->optionType()) {
42 case Option::Call:
43 results_.value = A(1);
44 break;
45 case Option::Put:
46 results_.value = A(-1);
47 break;
48 default:
49 QL_FAIL("Unknown type");
50 }
51 }
52
54 return process_->x0();
55 }
56
58 return process_->time(arguments_.exercise->lastDate());
59 }
60
62 return process_->blackVolatility()->blackVol(residualTime(), minmax());
63 }
64
66 return volatility() * std::sqrt(residualTime());
67 }
68
70 return process_->riskFreeRate()->zeroRate(residualTime(), Continuous,
72 }
73
75 const {
76 return process_->riskFreeRate()->discount(residualTime());
77 }
78
80 return process_->dividendYield()->zeroRate(residualTime(),
82 }
83
85 const {
86 return process_->dividendYield()->discount(residualTime());
87 }
88
90 return arguments_.minmax;
91 }
92
94 Volatility vol = volatility();
95 Real lambda = 2.0*(riskFreeRate() - dividendYield())/(vol*vol);
96 Real s = underlying()/minmax();
97 Real d1 = std::log(s)/stdDeviation() + 0.5*(lambda+1.0)*stdDeviation();
98 Real n1 = f_(eta*d1);
99 Real n2 = f_(eta*(d1-stdDeviation()));
100 Real n3 = f_(eta*(-d1+lambda*stdDeviation()));
101 Real n4 = f_(eta*-d1);
102 Real pow_s = std::pow(s, -lambda);
103 return eta*((underlying() * dividendDiscount() * n1 -
104 minmax() * riskFreeDiscount() * n2) +
106 (pow_s * n3 - dividendDiscount()* n4/riskFreeDiscount())/
107 lambda));
108 }
109
110}
111
AnalyticContinuousFloatingLookbackEngine(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.