Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
barrieroptionwrapper.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7 ORE is free software: you can redistribute it and/or modify it
8 under the terms of the Modified BSD License. You should have received a
9 copy of the license along with this program.
10 The license is also available online at <http://opensourcerisk.org>
11 This program is distributed on the basis that it will form a useful
12 contribution to risk analytics and model standardisation, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
15*/
16
17/*! \file ored/portfolio/barrieroptionwrapper.hpp
18 \brief Wrapper for option instruments, tracks whether option has been exercised or not
19 \ingroup tradedata
20*/
21
22#pragma once
23
26#include <ql/instruments/doublebarriertype.hpp>
27#include <ql/instruments/barriertype.hpp>
28#include <ql/index.hpp>
30
31namespace ore {
32namespace data {
33using namespace QuantLib;
34
35//! Barrier Option Wrapper
36/*! An Barrier Option Wrapper will exercise whenever the barrier is touched.
37 If it is an 'out' option it will pay the rebate value when exercised
38 */
40public:
41 BarrierOptionWrapper(const QuantLib::ext::shared_ptr<QuantLib::Instrument>& inst, const bool isLongOption,
42 const QuantLib::Date& exerciseDate, const bool isPhysicalDelivery,
43 const QuantLib::ext::shared_ptr<QuantLib::Instrument>& undInst, Barrier::Type barrierType,
44 Handle<Quote> spot, Real rebate, const QuantLib::Currency ccy,
45 const QuantLib::Date& startDate, const QuantLib::ext::shared_ptr<QuantLib::Index>& index,
47 // multiplier as seen from the option holder
48 const Real multiplier = 1.0,
49 // undMultiplier w.r.t. underlying as seen from the option holder
50 const Real undMultiplier = 1.0,
51 const std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>& additionalInstruments =
52 std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>(),
53 const std::vector<Real>& additionalMultipliers = std::vector<Real>())
54 : OptionWrapper(inst, isLongOption, std::vector<QuantLib::Date>(1, exerciseDate), isPhysicalDelivery,
55 std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>(1, undInst), multiplier, undMultiplier,
57 spot_(spot), barrierType_(barrierType), rebate_(rebate), ccy_(ccy), startDate_(startDate),
58 index_(index) {
59 calendar_ = index ? index->fixingCalendar() : calendar;
60 reset();
61 }
62
63 const std::map<std::string, boost::any>& additionalResults() const override;
64 virtual bool checkBarrier(Real, bool) const = 0;
65
66protected:
67 QuantLib::Real NPV() const override;
68 Handle<Quote> spot_;
69 Barrier::Type barrierType_;
70 Real rebate_;
71 const QuantLib::Currency ccy_;
72 const QuantLib::Date startDate_;
73 QuantLib::ext::shared_ptr<QuantLib::Index> index_;
75};
76
78public:
79 SingleBarrierOptionWrapper(const QuantLib::ext::shared_ptr<QuantLib::Instrument>& inst, const bool isLongOption,
80 const QuantLib::Date& exerciseDate, const bool isPhysicalDelivery,
81 const QuantLib::ext::shared_ptr<QuantLib::Instrument>& undInst, Barrier::Type barrierType,
82 Handle<Quote> spot, Real barrier, Real rebate, const QuantLib::Currency ccy,
83 const QuantLib::Date& startDate, const QuantLib::ext::shared_ptr<QuantLib::Index>& index,
85 // multiplier as seen from the option holder
86 const Real multiplier = 1.0,
87 // undMultiplier w.r.t. underlying as seen from the option holder
88 const Real undMultiplier = 1.0,
89 const std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>& additionalInstruments =
90 std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>(),
91 const std::vector<Real>& additionalMultipliers = std::vector<Real>())
92 : BarrierOptionWrapper(inst, isLongOption, exerciseDate, isPhysicalDelivery, undInst, barrierType, spot, rebate,
93 ccy, startDate, index, calendar, multiplier, undMultiplier, additionalInstruments, additionalMultipliers),
94 barrier_(barrier) {}
95
96 bool checkBarrier(Real spot, bool isTouchingOnly) const override;
97 bool exercise() const override;
98
99protected:
101};
102
104public:
105 DoubleBarrierOptionWrapper(const QuantLib::ext::shared_ptr<QuantLib::Instrument>& inst, const bool isLongOption,
106 const QuantLib::Date& exerciseDate, const bool isPhysicalDelivery,
107 const QuantLib::ext::shared_ptr<QuantLib::Instrument>& undInst, DoubleBarrier::Type barrierType,
108 Handle<Quote> spot, Real barrierLow, Real barrierHigh, Real rebate,
109 const QuantLib::Currency ccy, const QuantLib::Date& startDate,
110 const QuantLib::ext::shared_ptr<QuantLib::Index>& index, const QuantLib::Calendar& calendar,
111 // multiplier as seen from the option holder
112 const Real multiplier = 1.0,
113 // undMultiplier w.r.t. underlying as seen from the option holder
114 const Real undMultiplier = 1.0,
115 const std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>& additionalInstruments =
116 std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>(),
117 const std::vector<Real>& additionalMultipliers = std::vector<Real>())
119 inst, isLongOption, exerciseDate, isPhysicalDelivery, undInst,
120 (barrierType == DoubleBarrier::Type::KnockOut ? Barrier::Type::UpOut : Barrier::Type::UpIn), spot, rebate,
121 ccy, startDate, index, calendar, multiplier, undMultiplier, additionalInstruments, additionalMultipliers),
122 barrierLow_(barrierLow), barrierHigh_(barrierHigh) {
123 QL_REQUIRE(barrierType == DoubleBarrier::Type::KnockOut || barrierType == DoubleBarrier::Type::KnockIn,
124 "Invalid barrier type " << barrierType << ". Only KnockOut and KnockIn are supported.");
125 QL_REQUIRE(barrierLow < barrierHigh, "barrierLow has to be less than barrierHigh");
126 }
127
128 bool checkBarrier(Real spot, bool isTouchingOnly) const override;
129 bool exercise() const override;
130
131protected:
134};
135
136} // namespace data
137} // namespace oreplus
QuantLib::Real NPV() const override
Return the NPV of this instrument.
const std::map< std::string, boost::any > & additionalResults() const override
Return the additional results of this instrument.
BarrierOptionWrapper(const QuantLib::ext::shared_ptr< QuantLib::Instrument > &inst, const bool isLongOption, const QuantLib::Date &exerciseDate, const bool isPhysicalDelivery, const QuantLib::ext::shared_ptr< QuantLib::Instrument > &undInst, Barrier::Type barrierType, Handle< Quote > spot, Real rebate, const QuantLib::Currency ccy, const QuantLib::Date &startDate, const QuantLib::ext::shared_ptr< QuantLib::Index > &index, const QuantLib::Calendar &calendar, const Real multiplier=1.0, const Real undMultiplier=1.0, const std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > &additionalInstruments=std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > >(), const std::vector< Real > &additionalMultipliers=std::vector< Real >())
virtual bool checkBarrier(Real, bool) const =0
QuantLib::ext::shared_ptr< QuantLib::Index > index_
bool checkBarrier(Real spot, bool isTouchingOnly) const override
DoubleBarrierOptionWrapper(const QuantLib::ext::shared_ptr< QuantLib::Instrument > &inst, const bool isLongOption, const QuantLib::Date &exerciseDate, const bool isPhysicalDelivery, const QuantLib::ext::shared_ptr< QuantLib::Instrument > &undInst, DoubleBarrier::Type barrierType, Handle< Quote > spot, Real barrierLow, Real barrierHigh, Real rebate, const QuantLib::Currency ccy, const QuantLib::Date &startDate, const QuantLib::ext::shared_ptr< QuantLib::Index > &index, const QuantLib::Calendar &calendar, const Real multiplier=1.0, const Real undMultiplier=1.0, const std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > &additionalInstruments=std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > >(), const std::vector< Real > &additionalMultipliers=std::vector< Real >())
const std::vector< Real > & additionalMultipliers() const
const std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > & additionalInstruments() const
const QuantLib::Date & exerciseDate() const
the (actual) date the option was exercised
bool isPhysicalDelivery() const
return true for physical delivery, false for cash settlement
void reset() override
reset is called every time a new path is about to be priced.
bool checkBarrier(Real spot, bool isTouchingOnly) const override
SingleBarrierOptionWrapper(const QuantLib::ext::shared_ptr< QuantLib::Instrument > &inst, const bool isLongOption, const QuantLib::Date &exerciseDate, const bool isPhysicalDelivery, const QuantLib::ext::shared_ptr< QuantLib::Instrument > &undInst, Barrier::Type barrierType, Handle< Quote > spot, Real barrier, Real rebate, const QuantLib::Currency ccy, const QuantLib::Date &startDate, const QuantLib::ext::shared_ptr< QuantLib::Index > &index, const QuantLib::Calendar &calendar, const Real multiplier=1.0, const Real undMultiplier=1.0, const std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > &additionalInstruments=std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > >(), const std::vector< Real > &additionalMultipliers=std::vector< Real >())
Base class for wrapper of QL instrument, used to store "state" of trade under each scenario.
@ data
Definition: log.hpp:77
Calendar calendar
Definition: utilities.cpp:441
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Wrapper for option instruments, tracks whether option has been exercised or not.