示例#1
0
文件: Seasonality.cs 项目: cub-/qlnet
      public override bool isConsistent(InflationTermStructure iTS) 
      {

         // If multi-year is the specification consistent with the term structure start date?
         // We do NOT test daily seasonality because this will, in general, never be consistent
         // given weekends, holidays, leap years, etc.
         if(this.frequency() == Frequency.Daily) return true;
         if( (int)this.frequency() == seasonalityFactors().Count ) return true;

         // how many years do you need to test?
         int nTest = seasonalityFactors().Count / (int)this.frequency();
         // ... relative to the start of the inflation curve
         KeyValuePair<Date,Date> lim = Utils.inflationPeriod(iTS.baseDate(), iTS.frequency());
         Date curveBaseDate = lim.Value;
         double factorBase = this.seasonalityFactor(curveBaseDate);

         double eps = 0.00001;
         for (int i = 1; i < nTest; i++) 
         {
            double factorAt = this.seasonalityFactor(curveBaseDate+new Period(i,TimeUnit.Years));
            if (Math.Abs(factorAt-factorBase)>=eps)
               throw new ApplicationException("seasonality is inconsistent with inflation " +
                        "term structure, factors " + factorBase + " and later factor " 
                        + factorAt + ", " + i + " years later from inflation curve "
                        + " with base date at " + curveBaseDate);
         }

         return true;

      }
示例#2
0
文件: Seasonality.cs 项目: cub-/qlnet
      //@}

      //! \name Seasonality interface
      //@{

      public override double correctZeroRate(Date d,double r,InflationTermStructure iTS)
      {
        KeyValuePair<Date,Date> lim = Utils.inflationPeriod(iTS.baseDate(), iTS.frequency());
        Date curveBaseDate = lim.Value;
        return seasonalityCorrection(r, d, iTS.dayCounter(), curveBaseDate, true);

      }
      public virtual bool isConsistent(InflationTermStructure iTS) 
      {

         // If multi-year is the specification consistent with the term structure start date?
         // We do NOT test daily seasonality because this will, in general, never be consistent
         // given weekends, holidays, leap years, etc.
         if(this.frequency() == Frequency.Daily) return true;
         if( (int)this.frequency() == seasonalityFactors().Count ) return true;

         // how many years do you need to test?
         int nTest = seasonalityFactors().Count / (int)this.frequency();
         // ... relative to the start of the inflation curve
         KeyValuePair<Date,Date> lim = Utils.inflationPeriod(iTS.baseDate(), iTS.frequency());
         Date curveBaseDate = lim.Value;
         double factorBase = this.seasonalityFactor(curveBaseDate);

         double eps = 0.00001;
         for (int i = 1; i < nTest; i++) 
         {
            double factorAt = this.seasonalityFactor(curveBaseDate+new Period(i,TimeUnit.Years));
            if (Math.Abs(factorAt-factorBase)>=eps)
               throw new ApplicationException("seasonality is inconsistent with inflation " +
                        "term structure, factors " + factorBase + " and later factor " 
                        + factorAt + ", " + i + " years later from inflation curve "
                        + " with base date at " + curveBaseDate);
         }

         return true;

      }
 public virtual double correctYoYRate(Date d, double r, InflationTermStructure iTS)
 {
    KeyValuePair<Date,Date> lim = Utils.inflationPeriod(iTS.baseDate(), iTS.frequency());
    Date curveBaseDate = lim.Value;
    return seasonalityCorrection(r, d, iTS.dayCounter(), curveBaseDate, false);
 }