Assembla home | Assembla project page
 

Changeset 211

Show
Ignore:
Timestamp:
06/16/08 22:54:38 (4 months ago)
Author:
snovik
Message:

Change: Some code cleansing of bootstrapping

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/QLNet/QLNet/Termstructures/Bootstraperror.cs

    r202 r211  
    2424namespace QLNet { 
    2525    //! 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 { 
    3027 
    31         private PiecewiseYieldCurve<T, I, B> curve_; 
     28        private IPiecewiseYieldCurve curve_; 
    3229        private BootstrapHelper<YieldTermStructure> helper_; 
    3330        private int segment_; 
    3431 
    35         public BootstrapError(PiecewiseYieldCurve<T, I, B> curve, BootstrapHelper<YieldTermStructure> helper, int segment) { 
     32        public BootstrapError(IPiecewiseYieldCurve curve, BootstrapHelper<YieldTermStructure> helper, int segment) { 
    3633            curve_ = curve; 
    3734            helper_ = helper; 
  • trunk/QLNet/QLNet/Termstructures/Bootstraphelper.cs

    r203 r211  
    2424namespace QLNet { 
    2525    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(); 
    3428    } 
    3529 
  • trunk/QLNet/QLNet/Termstructures/Iterativebootstrap.cs

    r207 r211  
    2727         
    2828        private bool validCurve_ = false; 
    29         private object tsContainer_; // yes, it is a workaround 
     29        private IPiecewiseYieldCurve ts_; // yes, it is a workaround 
    3030 
    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; 
    3833 
    3934            int n = ts_.instruments_.Count; 
     
    4540        } 
    4641 
    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() { 
    5343 
    5444            //prepare instruments 
     
    137127 
    138128                    try { 
    139                         var error = new BootstrapError<T, I, B>(ts_, instrument, i); 
     129                        var error = new BootstrapError(ts_, instrument, i); 
    140130                        double r = solver.solve(error, ts_.accuracy_, guess, min, max); 
    141131                        // redundant assignment (as it has been already performed by BootstrapError in solve procedure), but safe 
  • trunk/QLNet/QLNet/Termstructures/Yield/PiecewiseYieldCurve.cs

    r210 r211  
    2727        #region Properties 
    2828        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_; 
    2938 
    3039        public List<BootstrapHelper<YieldTermStructure>> instruments_; 
    3140 
    3241        public Interpolation interpolation_; 
     42        public IInterpolationFactory interpolator_; 
    3343        #endregion 
    3444 
     
    95105 
    96106        #region Properties 
    97         public List<Date> dates_; 
    98         public List<double> times_ = new List<double>(); 
    99  
    100107        private List<Handle<Quote>> jumps_; 
    101108        private List<Date> jumpDates_; 
     
    103110        private int nJumps_; 
    104111 
    105         public double accuracy_; 
    106112        protected Date latestReference_; 
    107113 
    108         public Interpolator interpolator_; 
    109  
    110         protected BootStrap bootstrap_; 
     114        protected IBootStrap bootstrap_; 
    111115        #endregion 
    112116 
     
    183187            jumps.ForEach(x => x.registerWith(update)); 
    184188 
    185             bootstrap_.setup<Traits, Interpolator, BootStrap>(this); 
     189            bootstrap_.setup(this); 
    186190        } 
    187191 
     
    216220            jumps.ForEach(x => x.registerWith(update)); 
    217221 
    218             bootstrap_.setup<Traits, Interpolator, BootStrap>(this); 
     222            bootstrap_.setup(this); 
    219223        }  
    220224        #endregion 
     
    222226        // here we do not refer to the base curve as in QL because our base curve is YieldTermStructure and not Traits::base_curve 
    223227        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_; } 
    227228 
    228229        public Dictionary<Date, double> nodes() { 
     
    272273        protected override void performCalculations() { 
    273274            // just delegate to the bootstrapper 
    274             bootstrap_.calculate<Traits, Interpolator, BootStrap>(); 
     275            bootstrap_.calculate(); 
    275276        } 
    276277    } 
  • trunk/QLNet/QLNet/Termstructures/localbootstrap.cs

    r208 r211  
    105105       
    106106        private bool validCurve_; 
    107         private object tsContainer_; // yes, it is a workaround 
     107        private IPiecewiseYieldCurve ts_; // yes, it is a workaround 
    108108        int localisation_; 
    109109        bool forcePositive_; 
     
    116116        } 
    117117 
    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; 
    125120 
    126121            int n = ts_.instruments_.Count; 
     
    135130        } 
    136131 
    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() { 
    143133 
    144134            validCurve_ = false; 
     
    218208                } 
    219209 
    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); 
    222212                Problem toSolve = new Problem(currentCost, solverConstraint, startArray); 
    223213                EndCriteria.Type endType = solver.minimize(toSolve, endCriteria);