/src/quantlib/ql/experimental/finitedifferences/fdmvppstepconditionfactory.cpp
Line | Count | Source |
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 | | <https://www.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 | | |
23 | | #include <ql/experimental/finitedifferences/fdmvppstartlimitstepcondition.hpp> |
24 | | #include <ql/experimental/finitedifferences/fdmvppstepconditionfactory.hpp> |
25 | | #include <ql/methods/finitedifferences/meshers/uniform1dmesher.hpp> |
26 | | #include <utility> |
27 | | |
28 | | namespace QuantLib { |
29 | | |
30 | | FdmVPPStepConditionFactory::FdmVPPStepConditionFactory(VanillaVPPOption::arguments args) |
31 | 0 | : args_(std::move(args)) { |
32 | 0 | QL_REQUIRE(!( args_.nStarts != Null<Size>() |
33 | 0 | && args_.nRunningHours != Null<Size>()), |
34 | 0 | "start and running hour limt together is not supported"); |
35 | | |
36 | 0 | if ( args_.nRunningHours == Null<Size>() |
37 | 0 | && args_.nStarts == Null<Size>()) { |
38 | 0 | type_ = Vanilla; |
39 | 0 | } |
40 | 0 | else if (args_.nRunningHours == Null<Size>()) { |
41 | 0 | type_ = StartLimit; |
42 | 0 | } |
43 | 0 | else { |
44 | 0 | type_ = RunningHourLimit; |
45 | 0 | } |
46 | 0 | } |
47 | | |
48 | | ext::shared_ptr<Fdm1dMesher> |
49 | 0 | FdmVPPStepConditionFactory::stateMesher() const { |
50 | 0 | Size nStates; |
51 | 0 | switch (type_) { |
52 | 0 | case Vanilla: |
53 | 0 | nStates = 2*args_.tMinUp + args_.tMinDown; |
54 | 0 | break; |
55 | 0 | case StartLimit: |
56 | 0 | nStates = FdmVPPStartLimitStepCondition::nStates( |
57 | 0 | args_.tMinUp,args_.tMinDown, args_.nStarts); |
58 | 0 | break; |
59 | 0 | default: |
60 | 0 | QL_FAIL("vpp type is not supported"); |
61 | 0 | } |
62 | | |
63 | 0 | return ext::shared_ptr<Fdm1dMesher>( |
64 | 0 | new Uniform1dMesher(0.0, 1.0, nStates)); |
65 | 0 | } |
66 | | |
67 | | ext::shared_ptr<FdmVPPStepCondition> FdmVPPStepConditionFactory::build( |
68 | | const FdmVPPStepConditionMesher& mesh, |
69 | | Real fuelCostAddon, |
70 | | const ext::shared_ptr<FdmInnerValueCalculator>& fuel, |
71 | 0 | const ext::shared_ptr<FdmInnerValueCalculator>& spark) const { |
72 | |
|
73 | 0 | const FdmVPPStepConditionParams params = { |
74 | 0 | args_.heatRate, args_.pMin, args_.pMax, |
75 | 0 | args_.tMinUp, args_.tMinDown, |
76 | 0 | args_.startUpFuel, args_.startUpFixCost, |
77 | 0 | fuelCostAddon |
78 | 0 | }; |
79 | |
|
80 | 0 | switch (type_) { |
81 | 0 | case Vanilla: |
82 | 0 | case StartLimit: |
83 | 0 | return ext::shared_ptr<FdmVPPStepCondition>( |
84 | 0 | new FdmVPPStartLimitStepCondition(params, args_.nStarts, |
85 | 0 | mesh, fuel, spark)); |
86 | 0 | default: |
87 | | QL_FAIL("vpp type is not supported"); |
88 | 0 | } |
89 | 0 | } |
90 | | } |