Assembla home | Assembla project page
 

Changeset 214

Show
Ignore:
Timestamp:
06/18/08 05:53:32 (3 months ago)
Author:
snovik
Message:

New: ForEach? extension method with iterator. This can simplify lots of code.
Changes: Some code has been adjusted to .net collection functionality (e.g. ForEach? with iterator)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/QLNet/QLNet/Cashflows/Coupon.cs

    r62 r214  
    2222using QLNet; 
    2323 
    24 namespace QLNet 
    25 
     24namespace QLNet { 
    2625    //! %coupon accruing over a fixed period 
    2726    //! This class implements part of the CashFlow interface but it is 
    2827    //  still abstract and provides derived classes with methods for accrual period calculations. 
    29     public abstract class Coupon : CashFlow 
    30     { 
     28    public abstract class Coupon : CashFlow { 
    3129        protected double nominal_; 
    3230        protected Date paymentDate_, accrualStartDate_, accrualEndDate_, refPeriodStart_, refPeriodEnd_; 
     
    5452        public Coupon(double nominal, Date paymentDate, Date accrualStartDate, Date accrualEndDate, Date refPeriodStart) : 
    5553            this(nominal, paymentDate, accrualStartDate, accrualEndDate, refPeriodStart, null) { } 
    56         public Coupon(double nominal, Date paymentDate, Date accrualStartDate, Date accrualEndDate, Date refPeriodStart, Date refPeriodEnd) 
    57         { 
     54        public Coupon(double nominal, Date paymentDate, Date accrualStartDate, Date accrualEndDate, Date refPeriodStart, Date refPeriodEnd) { 
    5855            nominal_ = nominal; 
    5956            paymentDate_ = paymentDate; 
     
    6764        } 
    6865 
    69         public double accrualPeriod() 
    70         {                          //! accrual period as fraction of year 
     66        //! accrual period as fraction of year 
     67        public double accrualPeriod() { 
    7168            return dayCounter().yearFraction(accrualStartDate_, accrualEndDate_, refPeriodStart_, refPeriodEnd_); 
    7269        } 
    73         public int accrualDays 
    74         {                                //! accrual period in days 
    75             get { return dayCounter().dayCount(accrualStartDate_, accrualEndDate_); } 
    76         } 
    77  
    78         // recheck 
    79         //void Coupon::accept(AcyclicVisitor& v) { 
    80         //    Visitor<Coupon>* v1 = dynamic_cast<Visitor<Coupon>*>(&v); 
    81         //    if (v1 != 0) 
    82         //        v1->visit(*this); 
    83         //    else 
    84         //        CashFlow::accept(v); 
    85         //} 
     70        //! accrual period in days 
     71        public int accrualDays() { return dayCounter().dayCount(accrualStartDate_, accrualEndDate_); } 
    8672    } 
    8773} 
  • trunk/QLNet/QLNet/Cashflows/averagebmacoupon.cs

    r62 r214  
    6767 
    6868        //! fixings of the underlying index to be averaged 
    69         public List<double> indexFixings() { 
    70             List<double> fixings = new List<double>(); 
    71             for (int i=0; i<fixings.Count; ++i) 
    72                 fixings.Add(index_.fixing(fixingSchedule_.date(i))); 
    73             return fixings; 
    74         } 
     69        public List<double> indexFixings() { return fixingSchedule_.dates().Select(d => index_.fixing(d)).ToList(); } 
    7570 
    7671        public override double convexityAdjustment() { 
  • trunk/QLNet/QLNet/Termstructures/Iterativebootstrap.cs

    r211 r214  
    5656 
    5757            // check that there is no instruments with invalid quote 
    58             i = ts_.instruments_.FindIndex(x => !x.quoteIsValid()); 
    59             if (i != -1) 
     58            if ((i = ts_.instruments_.FindIndex(x => !x.quoteIsValid())) != -1) 
    6059                throw new ArgumentException("instrument " + i + " (maturity: " + ts_.instruments_[i].latestDate() + 
    6160                       ") has an invalid quote"); 
  • trunk/QLNet/QLNet/Termstructures/Yield/PiecewiseYieldCurve.cs

    r211 r214  
    2323 
    2424namespace QLNet { 
    25     // this is the abstract class to give access to all properties and methods of PiecewiseYieldCurve and avoiding generics 
     25    // this is an abstract class to give access to all properties and methods of PiecewiseYieldCurve and avoiding generics 
    2626    public abstract class IPiecewiseYieldCurve : YieldTermStructure, ITraits { 
    2727        #region Properties 
     
    7070 
    7171 
    72     public class PiecewiseYieldCurve<Traits, Interpolator> 
    73         : PiecewiseYieldCurve<Traits, Interpolator, IterativeBootstrap> 
     72    public class PiecewiseYieldCurve<Traits, Interpolator> : PiecewiseYieldCurve<Traits, Interpolator, IterativeBootstrap> 
    7473        where Traits : ITraits, new() 
    7574        where Interpolator : IInterpolationFactory, new() { 
     
    9998 
    10099 
    101     public class PiecewiseYieldCurve<Traits, Interpolator, BootStrap> : IPiecewiseYieldCurve, ITraits 
     100    public class PiecewiseYieldCurve<Traits, Interpolator, BootStrap> : IPiecewiseYieldCurve 
    102101        where Traits : ITraits, new() 
    103102        where Interpolator : IInterpolationFactory, new() 
     
    230229            calculate(); 
    231230            Dictionary<Date, double> results = new Dictionary<Date, double>(); 
    232             for (int i = 0; i < dates_.Count; ++i) 
    233                 results.Add(dates_[i], data_[i]); 
     231            dates_.ForEach((i, x) => results.Add(x, data_[i])); 
    234232            return results; 
    235233        } 
     
    248246            if (jumpDates_.Count != 0 && jumps_.Count != 0) { // turn of year dates 
    249247                jumpDates_ = new InitializedList<Date>(nJumps_); 
     248                jumpDates_.ForEach((i, d) => jumpDates_[i] = new Date(31, Month.December, refDate.Year + i)); 
     249 
    250250                jumpTimes_ = new InitializedList<double>(nJumps_); 
    251                 for (int i=0; i<nJumps_; ++i) 
    252                     jumpDates_[i] = new Date(31, Month.December, refDate.Year + i); 
    253251            } else { // fixed dats 
    254252                if (!(jumpDates_.Count == nJumps_)) 
  • trunk/QLNet/QLNet/Termstructures/localbootstrap.cs

    r211 r214  
    4444 
    4545        public override double value(Vector x) { 
    46             int i = initialIndex_; 
    47             x.ForEach(z => { 
    48                 curve_.updateGuess(curve_.data_, z, i); 
    49                 ++i; 
    50             }); 
     46            x.ForEach((j, v) => curve_.updateGuess(curve_.data_, v, j + initialIndex_)); 
    5147 
    5248            curve_.interpolation_.update(); 
    5349 
    54             double penalty = 0.0; 
    55             for(int j = start_; j < end_; j++) { 
    56                 double quoteError = rateHelpers_[j].quoteError(); 
    57                 penalty += Math.Abs(quoteError); 
    58             } 
     50            double penalty = rateHelpers_.GetRange(start_, localisation_) 
     51                                         .Aggregate(0.0, (acc, v) => Math.Abs(v.quoteError())); 
    5952            return penalty; 
    6053        } 
    6154 
    6255        public override Vector values(Vector x) { 
    63             int i = initialIndex_; 
    64             x.ForEach(z => {  
    65                 curve_.updateGuess(curve_.data_, z, i); 
    66                 ++i;  
    67             }); 
     56            x.ForEach((j, v) => curve_.updateGuess(curve_.data_, v, j + initialIndex_)); 
    6857 
    6958            curve_.interpolation_.update(); 
    7059 
    71             Vector penalties = new Vector(localisation_); 
    72             var instIt = start_; 
    73             int penIt = 0; 
    74             while (instIt != end_) { 
    75                 double quoteError = rateHelpers_[instIt].quoteError(); 
    76                 penalties[penIt] = Math.Abs(quoteError); 
    77                 ++instIt; 
    78                 ++penIt; 
    79             } 
    80             return penalties; 
     60            var penalties = rateHelpers_.GetRange(start_, localisation_).Select(c => Math.Abs(c.quoteError())).ToList(); 
     61            return new Vector(penalties); 
    8162        } 
    8263    } 
     
    133114 
    134115            validCurve_ = false; 
    135             int nInsts = ts_.instruments_.Count
     116            int nInsts = ts_.instruments_.Count, i
    136117 
    137118            // ensure rate helpers are sorted 
     
    139120 
    140121            // check that there is no instruments with the same maturity 
    141             for (int i = 1; i < nInsts; ++i) { 
     122            for (i = 1; i < nInsts; ++i) { 
    142123                Date m1 = ts_.instruments_[i - 1].latestDate(), 
    143124                     m2 = ts_.instruments_[i].latestDate(); 
     
    146127 
    147128            // check that there is no instruments with invalid quote 
    148             for (int i = 0; i < nInsts; ++i) 
    149                 if (!ts_.instruments_[i].quoteIsValid()) 
    150                     throw new ArgumentException("instrument " + i + " (maturity: " + ts_.instruments_[i].latestDate() + 
    151                            ") has an invalid quote"); 
     129            if ((i = ts_.instruments_.FindIndex(x => !x.quoteIsValid())) != -1) 
     130                throw new ArgumentException("instrument " + i + " (maturity: " + ts_.instruments_[i].latestDate() + 
     131                       ") has an invalid quote"); 
    152132 
    153133            // setup instruments and register with them 
    154             ts_.instruments_.ForEach(i => i.setTermStructure(ts_)); 
     134            ts_.instruments_.ForEach(j => j.setTermStructure(ts_)); 
    155135 
    156136            // set initial guess only if the current curve cannot be used as guess 
     
    168148            ts_.dates_[0] = ts_.initialDate(ts_); 
    169149            ts_.times_[0] = ts_.timeFromReference(ts_.dates_[0]); 
    170             for (int i = 0; i < nInsts; ++i) { 
     150            for (i = 0; i < nInsts; ++i) { 
    171151                ts_.dates_[i + 1] = ts_.instruments_[i].latestDate(); 
    172152                ts_.times_[i + 1] = ts_.timeFromReference(ts_.dates_[i + 1]); 
  • trunk/QLNet/QLNet/Time/Schedule.cs

    r62 r214  
    5353        private List<bool> isRegular_ = new List<bool>(); 
    5454 
    55         public List<Date> dates() { 
    56             List<Date> result = new List<Date>(); 
    57             foreach(Date d in adjustedDates_) 
    58                 result.Add(d); 
    59             return result; 
    60         } 
     55        public List<Date> dates() { return new List<Date>(adjustedDates_); } 
    6156        public int Count { get { return adjustedDates_.Count; } } 
    6257 
     
    8782        #endregion 
    8883 
    89                // constructors 
     84        #region Constructors 
    9085        public Schedule() { } 
    91                public Schedule(List<Date> dates__, Calendar calendar__, BusinessDayConvention convention__) { 
    92                        fullInterface_ = false; 
    93                    tenor_ = new Period(); 
    94                        calendar_ = calendar__; 
    95                    convention_ = convention__; 
    96                    terminationDateConvention_ = convention__; 
    97                    rule_ = DateGeneration.Rule.Forward; 
    98                        endOfMonth_ = false; 
     86        public Schedule(List<Date> dates__, Calendar calendar__, BusinessDayConvention convention__) { 
     87            fullInterface_ = false; 
     88            tenor_ = new Period(); 
     89            calendar_ = calendar__; 
     90            convention_ = convention__; 
     91            terminationDateConvention_ = convention__; 
     92            rule_ = DateGeneration.Rule.Forward; 
     93            endOfMonth_ = false; 
    9994            adjustedDates_ = dates__; 
    100                
     95       
    10196        public Schedule(Date effectiveDate__, Date terminationDate__, Period tenor__, Calendar calendar__, 
    10297                 BusinessDayConvention convention__, BusinessDayConvention terminationDateConvention__, 
     
    10499            : this(effectiveDate__, terminationDate__, tenor__, calendar__, 
    105100                 convention__, terminationDateConvention__, rule__, endOfMonth__, null, null) { } 
    106                public Schedule(Date effectiveDate__, Date terminationDate__, Period tenor__, Calendar calendar__, 
     101        public Schedule(Date effectiveDate__, Date terminationDate__, Period tenor__, Calendar calendar__, 
    107102                 BusinessDayConvention convention__, BusinessDayConvention terminationDateConvention__, 
    108103                 DateGeneration.Rule rule__, bool endOfMonth__, 
    109104                 Date firstDate__, Date nextToLastDate__) { 
    110                        // first save the properties 
    111                        fullInterface_ = true; 
    112                    tenor_ = tenor__; 
    113                        calendar_ = calendar__; 
    114                    convention_ = convention__; 
    115                    terminationDateConvention_ = terminationDateConvention__; 
    116                    rule_ = rule__; 
    117                        endOfMonth_ = endOfMonth__; 
    118                    firstDate_ = firstDate__; 
    119                        nextToLastDate_ = nextToLastDate__; 
    120                  
    121                        // sanity checks 
    122                        if (effectiveDate__ == null) throw new ArgumentException("Null effective date"); 
    123                        if (terminationDate__ == null) throw new ArgumentException("Null termination  date"); 
    124                        if (effectiveDate__ >= terminationDate__) throw new ArgumentException("Effective date (" + effectiveDate__ + 
    125                           ") is later than or equal to termination date (" + terminationDate__ + ")"); 
     105            // first save the properties 
     106            fullInterface_ = true; 
     107            tenor_ = tenor__; 
     108            calendar_ = calendar__; 
     109            convention_ = convention__; 
     110            terminationDateConvention_ = terminationDateConvention__; 
     111            rule_ = rule__; 
     112            endOfMonth_ = endOfMonth__; 
     113            firstDate_ = firstDate__; 
     114            nextToLastDate_ = nextToLastDate__; 
     115 
     116            // sanity checks 
     117            if (effectiveDate__ == null) throw new ArgumentException("Null effective date"); 
     118            if (terminationDate__ == null) throw new ArgumentException("Null termination  date"); 
     119            if (effectiveDate__ >= terminationDate__) throw new ArgumentException("Effective date (" + effectiveDate__ + 
     120                       ") is later than or equal to termination date (" + terminationDate__ + ")"); 
    126121 
    127122            if (tenor_.units() == 0) 
    128                    rule_ = DateGeneration.Rule.Zero; 
     123                rule_ = DateGeneration.Rule.Zero; 
    129124            else if (tenor_.units() < 0) 
    130                    throw new ArgumentException("Non positive tenor (" + tenor_ + ") is not allowed"); 
    131  
    132                        // though firstDate_ and nextToLastDate are always provided 
    133                if (firstDate_ != null) { 
    134                    switch (rule_) { 
    135                                        case DateGeneration.Rule.Backward: 
    136                                        case DateGeneration.Rule.Forward: 
    137                                                if (!(firstDate_ > effectiveDate__ && firstDate_ < terminationDate__)) 
    138                                                        throw new ArgumentException("First date (" + firstDate_ + ") is out of range [effective date (" + effectiveDate__ 
    139                                                                                                                + "), termination date (" + terminationDate__ + ")]"); 
    140                                                break; 
    141                                        case DateGeneration.Rule.Zero: 
    142                                        case DateGeneration.Rule.ThirdWednesday: 
    143                                                throw new ArgumentException("First date is incompatible with " + rule_ + " date generation rule"); 
    144                                        default: 
    145                                                throw Error.UnknownDateGenerationRule(rule_); 
    146                    } 
    147                } 
     125                throw new ArgumentException("Non positive tenor (" + tenor_ + ") is not allowed"); 
     126 
     127            // though firstDate_ and nextToLastDate are always provided 
     128            if (firstDate_ != null) { 
     129                switch (rule_) { 
     130                    case DateGeneration.Rule.Backward: 
     131                    case DateGeneration.Rule.Forward: 
     132                        if (!(firstDate_ > effectiveDate__ && firstDate_ < terminationDate__)) 
     133                            throw new ArgumentException("First date (" + firstDate_ + ") is out of range [effective date (" + effectiveDate__ 
     134                                                        + "), termination date (" + terminationDate__ + ")]"); 
     135                        break; 
     136                    case DateGeneration.Rule.Zero: 
     137                    case DateGeneration.Rule.ThirdWednesday: 
     138                        throw new ArgumentException("First date is incompatible with " + rule_ + " date generation rule"); 
     139                    default: 
     140                        throw Error.UnknownDateGenerationRule(rule_); 
     141                } 
     142            } 
    148143 
    149144            if (nextToLastDate_ != null) { 
    150                    switch (rule_) { 
    151                                        case DateGeneration.Rule.Backward: 
    152                                        case DateGeneration.Rule.Forward: 
    153                                                if (!(nextToLastDate_ > effectiveDate__ && nextToLastDate_ < terminationDate__)) 
    154                                throw new ArgumentException("Next to last date (" + nextToLastDate_ + ") out of range [effective date (" + effectiveDate__ 
    155                                   + "), termination date (" + terminationDate__ + ")]"); 
    156                                                break; 
    157                                        case DateGeneration.Rule.Zero: 
    158                                        case DateGeneration.Rule.ThirdWednesday: 
    159                                                throw new ArgumentException("Next to last date incompatible with " + rule_ + " date generation rule"); 
    160                                        default: 
    161                                                throw Error.UnknownDateGenerationRule(rule_); 
    162                    } 
    163                } 
    164  
    165                // calendar needed for endOfMonth adjustment 
    166                Calendar nullCalendar = new NullCalendar(); 
    167                int periods = 1; 
    168                Date seed, exitDate; 
     145                switch (rule_) { 
     146                    case DateGeneration.Rule.Backward: 
     147                    case DateGeneration.Rule.Forward: 
     148                        if (!(nextToLastDate_ > effectiveDate__ && nextToLastDate_ < terminationDate__)) 
     149                            throw new ArgumentException("Next to last date (" + nextToLastDate_ + ") out of range [effective date (" + effectiveDate__ 
     150                               + "), termination date (" + terminationDate__ + ")]"); 
     151                        break; 
     152                    case DateGeneration.Rule.Zero: 
     153                    case DateGeneration.Rule.ThirdWednesday: 
     154                        throw new ArgumentException("Next to last date incompatible with " + rule_ + " date generation rule"); 
     155                    default: 
     156                        throw Error.UnknownDateGenerationRule(rule_); 
     157                } 
     158            } 
     159 
     160            // calendar needed for endOfMonth adjustment 
     161            Calendar nullCalendar = new NullCalendar(); 
     162            int periods = 1; 
     163            Date seed, exitDate; 
    169164            switch (rule_) { 
    170                                case DateGeneration.Rule.Zero: 
    171                            tenor_ = new Period(0, TimeUnit.Days); 
     165                case DateGeneration.Rule.Zero: 
     166                    tenor_ = new Period(0, TimeUnit.Days); 
    172167                    originalDates_.Add(effectiveDate__); 
    173168                    originalDates_.Add(terminationDate__); 
     
    175170                    break; 
    176171 
    177                                case DateGeneration.Rule.Backward: 
     172                case DateGeneration.Rule.Backward: 
    178173                    originalDates_.Add(terminationDate__); 
    179174                    seed = terminationDate__; 
    180                            if (nextToLastDate_ != null) { 
     175                    if (nextToLastDate_ != null) { 
    181176                        originalDates_.Insert(0, nextToLastDate_); 
    182177                        Date temp = nullCalendar.advance(seed, -periods * tenor_, convention_, endOfMonth_); 
    183178                        isRegular_.Insert(0, temp == nextToLastDate_); 
    184179                        seed = nextToLastDate_; 
    185                            } 
    186                            exitDate = effectiveDate__; 
     180                    } 
     181                    exitDate = effectiveDate__; 
    187182                    if (firstDate_ != null) 
    188                                exitDate = firstDate_; 
    189                            while (true) { 
    190                                Date temp = nullCalendar.advance(seed, -periods*tenor_, convention_, endOfMonth_); 
    191                                if (temp < exitDate) 
    192                                    break; 
    193                                else { 
     183                        exitDate = firstDate_; 
     184                    while (true) { 
     185                        Date temp = nullCalendar.advance(seed, -periods * tenor_, convention_, endOfMonth_); 
     186                        if (temp < exitDate) 
     187                            break; 
     188                        else { 
    194189                            originalDates_.Insert(0, temp); 
    195190                            isRegular_.Insert(0, true); 
    196191                            ++periods; 
    197                                } 
    198                            } 
    199                            if (endOfMonth_ && calendar_.isEndOfMonth(seed)) 
    200                                convention_ = BusinessDayConvention.Preceding; 
     192                        } 
     193                    } 
     194                    if (endOfMonth_ && calendar_.isEndOfMonth(seed)) 
     195                        convention_ = BusinessDayConvention.Preceding; 
    201196                    if (calendar_.adjust(originalDates_[0], convention_) != calendar_.adjust(effectiveDate__, convention_)) { 
    202197                        originalDates_.Insert(0, effectiveDate__); 
    203198                        isRegular_.Insert(0, false); 
    204199                    } 
    205                            break; 
     200                    break; 
    206201 
    207202                case DateGeneration.Rule.ThirdWednesday: 
     
    209204                    goto case DateGeneration.Rule.Forward;                      // fall through 
    210205 
    211                                case DateGeneration.Rule.Forward: 
     206                case DateGeneration.Rule.Forward: 
    212207                    originalDates_.Add(effectiveDate__); 
    213208                    seed = effectiveDate__; 
    214                            if (firstDate_ != null) { 
     209                    if (firstDate_ != null) { 
    215210                        originalDates_.Add(firstDate_); 
    216211                        Date temp = nullCalendar.advance(seed, periods * tenor_, convention_, endOfMonth_); 
    217212                        isRegular_.Add(temp == firstDate_); 
    218213                        seed = firstDate_; 
    219                            } 
    220                            exitDate = terminationDate__; 
    221                            if (nextToLastDate_ != null) 
    222                                exitDate = nextToLastDate_; 
    223                            while (true) { 
    224                                Date temp = nullCalendar.advance(seed, periods*tenor_, convention_, endOfMonth_); 
    225                                if (temp > exitDate) 
    226                                    break; 
    227                                else { 
     214                    } 
     215                    exitDate = terminationDate__; 
     216                    if (nextToLastDate_ != null) 
     217                        exitDate = nextToLastDate_; 
     218                    while (true) { 
     219                        Date temp = nullCalendar.advance(seed, periods * tenor_, convention_, endOfMonth_); 
     220                        if (temp > exitDate) 
     221                            break; 
     222                        else { 
    228223                            originalDates_.Add(temp); 
    229224                            isRegular_.Add(true); 
    230225                            ++periods; 
    231                                } 
    232                            } 
    233                            if (endOfMonth_ && calendar_.isEndOfMonth(seed)) 
    234                                convention_ = BusinessDayConvention.Preceding; 
     226                        } 
     227                    } 
     228                    if (endOfMonth_ && calendar_.isEndOfMonth(seed)) 
     229                        convention_ = BusinessDayConvention.Preceding; 
    235230                    if (calendar_.adjust(originalDates_.Last(), terminationDateConvention_) != calendar_.adjust(terminationDate__, terminationDateConvention_)) { 
    236231                        originalDates_.Add(terminationDate__); 
    237232                        isRegular_.Add(false); 
    238233                    } 
    239                            break; 
    240  
    241                                default: 
    242                                        throw Error.UnknownDateGenerationRule(rule_); 
    243                } 
     234                    break; 
     235 
     236                default: 
     237                    throw Error.UnknownDateGenerationRule(rule_); 
     238            } 
    244239 
    245240            // adjustments to holidays, etc. 
     
    248243                    originalDates_[i] = Date.nthWeekday(3, DayOfWeek.Wednesday, originalDates_[i].Month, originalDates_[i].Year); 
    249244 
    250             foreach(Date d in originalDates_) 
     245            foreach (Date d in originalDates_) 
    251246                adjustedDates_.Add(calendar_.adjust(d, convention_)); 
    252247 
    253                // termination date is NOT adjusted as per ISDA specifications unless otherwise specified in the confirmation of the deal 
    254                if (terminationDateConvention_ != BusinessDayConvention.Unadjusted) 
     248            // termination date is NOT adjusted as per ISDA specifications unless otherwise specified in the confirmation of the deal 
     249            if (terminationDateConvention_ != BusinessDayConvention.Unadjusted) 
    255250                adjustedDates_[adjustedDates_.Count - 1] = calendar_.adjust(originalDates_.Last(), terminationDateConvention_); 
    256                 } 
     251        }  
     252        #endregion 
    257253 
    258254                private void CheckInterface() { if (!fullInterface_) throw new ArgumentException("full interface not available"); } 
    259255                 
     256        // returns the period of the Schedule during which Date d happens 
    260257        public int periodOfDate(Date d) { 
    261258            int result = adjustedDates_.BinarySearch(d); 
     
    264261            return result; 
    265262        } 
     263 
     264        //// looks up the date of the previous period point relative to Date d 
     265        //public Date previousDate(Date d) { 
     266        //    int i = periodOfDate(d); 
     267        //    return this[i - 1]; 
     268        //} 
     269 
     270        //// looks up the date of the next period point relative to Date d 
     271        //public Date nextDate(Date d) { 
     272        //    int i = periodOfDate(d); 
     273        //    return this[i + 1]; 
     274        //} 
    266275 
    267276        // Iterator interface 
  • trunk/QLNet/QLNet/Utils.cs

    r204 r214  
    2323 
    2424namespace QLNet { 
     25    // here are extensions to IList to accomodate some QL functionality as well as have useful things for .net 
    2526    public static partial class Utils { 
     27        // equivalent of ForEach but with the index 
     28        public static void ForEach<T>(this IList<T> items, Action<int, T> action) { 
     29            if (items != null && action != null) 
     30                for (int idx = 0; idx < items.Count; idx++) 
     31                    action(idx, items[idx]); 
     32        } 
     33 
     34        // this is a version of element retrieval with some logic for default values 
    2635        public static T Get<T>(this List<T> v, int i) { return Get(v, i, default(T)); } 
    2736        public static T Get<T>(this List<T> v, int i, T defval) { 
     
    3039            else return v[i]; 
    3140        } 
     41    } 
    3242 
     43 
     44    public static partial class Utils { 
    3345        public static double effectiveFixedRate(List<double> spreads, List<double> caps, List<double> floors, int i) { 
    3446            double result = Get(spreads, i);