Changeset 211
- Timestamp:
- 06/16/08 22:54:38 (4 months ago)
- Files:
-
- trunk/QLNet/QLNet/Termstructures/Bootstraperror.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Termstructures/Bootstraphelper.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Termstructures/Iterativebootstrap.cs (modified) (3 diffs)
- trunk/QLNet/QLNet/Termstructures/Yield/PiecewiseYieldCurve.cs (modified) (7 diffs)
- trunk/QLNet/QLNet/Termstructures/localbootstrap.cs (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/QLNet/QLNet/Termstructures/Bootstraperror.cs
r202 r211 24 24 namespace QLNet { 25 25 //! bootstrap error 26 public class BootstrapError<T, I, B> : ISolver1d 27 where T : ITraits, new() 28 where I : IInterpolationFactory, new() 29 where B : IBootStrap, new() { 26 public class BootstrapError : ISolver1d { 30 27 31 private PiecewiseYieldCurve<T, I, B>curve_;28 private IPiecewiseYieldCurve curve_; 32 29 private BootstrapHelper<YieldTermStructure> helper_; 33 30 private int segment_; 34 31 35 public BootstrapError( PiecewiseYieldCurve<T, I, B>curve, BootstrapHelper<YieldTermStructure> helper, int segment) {32 public BootstrapError(IPiecewiseYieldCurve curve, BootstrapHelper<YieldTermStructure> helper, int segment) { 36 33 curve_ = curve; 37 34 helper_ = helper; trunk/QLNet/QLNet/Termstructures/Bootstraphelper.cs
r203 r211 24 24 namespace QLNet { 25 25 public interface IBootStrap { 26 void setup<T, I, B>(PiecewiseYieldCurve<T, I, B> ts) 27 where T : ITraits, new() 28 where I : IInterpolationFactory, new() 29 where B : IBootStrap, new(); 30 void calculate<T, I, B>() 31 where T : ITraits, new() 32 where I : IInterpolationFactory, new() 33 where B : IBootStrap, new(); 26 void setup(IPiecewiseYieldCurve ts); 27 void calculate(); 34 28 } 35 29 trunk/QLNet/QLNet/Termstructures/Iterativebootstrap.cs
r207 r211 27 27 28 28 private bool validCurve_ = false; 29 private object tsContainer_; // yes, it is a workaround29 private IPiecewiseYieldCurve ts_; // yes, it is a workaround 30 30 31 public void setup<T, I, B>(PiecewiseYieldCurve<T, I, B> ts) 32 where T : ITraits, new() 33 where I : IInterpolationFactory, new() 34 where B : IBootStrap, new() { 35 36 tsContainer_ = ts; 37 PiecewiseYieldCurve<T, I, B> ts_ = tsContainer_ as PiecewiseYieldCurve<T, I, B>; 31 public void setup(IPiecewiseYieldCurve ts) { 32 ts_ = ts; 38 33 39 34 int n = ts_.instruments_.Count; … … 45 40 } 46 41 47 public void calculate<T, I, B>() 48 where T : ITraits, new() 49 where I : IInterpolationFactory, new() 50 where B : IBootStrap, new() { 51 52 PiecewiseYieldCurve<T, I, B> ts_ = tsContainer_ as PiecewiseYieldCurve<T, I, B>; 42 public void calculate() { 53 43 54 44 //prepare instruments … … 137 127 138 128 try { 139 var error = new BootstrapError <T, I, B>(ts_, instrument, i);129 var error = new BootstrapError(ts_, instrument, i); 140 130 double r = solver.solve(error, ts_.accuracy_, guess, min, max); 141 131 // redundant assignment (as it has been already performed by BootstrapError in solve procedure), but safe trunk/QLNet/QLNet/Termstructures/Yield/PiecewiseYieldCurve.cs
r210 r211 27 27 #region Properties 28 28 public List<double> data_; 29 public List<double> data() { calculate(); return data_; } 30 31 public List<Date> dates_; 32 public List<Date> dates() { calculate(); return dates_; } 33 34 public List<double> times_ = new List<double>(); 35 public List<double> times() { calculate(); return times_; } 36 37 public double accuracy_; 29 38 30 39 public List<BootstrapHelper<YieldTermStructure>> instruments_; 31 40 32 41 public Interpolation interpolation_; 42 public IInterpolationFactory interpolator_; 33 43 #endregion 34 44 … … 95 105 96 106 #region Properties 97 public List<Date> dates_;98 public List<double> times_ = new List<double>();99 100 107 private List<Handle<Quote>> jumps_; 101 108 private List<Date> jumpDates_; … … 103 110 private int nJumps_; 104 111 105 public double accuracy_;106 112 protected Date latestReference_; 107 113 108 public Interpolator interpolator_; 109 110 protected BootStrap bootstrap_; 114 protected IBootStrap bootstrap_; 111 115 #endregion 112 116 … … 183 187 jumps.ForEach(x => x.registerWith(update)); 184 188 185 bootstrap_.setup <Traits, Interpolator, BootStrap>(this);189 bootstrap_.setup(this); 186 190 } 187 191 … … 216 220 jumps.ForEach(x => x.registerWith(update)); 217 221 218 bootstrap_.setup <Traits, Interpolator, BootStrap>(this);222 bootstrap_.setup(this); 219 223 } 220 224 #endregion … … 222 226 // here we do not refer to the base curve as in QL because our base curve is YieldTermStructure and not Traits::base_curve 223 227 public override Date maxDate() { calculate(); return dates_.Last(); } 224 public List<Date> dates() { calculate(); return dates_; }225 public List<double> times() { calculate(); return times_; }226 public List<double> data() { calculate(); return data_; }227 228 228 229 public Dictionary<Date, double> nodes() { … … 272 273 protected override void performCalculations() { 273 274 // just delegate to the bootstrapper 274 bootstrap_.calculate <Traits, Interpolator, BootStrap>();275 bootstrap_.calculate(); 275 276 } 276 277 } trunk/QLNet/QLNet/Termstructures/localbootstrap.cs
r208 r211 105 105 106 106 private bool validCurve_; 107 private object tsContainer_; // yes, it is a workaround107 private IPiecewiseYieldCurve ts_; // yes, it is a workaround 108 108 int localisation_; 109 109 bool forcePositive_; … … 116 116 } 117 117 118 public void setup<T, I, B>(PiecewiseYieldCurve<T, I, B> ts) 119 where T : ITraits, new() 120 where I : IInterpolationFactory, new() 121 where B : IBootStrap, new() { 122 123 tsContainer_ = ts; 124 PiecewiseYieldCurve<T, I, B> ts_ = tsContainer_ as PiecewiseYieldCurve<T, I, B>; 118 public void setup(IPiecewiseYieldCurve ts) { 119 ts_ = ts; 125 120 126 121 int n = ts_.instruments_.Count; … … 135 130 } 136 131 137 public void calculate<T, I, B>() 138 where T : ITraits, new() 139 where I : IInterpolationFactory, new() 140 where B : IBootStrap, new() { 141 142 PiecewiseYieldCurve<T, I, B> ts_ = tsContainer_ as PiecewiseYieldCurve<T, I, B>; 132 public void calculate() { 143 133 144 134 validCurve_ = false; … … 218 208 } 219 209 220 var currentCost = new PenaltyFunction< PiecewiseYieldCurve<T, I, B>>(ts_, initialDataPt, ts_.instruments_,221 iInst - localisation_ + 1, iInst + 1);210 var currentCost = new PenaltyFunction<IPiecewiseYieldCurve>(ts_, initialDataPt, ts_.instruments_, 211 iInst - localisation_ + 1, iInst + 1); 222 212 Problem toSolve = new Problem(currentCost, solverConstraint, startArray); 223 213 EndCriteria.Type endType = solver.minimize(toSolve, endCriteria);