Assembla home | Assembla project page
 

Changeset 227

Show
Ignore:
Timestamp:
08/03/08 20:09:17 (4 months ago)
Author:
snovik
Message:

Fix: Index manager now works correctly with empty histories
Added: another ctor for FloatingRateBond?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/QLNet/QLNet/Indexes/Indexmanager.cs

    r203 r227  
    3434        //! returns whether historical fixings were stored for the index 
    3535        public bool hasHistory(string name) { 
    36             return data_.ContainsKey(name)
     36            return data_.ContainsKey(name) && data_[name].value().Count > 0
    3737        } 
    3838 
    3939        //! returns the (possibly empty) history of the index fixings 
    4040        public ObservableValue<TimeSeries<double>> getHistory(string name) { 
    41             if (!hasHistory(name)) 
    42                 data_.Add(name, new ObservableValue<TimeSeries<double>>()); 
     41            checkExists(name); 
    4342            return data_[name]; 
    4443        } 
     
    4645        //! stores the historical fixings of the index 
    4746        public void setHistory(string name, ObservableValue<TimeSeries<double>> history) { 
    48             if (!hasHistory(name)) 
    49                 data_.Add(name, null); 
     47            checkExists(name); 
    5048            data_[name].Assign(history); 
    5149        } 
    5250 
    53         //! observer notifying of changes in the index fixings 
    54         public ObservableValue<TimeSeries<double>> notifier(string name) { 
    55             if (!hasHistory(name)) 
    56                 data_.Add(name, new ObservableValue<TimeSeries<double>>()); 
    57             return data_[name]; 
    58         } 
     51        //! observer notifying of changes in the index fixings; in .NET it has the same logic as getHistory 
     52        public ObservableValue<TimeSeries<double>> notifier(string name) { return getHistory(name); } 
    5953 
    6054        //! returns all names of the indexes for which fixings were stored 
     
    7670                clearHistory(s); 
    7771        } 
     72 
     73        // checks whether index exists and adds it otherwise; for interal use only 
     74        private void checkExists(string name) { 
     75            if (!data_.ContainsKey(name)) 
     76                data_.Add(name, new ObservableValue<TimeSeries<double>>()); 
     77        } 
    7878    } 
    7979} 
  • trunk/QLNet/QLNet/Instruments/Bonds/FloatingRateBond.cs

    r225 r227  
    2626    //! \test calculations are tested by checking results against cached values. 
    2727    public class FloatingRateBond : Bond { 
    28         public FloatingRateBond(int settlementDays, double faceAmount, Schedule schedule, IborIndex index, DayCounter paymentDayCounter) 
     28        public FloatingRateBond(int settlementDays, double faceAmount, Schedule schedule, IborIndex index,  
     29                                DayCounter paymentDayCounter) 
    2930            : this(settlementDays, faceAmount, schedule, index, paymentDayCounter, BusinessDayConvention.Following, 
    30                    0, new List<double>() { 1 }, new List<double>() { 1 }, new List<double>(), new List<double>(), 
     31                   0, new List<double>() { 1 }, new List<double>() { 0 }, new List<double>(), new List<double>(), 
    3132                   false, 100, null) { } 
     33        public FloatingRateBond(int settlementDays, double faceAmount, Schedule schedule, IborIndex index, 
     34                                DayCounter paymentDayCounter, BusinessDayConvention paymentConvention, int fixingDays,  
     35                                List<double> gearings, List<double> spreads) 
     36            : this(settlementDays, faceAmount, schedule, index, paymentDayCounter, BusinessDayConvention.Following, 
     37                   fixingDays, gearings, spreads, new List<double>(), new List<double>(), false, 100, null) { } 
    3238        public FloatingRateBond(int settlementDays, double faceAmount, Schedule schedule, IborIndex index, DayCounter paymentDayCounter, 
    3339                                BusinessDayConvention paymentConvention, int fixingDays, List<double> gearings, List<double> spreads,