QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
analyticsimplechooserengine.cpp
Go to the documentation of this file.
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>
24#include <utility>
25
26namespace QuantLib {
27
29 ext::shared_ptr<GeneralizedBlackScholesProcess> process)
30 : process_(std::move(process)) {
32 }
33
36 DayCounter rfdc = process_->riskFreeRate()->dayCounter();
37 DayCounter divdc = process_->dividendYield()->dayCounter();
38 DayCounter voldc = process_->blackVolatility()->dayCounter();
39 QL_REQUIRE(rfdc==divdc,
40 "Risk-free rate and dividend yield must"
41 "have the same day counter");
42 QL_REQUIRE(rfdc==voldc,
43 "Risk-free rate and volatility must"
44 "have the same day counter");
45 Real spot = process_->stateVariable()->value();
46 auto payoff = ext::dynamic_pointer_cast<StrikedTypePayoff>(arguments_.payoff);
47 QL_REQUIRE(payoff, "non-plain payoff given");
48 Real strike = payoff->strike();
49 Volatility volatility = process_->blackVolatility()->blackVol(
50 arguments_.exercise->lastDate(),
51 strike);
52 Date maturity = arguments_.exercise->lastDate();
53 Real timeToMaturity = rfdc.yearFraction(today,maturity);
54 Real timeToChoosing = rfdc.yearFraction(today,arguments_.choosingDate);
55 Rate dividendRate =
56 process_->dividendYield()->zeroRate(maturity, divdc,
58 Rate riskFreeRate =
59 process_->riskFreeRate()->zeroRate(maturity, rfdc,
61
62 QL_REQUIRE(spot > 0.0, "negative or null spot value");
63 QL_REQUIRE(strike > 0.0, "negative or null strike value");
64 QL_REQUIRE(volatility > 0.0,
65 "negative or null volatility");
66 QL_REQUIRE(timeToChoosing > 0.0,
67 "choosing date earlier than or equal to evaluation date");
68
69 Real d = (std::log(spot/strike)
70 + ((riskFreeRate-dividendRate) + volatility*volatility*0.5)*timeToMaturity)
71 /(volatility*std::sqrt(timeToMaturity));
72
73 Real y = (std::log(spot/strike) + (riskFreeRate-dividendRate)*timeToMaturity
74 + (volatility*volatility*timeToChoosing/2))
75 /(volatility*std::sqrt(timeToChoosing));
76
78
79 results_.value = spot*std::exp(-dividendRate*timeToMaturity)*f(d)
80 - strike*std::exp(-riskFreeRate*timeToMaturity)
81 *f(d-volatility*std::sqrt(timeToMaturity))
82 -spot*std::exp(-dividendRate*timeToMaturity)*f(-y)
83 +strike*std::exp(-riskFreeRate*timeToMaturity)
84 *f(-y+volatility*std::sqrt(timeToChoosing));
85 }
86
87}
AnalyticSimpleChooserEngine(ext::shared_ptr< GeneralizedBlackScholesProcess > process)
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
Cumulative normal distribution function.
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
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
ext::shared_ptr< Exercise > exercise
Definition: option.hpp:65
ext::shared_ptr< Payoff > payoff
Definition: option.hpp:64
DateProxy & evaluationDate()
the date at which pricing is to be performed.
Definition: settings.hpp:147
static Settings & instance()
access to the unique instance
Definition: singleton.hpp:104
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Date d
Option exercise classes and payoff function.
@ NoFrequency
null frequency
Definition: frequency.hpp:37
QL_REAL Real
real number
Definition: types.hpp:50
Real Volatility
volatility
Definition: types.hpp:78
Real Rate
interest rates
Definition: types.hpp:70
ext::shared_ptr< QuantLib::Payoff > payoff
Definition: any.hpp:35
STL namespace.
normal, cumulative and inverse cumulative distributions
Payoffs for various options.
Analytic engine for simple chooser option.