Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
varianceswapgeneralreplicationengine.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 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/*! \file qle/pricingengines/varianceswapgeneralreplicationengine.hpp
20 \brief variance swap engine
21 \ingroup engines
22*/
23
24#pragma once
25
26#include <ql/quote.hpp>
27#include <ql/termstructures/yieldtermstructure.hpp>
28#include <ql/time/daycounters/actualactual.hpp>
29
30#include <ql/exercise.hpp>
31#include <ql/index.hpp>
32#include <ql/instruments/europeanoption.hpp>
33#include <ql/pricingengines/vanilla/analyticeuropeanengine.hpp>
34
36
37namespace QuantExt {
38using namespace QuantLib;
39
40/* Reference:
41 - Variance Swaps, European Equity Derivatives Research, JPMorgan, 4.5
42 - https://en.wikipedia.org/wiki/Variance_swap */
44public:
45 /*
46 struct VarSwapSettings {
47 enum class Scheme { GaussLobatto, Segment };
48 enum class Bounds { Fixed, PriceThreshold };
49 Scheme scheme = Scheme::GaussLobatto;
50 Bounds bounds = Bounds::PriceThreshold;
51 Real accuracy = 1E-5;
52 Size maxIterations = 1000;
53 Size steps = 100;
54 Real priceThreshold = 1E-10;
55 Size maxPriceThresholdSteps = 100;
56 Real priceThresholdStep = 0.1;
57 Real fixedMinStdDevs = -5.0;
58 Real fixedMaxStdDevs = 5.0;
59 };
60 */
61 // Renamed from Settings to avoid conflicts during the Python wrapping
63 public:
64 enum class Scheme { GaussLobatto, Segment };
65 enum class Bounds { Fixed, PriceThreshold };
69 Real accuracy = 1E-5;
70 Size maxIterations = 1000;
71 Size steps = 100;
72 Real priceThreshold = 1E-10;
75 Real fixedMinStdDevs = -5.0;
76 Real fixedMaxStdDevs = 5.0;
77 };
78
79 GeneralisedReplicatingVarianceSwapEngine(const QuantLib::ext::shared_ptr<QuantLib::Index>& index,
80 const QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess>& process,
81 const Handle<YieldTermStructure>& discountingTS,
82 const VarSwapSettings settings = VarSwapSettings(),
83 const bool staticTodaysSpot = true);
84
85 void calculate() const override;
86
87protected:
88 Real calculateAccruedVariance(const Calendar& jointCal) const;
89 Real calculateFutureVariance(const Date& maturity) const;
90
91 QuantLib::ext::shared_ptr<Index> index_;
92 QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess> process_;
93 Handle<YieldTermStructure> discountingTS_;
96
97 mutable Real cachedTodaysSpot_ = Null<Real>();
98};
99
100} // namespace QuantExt
QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > process_
base class for variance-swap engines
Variance swap.