Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
analyticdigitalamericanengine.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
23using std::string;
24using std::vector;
25
26namespace QuantExt {
27
28using namespace QuantLib;
29
31
32 QuantLib::AnalyticDigitalAmericanEngine::calculate();
33
34 // If a payDate was provided (and is greater than the expiryDate)
35 if (payDate_ > arguments_.exercise->lastDate()) {
36 Rate payDateDiscount = process_->riskFreeRate()->discount(payDate_);
37 Rate expiryDateDiscount = process_->riskFreeRate()->discount(arguments_.exercise->lastDate());
38 Rate factor = payDateDiscount / expiryDateDiscount;
39 results_.value *= factor;
40
41 auto discTouchProbIt = results_.additionalResults.find("discountedTouchProbability");
42 if (discTouchProbIt != results_.additionalResults.end()) {
43 if (knock_in())
44 discTouchProbIt->second = boost::any_cast<Real>(discTouchProbIt->second) * factor;
45 else
46 discTouchProbIt->second = 1.0 - (factor * (1.0 - boost::any_cast<Real>(discTouchProbIt->second)));
47 }
48 }
49
50 if (flipResults_) {
51 // Invert spot, forward, strike
52 auto resToInvert = vector<string>({"spot", "forward", "strike"});
53 for (const string& res : resToInvert) {
54 auto it = results_.additionalResults.find(res);
55 if (it != results_.additionalResults.end())
56 it->second = 1. / boost::any_cast<Real>(it->second);
57 }
58
59 // Swap riskFreeDiscount and dividendDiscount
60 auto rfDiscountIt = results_.additionalResults.find("riskFreeDiscount");
61 auto divDiscountIt = results_.additionalResults.find("dividendDiscount");
62 if (rfDiscountIt != results_.additionalResults.end() && divDiscountIt != results_.additionalResults.end())
63 std::swap(rfDiscountIt->second, divDiscountIt->second);
64 }
65}
66
67} // namespace QuantExt
Wrapper of QuantLib analytic digital American option engine to allow for flipping back some of the ad...
const Instrument::results * results_
Definition: cdsoption.cpp:81
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
Swap::arguments * arguments_