QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
kirkspreadoptionengine.cpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2011 Master IMAFA - Polytech'Nice Sophia - Université de Nice Sophia Antipolis
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20#include <ql/exercise.hpp>
23#include <utility>
24
25using namespace std;
26
27namespace QuantLib {
28
30
31 KirkSpreadOptionEngine::KirkSpreadOptionEngine(ext::shared_ptr<BlackProcess> process1,
32 ext::shared_ptr<BlackProcess> process2,
33 Handle<Quote> correlation)
34 : process1_(std::move(process1)), process2_(std::move(process2)), rho_(std::move(correlation)) {
38 }
39
41
42 // First: tests on types
44 "not an European Option");
45
46 ext::shared_ptr<PlainVanillaPayoff> payoff =
47 ext::dynamic_pointer_cast<PlainVanillaPayoff>(arguments_.payoff);
48 QL_REQUIRE(payoff, "not a plain-vanilla payoff");
49
50 // forward values - futures, so b=0
51 Real forward1 = process1_->stateVariable()->value();
52 Real forward2 = process2_->stateVariable()->value();
53
54 Date exerciseDate = arguments_.exercise->lastDate();
55
56 // Volatilities
57 Real sigma1 =
58 process1_->blackVolatility()->blackVol(exerciseDate,forward1);
59 Real sigma2 =
60 process2_->blackVolatility()->blackVol(exerciseDate,forward2);
61
62 DiscountFactor riskFreeDiscount =
63 process1_->riskFreeRate()->discount(exerciseDate);
64
65 Real strike = payoff->strike();
66
67 // Unique F (forward) value for pricing
68 Real F = forward1/(forward2+strike);
69
70 // Its volatility
71 Real sigma =
72 sqrt(pow(sigma1,2)
73 + pow((sigma2*(forward2/(forward2+strike))),2)
74 - 2*rho_->value()*sigma1*sigma2*(forward2/(forward2+strike)));
75
76 // Day counter and Dates handling variables
77 DayCounter rfdc = process1_->riskFreeRate()->dayCounter();
78 Time t = rfdc.yearFraction(process1_->riskFreeRate()->referenceDate(),
79 arguments_.exercise->lastDate());
80
81 // Black-Scholes solution values
82 Real d1 = (log(F)+ 0.5*pow(sigma,2)*t) / (sigma*sqrt(t));
83 Real d2 = d1 - sigma*sqrt(t);
84
87 Real Nd1 = cum(d1);
88 Real Nd2 = cum(d2);
89 Real NMd1 = cum(-d1);
90 Real NMd2 = cum(-d2);
91
92 Option::Type optionType = payoff->optionType();
93
94 if (optionType==Option::Call) {
95 results_.value = riskFreeDiscount*(F*Nd1-Nd2)*(forward2+strike);
96 } else {
97 results_.value = riskFreeDiscount*(NMd2 -F*NMd1)*(forward2+strike);
98 }
99
100 Real callValue = optionType == Option::Call ? results_.value : riskFreeDiscount*(F*Nd1-Nd2)*(forward2+strike);
101 results_.theta = -((log(riskFreeDiscount)/t)*callValue
102 + riskFreeDiscount*(forward1*sigma)/(2*sqrt(t))*pdf(d1));
103 }
104
106
107}
108
Cumulative normal distribution function.
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
Definition: daycounter.hpp:128
Shared handle to an observable.
Definition: handle.hpp:41
KirkSpreadOptionEngine(ext::shared_ptr< BlackProcess > process1, ext::shared_ptr< BlackProcess > process2, Handle< Quote > correlation)
ext::shared_ptr< BlackProcess > process1_
ext::shared_ptr< BlackProcess > process2_
Normal distribution function.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:226
ext::shared_ptr< Exercise > exercise
Definition: option.hpp:65
ext::shared_ptr< Payoff > payoff
Definition: option.hpp:64
const DefaultType & t
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Option exercise classes and payoff function.
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real DiscountFactor
discount factor between dates
Definition: types.hpp:66
Real sigma
ext::shared_ptr< QuantLib::Payoff > payoff
Kirk approximation for European spread option on futures.
Definition: any.hpp:37
STL namespace.
normal, cumulative and inverse cumulative distributions
#define QL_DEPRECATED_DISABLE_WARNING
Definition: qldefines.hpp:216
#define QL_DEPRECATED_ENABLE_WARNING
Definition: qldefines.hpp:217
Real F
Definition: sabr.cpp:200