Assembla home | Assembla project page
 

Changeset 209

Show
Ignore:
Timestamp:
06/16/08 22:31:33 (3 months ago)
Author:
snovik
Message:

New: QL 15070 (PiecewiseYieldCurve? with jumps)

Files:

Legend:

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

    r208 r209  
    6868            : base(referenceDate, instruments, dayCounter) { } 
    6969        public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 
    70                                    DayCounter dayCounter, Handle<Quote> turnOfYearEffect
    71             : base(referenceDate, instruments, dayCounter, turnOfYearEffect) { } 
    72         public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 
    73                                    DayCounter dayCounter, Handle<Quote> turnOfYearEffect, double accuracy) 
    74             : base(referenceDate, instruments, dayCounter, turnOfYearEffect, accuracy) { } 
    75         public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 
    76                                    DayCounter dayCounter, Handle<Quote> turnOfYearEffect, double accuracy, Interpolator i) 
    77             : base(referenceDate, instruments, dayCounter, turnOfYearEffect, accuracy, i) { } 
     70                                   DayCounter dayCounter, List<Handle<Quote>> jumps, List<Date> jumpDates
     71            : base(referenceDate, instruments, dayCounter, jumps, jumpDates) { } 
     72        public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 
     73                                   DayCounter dayCounter, List<Handle<Quote>> jumps, List<Date> jumpDates, double accuracy) 
     74            : base(referenceDate, instruments, dayCounter, jumps, jumpDates, accuracy) { } 
     75        public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 
     76                                   DayCounter dayCounter, List<Handle<Quote>> jumps, List<Date> jumpDates, double accuracy, Interpolator i) 
     77            : base(referenceDate, instruments, dayCounter, jumps, jumpDates, accuracy, i) { } 
    7878 
    7979        public PiecewiseYieldCurve(int settlementDays, Calendar calendar, List<BootstrapHelper<YieldTermStructure>> instruments, 
    8080                                   DayCounter dayCounter) 
    81             : this(settlementDays, calendar, instruments, dayCounter, new Handle<Quote>(), 1.0e-12) { } 
     81            : this(settlementDays, calendar, instruments, dayCounter, new List<Handle<Quote>>(), new List<Date>(), 1.0e-12) { } 
    8282        //public InterpolatedYieldCurve(int settlementDays, Calendar calendar, List<BootstrapHelper<YieldTermStructure>> instruments, 
    8383        //                              DayCounter dayCounter, Quote turnOfYearEffect) : 
    8484        //    this(settlementDays, calendar, instruments, dayCounter, turnOfYearEffect, 1.0e-12) { } 
    8585        public PiecewiseYieldCurve(int settlementDays, Calendar calendar, List<BootstrapHelper<YieldTermStructure>> instruments, 
    86                                       DayCounter dayCounter, Handle<Quote> turnOfYearEffect, double accuracy) 
    87             : base(settlementDays, calendar, instruments, dayCounter, turnOfYearEffect, accuracy) { } 
     86                                      DayCounter dayCounter, List<Handle<Quote>> jumps, List<Date> jumpDates, double accuracy) 
     87            : base(settlementDays, calendar, instruments, dayCounter, jumps, jumpDates, accuracy) { } 
    8888    } 
    8989 
     
    9898        public List<double> times_ = new List<double>(); 
    9999 
    100         protected Handle<Quote> turnOfYearEffect_; 
     100        private List<Handle<Quote>> jumps_; 
     101        private List<Date> jumpDates_; 
     102        private List<double> jumpTimes_; 
     103        private int nJumps_; 
     104 
    101105        public double accuracy_; 
    102106        protected Date latestReference_; 
    103         protected double turnOfYear_; 
    104107 
    105108        public Interpolator interpolator_; 
     
    146149        #region Constructors 
    147150        public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, DayCounter dayCounter) 
    148             : this(referenceDate, instruments, dayCounter, new Handle<Quote>(), 1.0e-12, new Interpolator(), new BootStrap()) { } 
    149         public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 
    150                                    DayCounter dayCounter, Handle<Quote> turnOfYearEffect) 
    151             : this(referenceDate, instruments, dayCounter, turnOfYearEffect, 1.0e-12, new Interpolator(), new BootStrap()) { } 
    152         public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 
    153                                    DayCounter dayCounter, Handle<Quote> turnOfYearEffect, double accuracy) 
    154             : this(referenceDate, instruments, dayCounter, turnOfYearEffect, accuracy, new Interpolator(), new BootStrap()) { } 
    155         public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 
    156                                    DayCounter dayCounter, Handle<Quote> turnOfYearEffect, double accuracy, Interpolator i) 
    157             : this(referenceDate, instruments, dayCounter, turnOfYearEffect, accuracy, i, new BootStrap()) { } 
    158         public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 
    159                                    DayCounter dayCounter, Handle<Quote> turnOfYearEffect, double accuracy, 
    160                                    Interpolator i, BootStrap bootstrap) 
     151            : this(referenceDate, instruments, dayCounter, new List<Handle<Quote>>(), new List<Date>(),  
     152                   1.0e-12, new Interpolator(), new BootStrap()) { } 
     153        public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 
     154                                   DayCounter dayCounter, List<Handle<Quote>> jumps, List<Date> jumpDates) 
     155            : this(referenceDate, instruments, dayCounter, jumps, jumpDates, 1.0e-12, new Interpolator(), new BootStrap()) { } 
     156        public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 
     157                                   DayCounter dayCounter, List<Handle<Quote>> jumps, 
     158                                   List<Date> jumpDates, double accuracy) 
     159            : this(referenceDate, instruments, dayCounter, jumps, jumpDates, accuracy, new Interpolator(), new BootStrap()) { } 
     160        public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 
     161                                   DayCounter dayCounter, List<Handle<Quote>> jumps, 
     162                                   List<Date> jumpDates, double accuracy, Interpolator i) 
     163            : this(referenceDate, instruments, dayCounter, jumps, jumpDates, accuracy, i, new BootStrap()) { } 
     164        public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 
     165                                   DayCounter dayCounter, List<Handle<Quote>> jumps, List<Date> jumpDates, 
     166                                   double accuracy, Interpolator i, BootStrap bootstrap) 
    161167            : base(referenceDate, new Calendar(), dayCounter) { 
    162168            instruments_ = instruments; 
    163             turnOfYearEffect_ = turnOfYearEffect; 
     169 
     170            jumps_ = jumps; 
     171            jumpDates_ = jumpDates; 
     172            jumpTimes_ = new InitializedList<double>(jumpDates.Count); 
     173            nJumps_ = jumps_.Count; 
     174 
    164175            accuracy_ = accuracy; 
    165176            interpolator_ = i; 
    166177            bootstrap_ = bootstrap; 
    167178 
    168             setTurnOfYear(); 
    169             turnOfYearEffect_.registerWith(update); 
     179            setJumps(); 
     180            jumps.ForEach(x => x.registerWith(update)); 
     181 
    170182            bootstrap_.setup<Traits, Interpolator, BootStrap>(this); 
    171183        } 
     
    177189        //                              DayCounter dayCounter, Quote turnOfYearEffect) : 
    178190        //    this(settlementDays, calendar, instruments, dayCounter, turnOfYearEffect, 1.0e-12) { } 
    179         public PiecewiseYieldCurve(int settlementDays, Calendar calendar, List<BootstrapHelper<YieldTermStructure>> instruments, 
    180                                    DayCounter dayCounter, Handle<Quote> turnOfYearEffect, double accuracy) 
    181             : this(settlementDays, calendar, instruments, dayCounter, turnOfYearEffect, accuracy,  
     191                                   //List<Handle<Quote>> jumps = std::vector<Handle<Quote> >(), 
     192                                   //List<Date> jumpDates = std::vector<Date>(), 
     193        public PiecewiseYieldCurve(int settlementDays, Calendar calendar, List<BootstrapHelper<YieldTermStructure>> instruments, 
     194                                   DayCounter dayCounter, List<Handle<Quote>> jumps, List<Date> jumpDates, double accuracy) 
     195            : this(settlementDays, calendar, instruments, dayCounter, jumps, jumpDates, accuracy,  
    182196                   new Interpolator(), new BootStrap()) { } 
    183197        public PiecewiseYieldCurve(int settlementDays, Calendar calendar, List<BootstrapHelper<YieldTermStructure>> instruments, 
    184                                    DayCounter dayCounter, Handle<Quote> turnOfYearEffect, double accuracy, 
     198                                   DayCounter dayCounter, List<Handle<Quote>> jumps, List<Date> jumpDates, double accuracy, 
    185199                                   Interpolator i, BootStrap bootstrap) 
    186200            : base(settlementDays, calendar, dayCounter) { 
    187201            instruments_ = instruments; 
    188             turnOfYearEffect_ = turnOfYearEffect; 
     202 
     203            jumps_ = jumps; 
     204            jumpDates_ = jumpDates; 
     205            jumpTimes_ = new InitializedList<double>(jumpDates.Count); 
     206            nJumps_ = jumps_.Count; 
     207 
    189208            accuracy_ = accuracy; 
    190209            interpolator_ = i; 
    191210            bootstrap_ = bootstrap; 
    192211 
    193             setTurnOfYear(); 
    194             turnOfYearEffect_.registerWith(update); 
     212            setJumps(); 
     213            jumps.ForEach(x => x.registerWith(update)); 
     214 
    195215            bootstrap_.setup<Traits, Interpolator, BootStrap>(this); 
    196216        }  
     
    216236            // LazyObject::update();        // we do it in the TermStructure  
    217237            if (referenceDate() != latestReference_) 
    218                 setTurnOfYear(); 
    219         } 
    220  
    221         private void setTurnOfYear() { 
     238                setJumps(); 
     239        } 
     240 
     241        private void setJumps() { 
    222242            Date refDate = referenceDate(); 
    223             Date turnOfYear = new Date(31, Month.December, refDate.Year); 
    224             turnOfYear_ = timeFromReference(turnOfYear); 
     243 
     244            if (jumpDates_.Count != 0 && jumps_.Count != 0) { // turn of year dates 
     245                jumpDates_ = new InitializedList<Date>(nJumps_); 
     246                jumpTimes_ = new InitializedList<double>(nJumps_); 
     247                for (int i=0; i<nJumps_; ++i) 
     248                    jumpDates_[i] = new Date(31, Month.December, refDate.Year + i); 
     249            } else { // fixed dats 
     250                if (!(jumpDates_.Count == nJumps_)) 
     251                    throw new ApplicationException("mismatch between number of jumps (" + nJumps_ + 
     252                           ") and jump dates (" + jumpDates_.Count + ")"); 
     253            } 
     254            for (int i=0; i<nJumps_; ++i) 
     255                jumpTimes_[i] = timeFromReference(jumpDates_[i]); 
    225256            latestReference_ = refDate; 
     257        } 
     258 
     259        public List<Date> jumpDates() { 
     260            calculate(); 
     261            return jumpDates_; 
     262        } 
     263 
     264        public List<double> jumpTimes() { 
     265            calculate(); 
     266            return jumpTimes_; 
    226267        } 
    227268 
  • trunk/QLNet/Test2008/T_Piecewiseyieldcurve.cs

    r207 r209  
    502502 
    503503            vars.termStructure = new PiecewiseYieldCurve<T, I, B>(vars.settlement, vars.instruments, 
    504                                     new Actual360(), new Handle<Quote>(), 1.0e-12, interpolator); 
     504                                    new Actual360(), new List<Handle<Quote>>(), new List<Date>(), 1.0e-12, interpolator); 
    505505 
    506506            RelinkableHandle<YieldTermStructure> curveHandle = new RelinkableHandle<YieldTermStructure>(); 
     
    547547            // check bonds 
    548548            vars.termStructure = new PiecewiseYieldCurve<T, I, B>(vars.settlement, vars.bondHelpers, 
    549                                      new Actual360(), new Handle<Quote>(), 1.0e-12, interpolator); 
     549                                     new Actual360(), new List<Handle<Quote>>(), new List<Date>(), 1.0e-12, interpolator); 
    550550            curveHandle.linkTo(vars.termStructure); 
    551551 
     
    574574            // check FRA 
    575575            vars.termStructure = new PiecewiseYieldCurve<T, I, B>(vars.settlement, vars.fraHelpers, 
    576                                         new Actual360(), new Handle<Quote>(), 1.0e-12, interpolator); 
     576                                        new Actual360(), new List<Handle<Quote>>(), new List<Date>(), 1.0e-12, interpolator); 
    577577            curveHandle.linkTo(vars.termStructure); 
    578578 
     
    644644 
    645645            vars.termStructure = new PiecewiseYieldCurve<T, I, B>(vars.settlement, vars.bmaHelpers, 
    646                                      new Actual360(), new Handle<Quote>(), 1.0e-12, interpolator); 
     646                                     new Actual360(), new List<Handle<Quote>>(), new List<Date>(), 1.0e-12, interpolator); 
    647647 
    648648            RelinkableHandle<YieldTermStructure> curveHandle = new RelinkableHandle<YieldTermStructure>();