QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
lfmswaptionengine.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) 2006 Klaus Spanderen
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
23#include <utility>
24
25namespace QuantLib {
26
27 LfmSwaptionEngine::LfmSwaptionEngine(const ext::shared_ptr<LiborForwardModel>& model,
28 Handle<YieldTermStructure> discountCurve)
30 discountCurve_(std::move(discountCurve)) {
32 }
33
34
36
38 "cash settled (ParYieldCurve) swaptions not priced with Lfm engine");
39
40 static const Spread basisPoint = 1.0e-4;
41
42 auto swap = arguments_.swap;
43 swap->setPricingEngine(ext::shared_ptr<PricingEngine>(
45
46 Spread correction = swap->spread() *
47 std::fabs(swap->floatingLegBPS()/swap->fixedLegBPS());
48 Rate fixedRate = swap->fixedRate() - correction;
49 Rate fairRate = swap->fairRate() - correction;
50
51 ext::shared_ptr<SwaptionVolatilityMatrix> volatility =
52 model_->getSwaptionVolatilityMatrix();
53
54 Date referenceDate = volatility->referenceDate();
55 DayCounter dayCounter = volatility->dayCounter();
56
57 Time exercise = dayCounter.yearFraction(referenceDate,
58 arguments_.exercise->date(0));
59 Time swapLength =
60 dayCounter.yearFraction(referenceDate,
61 arguments_.fixedPayDates.back())
62 - dayCounter.yearFraction(referenceDate,
63 arguments_.fixedResetDates[0]);
64
66 Volatility vol = volatility->volatility(exercise, swapLength,
67 fairRate, true);
68 results_.value = (swap->fixedLegBPS()/basisPoint) *
69 blackFormula(w, fixedRate, fairRate, vol*std::sqrt(exercise));
70 }
71
72}
Black formula.
const YieldTermStructure & discountCurve_
Definition: cashflows.cpp:418
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
Discounting engine for swaps.
Base class for some pricing engine on a particular model.
Shared handle to an observable.
Definition: handle.hpp:41
Handle< YieldTermStructure > discountCurve_
void calculate() const override
LfmSwaptionEngine(const ext::shared_ptr< LiborForwardModel > &model, Handle< YieldTermStructure > discountCurve)
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
Swaption class
Definition: swaption.hpp:88
discounting swap engine
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
Real Volatility
volatility
Definition: types.hpp:78
Real Spread
spreads on interest rates
Definition: types.hpp:74
Real Rate
interest rates
Definition: types.hpp:70
libor forward model swaption engine based on black formula
Definition: any.hpp:35
void swap(Array &v, Array &w) noexcept
Definition: array.hpp:903
Real blackFormula(Option::Type optionType, Real strike, Real forward, Real stdDev, Real discount, Real displacement)
STL namespace.