QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
vasicek.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) 2001, 2002, 2003 Sadruddin Rejeb
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
23
24namespace QuantLib {
25
27 : OneFactorAffineModel(4), r0_(r0),
28 a_(arguments_[0]), b_(arguments_[1]), sigma_(arguments_[2]),
29 lambda_(arguments_[3]) {
34 }
35
37 Real _a = a();
38 if (_a < std::sqrt(QL_EPSILON)) {
39 return 0.0;
40 } else {
41 Real sigma2 = sigma()*sigma();
42 Real bt = B(t, T);
43 return std::exp((b() + lambda()*sigma()/_a
44 - 0.5*sigma2/(_a*_a))*(bt - (T - t))
45 - 0.25*sigma2*bt*bt/_a);
46 }
47 }
48
50 Real _a = a();
51 if (_a < std::sqrt(QL_EPSILON))
52 return (T - t);
53 else
54 return (1.0 - std::exp(-_a*(T - t)))/_a;
55 }
56
58 Real strike, Time maturity,
59 Time bondMaturity) const {
60
61 Real v;
62 Real _a = a();
63 if (std::fabs(maturity) < QL_EPSILON) {
64 v = 0.0;
65 } else if (_a < std::sqrt(QL_EPSILON)) {
66 v = sigma()*B(maturity, bondMaturity)* std::sqrt(maturity);
67 } else {
68 v = sigma()*B(maturity, bondMaturity)*
69 std::sqrt(0.5*(1.0 - std::exp(-2.0*_a*maturity))/_a);
70 }
71 Real f = discountBond(0.0, bondMaturity, r0_);
72 Real k = discountBond(0.0, maturity, r0_)*strike;
73
74 return blackFormula(type, k, f, v);
75 }
76
77}
78
Black formula.
Standard constant parameter .
Definition: parameter.hpp:71
No constraint.
Definition: constraint.hpp:79
Single-factor affine base class.
Real discountBond(Time now, Time maturity, Array factors) const override
Constraint imposing positivity to all arguments
Definition: constraint.hpp:92
Parameter & sigma_
Definition: vasicek.hpp:67
Parameter & b_
Definition: vasicek.hpp:66
Parameter & lambda_
Definition: vasicek.hpp:68
Real B(Time t, Time T) const override
Definition: vasicek.cpp:49
Real b() const
Definition: vasicek.hpp:55
Real sigma() const
Definition: vasicek.hpp:57
Real lambda() const
Definition: vasicek.hpp:56
Real discountBondOption(Option::Type type, Real strike, Time maturity, Time bondMaturity) const override
Definition: vasicek.cpp:57
Real a() const
Definition: vasicek.hpp:54
Vasicek(Rate r0=0.05, Real a=0.1, Real b=0.05, Real sigma=0.01, Real lambda=0.0)
Definition: vasicek.cpp:26
Parameter & a_
Definition: vasicek.hpp:65
Real A(Time t, Time T) const override
Definition: vasicek.cpp:36
Real a_
const DefaultType & t
ext::function< Real(Real)> b
#define QL_EPSILON
Definition: qldefines.hpp:178
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
Real sigma
const VF_R b_
Definition: any.hpp:35
Real blackFormula(Option::Type optionType, Real strike, Real forward, Real stdDev, Real discount, Real displacement)
ext::shared_ptr< BlackVolTermStructure > v
Vasicek model class.