Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
analyticdoublebarrierbinaryengine.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2022 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
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19#include <ql/exercise.hpp>
21#include <utility>
22
23namespace QuantExt {
24
25using namespace QuantLib;
26
28
29 QuantLib::AnalyticDoubleBarrierBinaryEngine::calculate();
30
31 // If a payDate was provided (and is greater than the expiryDate)
32 if (payDate_ > arguments_.exercise->lastDate()) {
33 Rate payDateDiscount = process_->riskFreeRate()->discount(payDate_);
34 Rate expiryDateDiscount = process_->riskFreeRate()->discount(arguments_.exercise->lastDate());
35 Rate factor = payDateDiscount / expiryDateDiscount;
36 results_.value *= factor;
37 }
38
39 if (flipResults_) {
40 // Invert spot, costOfCarry
41 auto it = results_.additionalResults.find("spot");
42 if (it != results_.additionalResults.end())
43 it->second = 1. / boost::any_cast<Real>(it->second);
44 it = results_.additionalResults.find("costOfCarry");
45 if (it != results_.additionalResults.end())
46 it->second = -1. * boost::any_cast<Real>(it->second);
47
48 // Swap riskFreeRate and dividendYield
49 auto rfDiscountIt = results_.additionalResults.find("riskFreeRate");
50 auto divDiscountIt = results_.additionalResults.find("dividendYield");
51 if (rfDiscountIt != results_.additionalResults.end() && divDiscountIt != results_.additionalResults.end())
52 std::swap(rfDiscountIt->second, divDiscountIt->second);
53
54 // Invert and swap barrierLow and barrierHigh
55 auto barrierLowIt = results_.additionalResults.find("barrierLow");
56 auto barrierHighIt = results_.additionalResults.find("barrierHigh");
57 if (barrierLowIt != results_.additionalResults.end() && barrierHighIt != results_.additionalResults.end()) {
58 barrierLowIt->second = 1. / boost::any_cast<Real>(barrierLowIt->second);
59 barrierHighIt->second = 1. / boost::any_cast<Real>(barrierHighIt->second);
60 std::swap(barrierLowIt->second, barrierHighIt->second);
61 }
62 }
63}
64
65} // namespace QuantExt
Wrapper of QuantLib analytic double barrier binary engine to allow for flipping back some of the addi...
const Instrument::results * results_
Definition: cdsoption.cpp:81
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
Swap::arguments * arguments_