1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 3 /* 4 Copyright (C) 2006 Warren Chou 5 Copyright (C) 2008 StatPro Italia srl 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 21 /*! \file varianceswap.hpp 22 \brief Variance swap 23 */ 24 25 #ifndef quantlib_variance_swap_hpp 26 #define quantlib_variance_swap_hpp 27 28 #include <ql/processes/blackscholesprocess.hpp> 29 #include <ql/instruments/payoffs.hpp> 30 #include <ql/option.hpp> 31 #include <ql/position.hpp> 32 33 namespace QuantLib { 34 35 //! Variance swap 36 /*! \warning This class does not manage seasoned variance swaps. 37 38 \ingroup instruments 39 */ 40 class VarianceSwap : public Instrument { 41 public: 42 class arguments; 43 class results; 44 class engine; 45 VarianceSwap(Position::Type position, 46 Real strike, 47 Real notional, 48 const Date& startDate, 49 const Date& maturityDate); 50 //! \name Instrument interface 51 //@{ 52 bool isExpired() const; 53 //@} 54 //! \name Additional interface 55 //@{ 56 // inspectors 57 Real strike() const; 58 Position::Type position() const; 59 Date startDate() const; 60 Date maturityDate() const; 61 Real notional() const; 62 // results 63 Real variance() const; 64 //@} 65 // other 66 void setupArguments(PricingEngine::arguments* args) const; 67 void fetchResults(const PricingEngine::results*) const; 68 protected: 69 void setupExpired() const; 70 // data members 71 Position::Type position_; 72 Real strike_; 73 Real notional_; 74 Date startDate_, maturityDate_; 75 // results 76 mutable Real variance_; 77 }; 78 79 80 //! %Arguments for forward fair-variance calculation 81 class VarianceSwap::arguments : public virtual PricingEngine::arguments { 82 public: arguments()83 arguments() : strike(Null<Real>()), notional(Null<Real>()) {} 84 void validate() const; 85 Position::Type position; 86 Real strike; 87 Real notional; 88 Date startDate; 89 Date maturityDate; 90 }; 91 92 93 //! %Results from variance-swap calculation 94 class VarianceSwap::results : public Instrument::results { 95 public: 96 Real variance; reset()97 void reset() { 98 Instrument::results::reset(); 99 variance = Null<Real>(); 100 } 101 }; 102 103 //! base class for variance-swap engines 104 class VarianceSwap::engine : 105 public GenericEngine<VarianceSwap::arguments, 106 VarianceSwap::results> {}; 107 108 109 // inline definitions 110 startDate() const111 inline Date VarianceSwap::startDate() const { 112 return startDate_; 113 } 114 maturityDate() const115 inline Date VarianceSwap::maturityDate() const { 116 return maturityDate_; 117 } 118 strike() const119 inline Real VarianceSwap::strike() const { 120 return strike_; 121 } 122 notional() const123 inline Real VarianceSwap::notional() const { 124 return notional_; 125 } 126 position() const127 inline Position::Type VarianceSwap::position() const { 128 return position_; 129 } 130 131 } 132 133 134 #endif 135