QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
spreadblackscholesvanillaengine.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) 2024 Klaus Spanderen
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>
22
23namespace QuantLib {
24
26 ext::shared_ptr<GeneralizedBlackScholesProcess> process1,
27 ext::shared_ptr<GeneralizedBlackScholesProcess> process2,
28 Real correlation)
29 : process1_(std::move(process1)),
30 process2_(std::move(process2)),
31 rho_(correlation) {
34 }
35
37 const ext::shared_ptr<EuropeanExercise> exercise =
38 ext::dynamic_pointer_cast<EuropeanExercise>(arguments_.exercise);
39 QL_REQUIRE(exercise, "not an European exercise");
40
41 const ext::shared_ptr<SpreadBasketPayoff> spreadPayoff =
42 ext::dynamic_pointer_cast<SpreadBasketPayoff>(arguments_.payoff);
43 QL_REQUIRE(spreadPayoff," spread payoff expected");
44
45 const ext::shared_ptr<PlainVanillaPayoff> payoff =
46 ext::dynamic_pointer_cast<PlainVanillaPayoff>(
47 spreadPayoff->basePayoff());
48 QL_REQUIRE(payoff, "non-plain payoff given");
49 const Real strike = payoff->strike();
50 const Option::Type optionType = payoff->optionType();
51
52
53 const Date maturityDate = exercise->lastDate();
54 const Real f1 = process1_->stateVariable()->value()
55 / process1_->riskFreeRate()->discount(maturityDate)
56 * process1_->dividendYield()->discount(maturityDate);
57
58 const Real f2 = process2_->stateVariable()->value()
59 / process2_->riskFreeRate()->discount(maturityDate)
60 * process2_->dividendYield()->discount(maturityDate);
61
62 const Real variance1 =
63 process1_->blackVolatility()->blackVariance(maturityDate, f1);
64 const Real variance2 =
65 process2_->blackVolatility()->blackVariance(maturityDate, f2);
66
67 const DiscountFactor df =
68 process1_->riskFreeRate()->discount(exercise->lastDate());
69
70 results_.value = calculate(f1, f2, strike, optionType, variance1, variance2, df);
71 }
72}
Concrete date class.
Definition: date.hpp:125
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 ext::shared_ptr< GeneralizedBlackScholesProcess > process1_
SpreadBlackScholesVanillaEngine(ext::shared_ptr< GeneralizedBlackScholesProcess > process1, ext::shared_ptr< GeneralizedBlackScholesProcess > process2, Real correlation)
const ext::shared_ptr< GeneralizedBlackScholesProcess > process2_
#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.
QL_REAL Real
real number
Definition: types.hpp:50
Real DiscountFactor
discount factor between dates
Definition: types.hpp:66
ext::shared_ptr< QuantLib::Payoff > payoff
Definition: any.hpp:37
STL namespace.
base class for 2d spread pricing engines using the Black-Scholes model.