QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fdmvppstepconditionfactory.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) 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 fdmvppstepconditionfactory.cpp
21*/
22
26#include <utility>
27
28namespace QuantLib {
29
31 : args_(std::move(args)) {
34 "start and running hour limt together is not supported");
35
37 && args_.nStarts == Null<Size>()) {
38 type_ = Vanilla;
39 }
40 else if (args_.nRunningHours == Null<Size>()) {
42 }
43 else {
45 }
46 }
47
48 ext::shared_ptr<Fdm1dMesher>
50 Size nStates;
51 switch (type_) {
52 case Vanilla:
53 nStates = 2*args_.tMinUp + args_.tMinDown;
54 break;
55 case StartLimit:
58 break;
59 default:
60 QL_FAIL("vpp type is not supported");
61 }
62
63 return ext::shared_ptr<Fdm1dMesher>(
64 new Uniform1dMesher(0.0, 1.0, nStates));
65 }
66
67 ext::shared_ptr<FdmVPPStepCondition> FdmVPPStepConditionFactory::build(
68 const FdmVPPStepConditionMesher& mesh,
69 Real fuelCostAddon,
70 const ext::shared_ptr<FdmInnerValueCalculator>& fuel,
71 const ext::shared_ptr<FdmInnerValueCalculator>& spark) const {
72
73 const FdmVPPStepConditionParams params = {
77 fuelCostAddon
78 };
79
80 switch (type_) {
81 case Vanilla:
82 case StartLimit:
83 return ext::shared_ptr<FdmVPPStepCondition>(
85 mesh, fuel, spark));
86 break;
87 default:
88 QL_FAIL("vpp type is not supported");
89 }
90 }
91}
ext::shared_ptr< Fdm1dMesher > stateMesher() const
ext::shared_ptr< FdmVPPStepCondition > build(const FdmVPPStepConditionMesher &mesh, Real fuelCostAddon, const ext::shared_ptr< FdmInnerValueCalculator > &fuel, const ext::shared_ptr< FdmInnerValueCalculator > &spark) const
const VanillaVPPOption::arguments args_
enum QuantLib::FdmVPPStepConditionFactory::Type type_
FdmVPPStepConditionFactory(VanillaVPPOption::arguments args)
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
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Definition: errors.hpp:92
VPP incl start limit step condition for FD models.
factory for VPP step conditions for FD models
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
STL namespace.
One-dimensional simple uniform grid mesher.