QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fdmvppstartlimitstepcondition.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, 2012 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/*! \file fdmvppstartlimitstepcondition.cpp
21*/
22
23#include <ql/math/array.hpp>
29
30
31namespace QuantLib {
32
34 const FdmVPPStepConditionParams& params,
35 Size nStarts,
36 const FdmVPPStepConditionMesher& mesh,
37 const ext::shared_ptr<FdmInnerValueCalculator>& gasPrice,
38 const ext::shared_ptr<FdmInnerValueCalculator>& sparkSpreadPrice)
39 : FdmVPPStepCondition(params,
40 nStates(params.tMinUp, params.tMinDown, nStarts),
41 mesh, gasPrice, sparkSpreadPrice),
42 nStarts_(nStarts) {
43 QL_REQUIRE(tMinUp_ > 0, "minimum up time must be greater than one");
44 QL_REQUIRE(tMinDown_ > 0, "minimum down time must be greater than one");
45 }
46
48 const Real gasPrice, const Array& state, Time) const {
49
50 const Real startUpCost
52
53 Array retVal(state.size());
54 const Size sss = 2*tMinUp_ + tMinDown_;
55
56 for (Size i=0; i < nStates_; ++i) {
57 const Size j = i % sss;
58
59 if (j < tMinUp_-1) {
60 retVal[i] = std::max(state[i+1], state[tMinUp_+i+1]);
61 }
62 else if (j == tMinUp_-1) {
63 retVal[i] = std::max(state[i+tMinUp_+1],
64 std::max(state[i], state[i+tMinUp_]));
65 }
66 else if (j < 2*tMinUp_) {
67 retVal[i] = retVal[i-tMinUp_];
68 }
69 else if (j < 2*tMinUp_+tMinDown_-1) {
70 retVal[i] = state[i+1];
71 }
72 else if (nStarts_ == Null<Size>()) {
73 retVal[i] = std::max(state[i],
74 std::max(state.front(), state[tMinUp_]) - startUpCost);
75
76 }
77 else if (i >= sss) {
78 retVal[i] = std::max(state[i],
79 std::max(state[i+1-2*sss], state[i+1-2*sss+tMinUp_])
80 - startUpCost);
81 }
82 else {
83 retVal[i] = state[i];
84 }
85 }
86
87 return retVal;
88 }
89
91 Size nStarts) {
92 return (2*tMinUp+tMinDown)*((nStarts == Null<Size>())? 1 : nStarts+1);
93 }
94
96 return *std::max_element(states.begin(), states.end());
97 }
98
99}
1-D array used in linear algebra.
1-D array used in linear algebra.
Definition: array.hpp:52
const_iterator end() const
Definition: array.hpp:511
Size size() const
dimension of the array
Definition: array.hpp:495
Real front() const
Definition: array.hpp:451
const_iterator begin() const
Definition: array.hpp:503
Array changeState(Real gasPrice, const Array &state, Time t) const override
Real maxValue(const Array &states) const override
FdmVPPStartLimitStepCondition(const FdmVPPStepConditionParams &params, Size nStarts, const FdmVPPStepConditionMesher &mesh, const ext::shared_ptr< FdmInnerValueCalculator > &gasPrice, const ext::shared_ptr< FdmInnerValueCalculator > &sparkSpreadPrice)
template class providing a null value for a given type.
Definition: null.hpp:76
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
layer of abstraction to calculate the inner value
iterator for a linear fdm operator
memory layout of a fdm linear operator
mesher for a fdm grid
VPP incl start limit step condition for FD models.
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