QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
option.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
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
24#ifndef quantlib_option_hpp
25#define quantlib_option_hpp
26
27#include <ql/instrument.hpp>
28#include <utility>
29
30namespace QuantLib {
31
32 class Payoff;
33 class Exercise;
34
36 class Option : public Instrument {
37 public:
38 class arguments;
39 enum Type { Put = -1,
40 Call = 1
41 };
42 Option(ext::shared_ptr<Payoff> payoff, ext::shared_ptr<Exercise> exercise)
43 : payoff_(std::move(payoff)), exercise_(std::move(exercise)) {}
44 void setupArguments(PricingEngine::arguments*) const override;
45 ext::shared_ptr<Payoff> payoff() const { return payoff_; }
46 ext::shared_ptr<Exercise> exercise() const { return exercise_; };
47 protected:
48 // arguments
49 ext::shared_ptr<Payoff> payoff_;
50 ext::shared_ptr<Exercise> exercise_;
51 };
52
54 std::ostream& operator<<(std::ostream&, Option::Type);
55
58 public:
59 arguments() = default;
60 void validate() const override {
61 QL_REQUIRE(payoff, "no payoff given");
62 QL_REQUIRE(exercise, "no exercise given");
63 }
64 ext::shared_ptr<Payoff> payoff;
65 ext::shared_ptr<Exercise> exercise;
66 };
67
69 class Greeks : public virtual PricingEngine::results {
70 public:
71 void reset() override { delta = gamma = theta = vega = rho = dividendRho = Null<Real>(); }
76 };
77
79 class MoreGreeks : public virtual PricingEngine::results {
80 public:
81 void reset() override {
84 }
87 };
88
89
90 // inline definitions
91
93 auto* arguments = dynamic_cast<Option::arguments*>(args);
94 QL_REQUIRE(arguments != nullptr, "wrong argument type");
95
98 }
99
100 inline std::ostream& operator<<(std::ostream& out, Option::Type type) {
101 switch (type) {
102 case Option::Call:
103 return out << "Call";
104 case Option::Put:
105 return out << "Put";
106 default:
107 QL_FAIL("unknown option type");
108 }
109 }
110
111}
112
113
114#endif
additional option results
Definition: option.hpp:69
Real dividendRho
Definition: option.hpp:75
void reset() override
Definition: option.hpp:71
Abstract instrument class.
Definition: instrument.hpp:44
more additional option results
Definition: option.hpp:79
void reset() override
Definition: option.hpp:81
template class providing a null value for a given type.
Definition: null.hpp:76
basic option arguments
Definition: option.hpp:57
ext::shared_ptr< Exercise > exercise
Definition: option.hpp:65
void validate() const override
Definition: option.hpp:60
ext::shared_ptr< Payoff > payoff
Definition: option.hpp:64
base option class
Definition: option.hpp:36
void setupArguments(PricingEngine::arguments *) const override
Definition: option.hpp:92
ext::shared_ptr< Payoff > payoff_
Definition: option.hpp:49
ext::shared_ptr< Payoff > payoff() const
Definition: option.hpp:45
Option(ext::shared_ptr< Payoff > payoff, ext::shared_ptr< Exercise > exercise)
Definition: option.hpp:42
ext::shared_ptr< Exercise > exercise_
Definition: option.hpp:50
ext::shared_ptr< Exercise > exercise() const
Definition: option.hpp:46
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
std::ostream & operator<<(std::ostream &out, GFunctionFactory::YieldCurveModel type)
STL namespace.