QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
analyticdigitalamericanengine.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) 2003 Neil Firth
5 Copyright (C) 2004 Ferdinando Ametrano
6 Copyright (C) 2007 StatPro Italia srl
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
22#include <ql/exercise.hpp>
26#include <utility>
27
28namespace QuantLib {
29
31 ext::shared_ptr<GeneralizedBlackScholesProcess> process)
32 : process_(std::move(process)) {
33 registerWith(process_);
34 }
35
37
38 ext::shared_ptr<AmericanExercise> ex =
39 ext::dynamic_pointer_cast<AmericanExercise>(arguments_.exercise);
40 QL_REQUIRE(ex, "non-American exercise given");
41 QL_REQUIRE(ex->dates()[0] <=
42 process_->blackVolatility()->referenceDate(),
43 "American option with window exercise not handled yet");
44
45 ext::shared_ptr<StrikedTypePayoff> payoff =
46 ext::dynamic_pointer_cast<StrikedTypePayoff>(arguments_.payoff);
47 QL_REQUIRE(payoff, "non-striked payoff given");
48
49 Real spot = process_->stateVariable()->value();
50 QL_REQUIRE(spot > 0.0, "negative or null underlying given");
51
53 process_->blackVolatility()->blackVariance(ex->lastDate(),
54 payoff->strike());
55 Rate dividendDiscount =
56 process_->dividendYield()->discount(ex->lastDate());
57 Rate riskFreeDiscount =
58 process_->riskFreeRate()->discount(ex->lastDate());
59
60 if(ex->payoffAtExpiry()) {
61 AmericanPayoffAtExpiry pricer(spot, riskFreeDiscount,
62 dividendDiscount, variance,
63 payoff, knock_in());
64 results_.value = pricer.value();
65 } else {
66 AmericanPayoffAtHit pricer(spot, riskFreeDiscount,
67 dividendDiscount, variance, payoff);
68 results_.value = pricer.value();
69 results_.delta = pricer.delta();
70 results_.gamma = pricer.gamma();
71
72 DayCounter rfdc = process_->riskFreeRate()->dayCounter();
73 Time t = rfdc.yearFraction(
74 process_->riskFreeRate()->referenceDate(),
75 arguments_.exercise->lastDate());
76 results_.rho = pricer.rho(t);
77 }
78 }
79
80}
81
Analytical formulae for american exercise with payoff at expiry.
Analytical formulae for american exercise with payoff at hit.
analytic digital American option engine
const Instrument::results * results_
Definition: cdsoption.cpp:63
Analytic formula for American exercise payoff at-expiry options.
Analytic formula for American exercise payoff at-hit options.
Real rho(Time maturity) const
AnalyticDigitalAmericanEngine(ext::shared_ptr< GeneralizedBlackScholesProcess >)
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
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
const DefaultType & t
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Option exercise classes and payoff function.
LinearInterpolation variance
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real Rate
interest rates
Definition: types.hpp:70
ext::shared_ptr< QuantLib::Payoff > payoff
Definition: any.hpp:35
STL namespace.