//dtEffectiveDate is set somewhere else Date referenceDate = new Date((int)dtEffectiveDate.ToOADate()); NQuantLib.Settings.instance().setEvaluationDate( referenceDate ); RateHelperVector instruments = new RateHelperVector(); Calendar calendar = new TARGET(); DayCounter dayCounter = new Thirty360(NQuantLib.Thirty360.Convention.USA); // Swap Rates - Fixed Leg BusinessDayConvention fixedLegConvention = BusinessDayConvention.ModifiedFollowing; DayCounter fixedLegDayCounter = new Thirty360( NQuantLib.Thirty360.Convention.USA ); Frequency fixedLegFrequency = Frequency.Semiannual; // Swap Rates - XIBOR BusinessDayConvention xiborConvention = BusinessDayConvention.ModifiedFollowing; DayCounter xiborDayCounter = new Thirty360( Thirty360.Convention.USA ); Frequency xiborFrequency = Frequency.Quarterly; int settlementDays = 0;//settle is already accounted for above in setting effective date #region XIBOR index // Setup the XIBOR index. Xibor index = new Xibor( "dummy", new Period( xiborFrequency ), settlementDays, new Currency(), calendar, xiborConvention, xiborDayCounter ); #endregion //dfData holds the swap rates... for(int i=0;i<30;i++) { Quote quote = new SimpleQuote( Convert.ToDouble(dfData[i]/100) ); QuoteHandle quoteHandle = new QuoteHandle( quote ); RateHelper swapRateHelper = new SwapRateHelper( quoteHandle, new Period(i+1, NQuantLib.TimeUnit.Years ), 0, calendar, fixedLegFrequency, fixedLegConvention, fixedLegDayCounter, index ); instruments.Add(swapRateHelper); quoteHandle.Dispose(); quote.Dispose (); } decimal[] DiscountFactors = new decimal[30]; try { YieldTermStructure termStructure = new PiecewiseFlatForward( referenceDate, instruments, dayCounter ); for(int i=0;i<30;i++) { Date date = new Date((int)dtEffectiveDate.AddYears(i+1).ToOADate()); DiscountFactors[i] = Convert.ToDecimal(termStructure.discount(date,true)); } index.Dispose(); termStructure.Dispose(); instruments.Clear(); } catch { //and reset the discount factors to zero for(int i=0;i<30;i++) { DiscountFactors[i] = 0; } } ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |