| | 62 | |
|---|
| | 63 | //! Standard constant parameter \f$ a(t) = a \f$ |
|---|
| | 64 | public class ConstantParameter : Parameter |
|---|
| | 65 | { |
|---|
| | 66 | new private class Impl : Parameter.Impl |
|---|
| | 67 | { |
|---|
| | 68 | public override double value(Vector parameters, double UnnamedParameter1) |
|---|
| | 69 | { |
|---|
| | 70 | return parameters[0]; |
|---|
| | 71 | } |
|---|
| | 72 | } |
|---|
| | 73 | public ConstantParameter(Constraint constraint) |
|---|
| | 74 | : base(1, new ConstantParameter.Impl(), constraint) |
|---|
| | 75 | { |
|---|
| | 76 | } |
|---|
| | 77 | |
|---|
| | 78 | public ConstantParameter(double value, Constraint constraint) |
|---|
| | 79 | : base(1, new ConstantParameter.Impl(), constraint) |
|---|
| | 80 | { |
|---|
| | 81 | params_[0] = value; |
|---|
| | 82 | |
|---|
| | 83 | if (!(testParams(params_))) |
|---|
| | 84 | throw new ApplicationException(": invalid value"); |
|---|
| | 85 | } |
|---|
| | 86 | |
|---|
| | 87 | } |
|---|
| | 88 | |
|---|
| | 89 | //! %Parameter which is always zero \f$ a(t) = 0 \f$ |
|---|
| | 90 | public class NullParameter : Parameter |
|---|
| | 91 | { |
|---|
| | 92 | new private class Impl : Parameter.Impl |
|---|
| | 93 | { |
|---|
| | 94 | public override double value(Vector UnnamedParameter1, double UnnamedParameter2) |
|---|
| | 95 | { |
|---|
| | 96 | return 0.0; |
|---|
| | 97 | } |
|---|
| | 98 | } |
|---|
| | 99 | public NullParameter() |
|---|
| | 100 | : base(0, new NullParameter.Impl(), new NoConstraint()) |
|---|
| | 101 | { |
|---|
| | 102 | } |
|---|
| | 103 | } |
|---|
| | 104 | |
|---|
| | 105 | //! Piecewise-constant parameter |
|---|
| | 106 | // ! \f$ a(t) = a_i if t_{i-1} \geq t < t_i \f$. |
|---|
| | 107 | // This kind of parameter is usually used to enhance the fitting of a |
|---|
| | 108 | // model |
|---|
| | 109 | // |
|---|
| | 110 | public class PiecewiseConstantParameter : Parameter |
|---|
| | 111 | { |
|---|
| | 112 | new private class Impl : Parameter.Impl |
|---|
| | 113 | { |
|---|
| | 114 | public Impl(List<double> times) |
|---|
| | 115 | { |
|---|
| | 116 | times_ = times; |
|---|
| | 117 | } |
|---|
| | 118 | |
|---|
| | 119 | public override double value(Vector parameters, double t) |
|---|
| | 120 | { |
|---|
| | 121 | int size = times_.Count; |
|---|
| | 122 | for (int i = 0; i < size; i++) |
|---|
| | 123 | { |
|---|
| | 124 | if (t < times_[i]) |
|---|
| | 125 | return parameters[i]; |
|---|
| | 126 | } |
|---|
| | 127 | return parameters[size]; |
|---|
| | 128 | } |
|---|
| | 129 | private List<double> times_; |
|---|
| | 130 | } |
|---|
| | 131 | public PiecewiseConstantParameter(List<double> times) |
|---|
| | 132 | : base(times.Count + 1, new PiecewiseConstantParameter.Impl(times), new NoConstraint()) |
|---|
| | 133 | { |
|---|
| | 134 | } |
|---|
| | 135 | } |
|---|
| | 136 | |
|---|
| | 137 | ////! Deterministic time-dependent parameter used for yield-curve fitting |
|---|
| | 138 | //public class TermStructureFittingParameter : Parameter |
|---|
| | 139 | //{ |
|---|
| | 140 | // private class NumericalImpl : Parameter.Impl |
|---|
| | 141 | // { |
|---|
| | 142 | // public NumericalImpl(Handle<YieldTermStructure> termStructure) |
|---|
| | 143 | // { |
|---|
| | 144 | // times_ = null; |
|---|
| | 145 | // values_ = null; |
|---|
| | 146 | // termStructure_ = termStructure; |
|---|
| | 147 | // } |
|---|
| | 148 | |
|---|
| | 149 | // public void setvalue(double t, double x) |
|---|
| | 150 | // { |
|---|
| | 151 | // times_.Add(t); |
|---|
| | 152 | // values_.Add(x); |
|---|
| | 153 | // } |
|---|
| | 154 | // public void change(double x) |
|---|
| | 155 | // { |
|---|
| | 156 | // values_[values_.Count-1] = x; |
|---|
| | 157 | // } |
|---|
| | 158 | // public void reset() |
|---|
| | 159 | // { |
|---|
| | 160 | // times_.Clear(); |
|---|
| | 161 | // values_.Clear(); |
|---|
| | 162 | // } |
|---|
| | 163 | // public override double value(Vector UnnamedParameter1, double t) |
|---|
| | 164 | // { |
|---|
| | 165 | // //std::vector<Time>::const_iterator result = |
|---|
| | 166 | // // std::find(times_.begin(), times_.end(), t); |
|---|
| | 167 | // // QL_REQUIRE(result!=times_.end(), |
|---|
| | 168 | // // "fitting parameter not set!"); |
|---|
| | 169 | // // return values_[result - times_.begin()]; |
|---|
| | 170 | |
|---|
| | 171 | // throw new NotImplementedException("Need to implement the FindIndex method()"); |
|---|
| | 172 | |
|---|
| | 173 | // //int nIndex = times_.FindIndex( delegate(double val) { return val == locVal; }); |
|---|
| | 174 | // //if (nIndex == -1) |
|---|
| | 175 | // // throw new ApplicationException("fitting parameter not set!"); |
|---|
| | 176 | |
|---|
| | 177 | // //return values_[nIndex]; |
|---|
| | 178 | // } |
|---|
| | 179 | |
|---|
| | 180 | // public Handle<YieldTermStructure> termStructure() |
|---|
| | 181 | // { |
|---|
| | 182 | // return termStructure_; |
|---|
| | 183 | // } |
|---|
| | 184 | // private List<double> times_; |
|---|
| | 185 | // private List<double> values_; |
|---|
| | 186 | // private Handle<YieldTermStructure> termStructure_; |
|---|
| | 187 | // } |
|---|
| | 188 | |
|---|
| | 189 | // public TermStructureFittingParameter(Parameter.Impl impl) |
|---|
| | 190 | // : base(0, impl, new NoConstraint()) |
|---|
| | 191 | // { |
|---|
| | 192 | // } |
|---|
| | 193 | |
|---|
| | 194 | // public TermStructureFittingParameter(Handle<YieldTermStructure> term) |
|---|
| | 195 | // : base(0, new NumericalImpl(term), new NoConstraint()) |
|---|
| | 196 | // { |
|---|
| | 197 | // } |
|---|
| | 198 | //} |
|---|