QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
discretizedvanillaoption.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) 2002, 2003 Sadruddin Rejeb
5 Copyright (C) 2004 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
22#include <vector>
23
24namespace QuantLib {
25
27 const VanillaOption::arguments& args,
28 const StochasticProcess& process,
29 const TimeGrid& grid)
30 : arguments_(args) {
31 stoppingTimes_.resize(args.exercise->dates().size());
32 for (Size i=0; i<stoppingTimes_.size(); ++i) {
34 process.time(args.exercise->date(i));
35 if (!grid.empty()) {
36 // adjust to the given grid
38 }
39 }
40 }
41
43 values_ = Array(size, 0.0);
45 }
46
48
49 Time now = time();
50 switch (arguments_.exercise->type()) {
52 if (now <= stoppingTimes_[1] &&
53 now >= stoppingTimes_[0])
55 break;
59 break;
61 for (Real stoppingTime : stoppingTimes_) {
62 if (isOnTime(stoppingTime))
64 }
65 break;
66 default:
67 QL_FAIL("invalid option type");
68 }
69 }
70
72 Array grid = method()->grid(time());
73 for (Size j=0; j<values_.size(); j++) {
74 values_[j] = std::max(values_[j],
75 (*arguments_.payoff)(grid[j]));
76 }
77 }
78
79}
80
1-D array used in linear algebra.
Definition: array.hpp:52
Size size() const
dimension of the array
Definition: array.hpp:495
const ext::shared_ptr< Lattice > & method() const
DiscretizedVanillaOption(const VanillaOption::arguments &, const StochasticProcess &process, const TimeGrid &grid=TimeGrid())
basic option arguments
Definition: option.hpp:57
ext::shared_ptr< Exercise > exercise
Definition: option.hpp:65
ext::shared_ptr< Payoff > payoff
Definition: option.hpp:64
multi-dimensional stochastic process class.
virtual Time time(const Date &) const
time grid class
Definition: timegrid.hpp:43
bool empty() const
Definition: timegrid.hpp:165
Time closestTime(Time t) const
returns the time on the grid closest to the given t
Definition: timegrid.hpp:148
discretized vanilla option
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Definition: errors.hpp:92
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35