QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
stickyratchet.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) 2007 Marco Bianchetti
5 Copyright (C) 2007 Giorgio Facchinetti
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
22
23namespace QuantLib {
24
25 // Double Sticky/Ratchet payoffs
27 QL_REQUIRE((std::fabs(type1_)==1.0 || type1_==0.0),
28 "unknown/illegal type1 value (only 0.0 and +/-1,0 are allowed))");
29 QL_REQUIRE((std::fabs(type2_)==1.0 || type2_==0.0),
30 "unknown/illegal type2 value(only 0.0 and +/-1,0 are allowed)");
31 Real swaplet = gearing3_ * forward + spread3_;
32 Real effStrike1 = gearing1_ * initialValue1_ + spread1_;
33 Real effStrike2 = gearing2_ * initialValue2_ + spread2_;
34 Real effStrike3 = type1_*type2_*std::max<Real>(type2_*(swaplet-effStrike2),0.0);
35 Real price = accrualFactor_ * (swaplet -
36 type1_*std::max<Real>(type1_*(swaplet-effStrike1),effStrike3));
37 return price;
38 }
39
40 std::string DoubleStickyRatchetPayoff::name() const {
41 return "DoubleStickyRatchetPayoff";
42 }
43
45 std::ostringstream result;
46 result << name();
47 return result.str();
48 }
49
51 auto* v1 = dynamic_cast<Visitor<DoubleStickyRatchetPayoff>*>(&v);
52 if (v1 != nullptr)
53 v1->visit(*this);
54 else
56 }
57
58/*---------------------------------------------------------------------------
59
60 // Old code for single sticky/ratchet payoffs,
61 // superated by DoubleStickyRatchetPayoff class above
62
63 // Single Sticky/Ratchet payoffs
64 Real StickyRatchetPayoff::operator()(Real forward) const {
65 QL_REQUIRE(abs(type_)==1.0, "unknown/illegal option type");
66 Real swaplet = gearing2_ * forward + spread2_;
67 Real effStrike = gearing2_ * initialValue_ + spread2_;
68 Real price = accrualFactor_ * (swaplet -
69 type_*std::max<Real>(type_*(swaplet-effStrike),0.0));
70 return price;
71 }
72
73 std::string StickyRatchetPayoff::description() const {
74 std::ostringstream result;
75 result << name();
76 return result.str();
77 }
78
79 void StickyRatchetPayoff::accept(AcyclicVisitor& v) {
80 Visitor<StickyRatchetPayoff>* v1 =
81 dynamic_cast<Visitor<StickyRatchetPayoff>*>(&v);
82 if (v1 != 0)
83 v1->visit(*this);
84 else
85 Payoff::accept(v);
86 }
87-----------------------------------------------------------------------------*/
88
89}
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
std::string description() const override
void accept(AcyclicVisitor &) override
std::string name() const override
Real operator()(Real forward) const override
virtual void accept(AcyclicVisitor &)
Definition: payoff.hpp:58
Visitor for a specific class
Definition: visitor.hpp:40
virtual void visit(T &)=0
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
ext::shared_ptr< BlackVolTermStructure > v
Payoffs for double nested options of sticky or ratchet type.