IndexOutOfRangeException in PiecewiseFlatForward

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

IndexOutOfRangeException in PiecewiseFlatForward

Development-8

Hi,

 

I am new to QuantLib.

 

I have installed QuantLib.net on my WindowsXP machine.

 

I am getting an exception when I run the last line of the following C# code:

 

            static void Main(string[] args)

            {

                  IBusinessCalendar calendar = TARGET.Instance;

                  DateTime todaysDate = new DateTime(2001, 11, 1);

                  DateTime settlementDate = new DateTime(2001, 11, 3);

                 

                  // deposits

                  double d1wQuote=0.0382;

                  double d1mQuote=0.0372;

                  double d3mQuote=0.0363;

 

                  /*********************

                   ***  RATE HELPERS ***

                   *********************/

                  Actual360 depositDayCounter = Actual360.Instance;

                  int settlementDays = 2;

 

DepositRateHelper d1w = new DepositRateHelper(d1wQuote,1,                                                                          TimeUnit.Weeks,settlementDays, calendar, RollingConvention.ModifiedFollowing, depositDayCounter);

 

DepositRateHelper d1m = new DepositRateHelper(d1mQuote,1, TimeUnit.Months,settlementDays, calendar, RollingConvention.ModifiedFollowing, depositDayCounter);

 

DepositRateHelper d3m = new DepositRateHelper(d3mQuote,3, TimeUnit.Months,settlementDays, calendar, RollingConvention.ModifiedFollowing, depositDayCounter);

                                   

RateHelper[] depos = new RateHelper[3] {d1w, d1m, d3m};

                                   

TermStructure depoTermStruc = new (PiecewiseFlatForward(todaysDate, settlementDate,

                        depos,depositDayCounter,.0001);

                 

Console.WriteLine(depoTermStruc.Discount(30,true));

            }

 

When I inspect the objects during a debugging session I notice that the MaxTime and MaxDate fields of the TermStructure which I have created in the second-last line have System.IndexOutOfRangeException as a value.

 

Separately, are there any examples of QuantLib.net implementation as there are for regular QuantLib.

 

Thankyou in advance for your assistance,

 

Kind Regards,

Richard Howes

 

Reply | Threaded
Open this post in threaded view
|

RE: IndexOutOfRangeException in PiecewiseFlatForward

Jens Thiel-2
Nachricht
Hi Richard,
 
can you change the code in PiecewiseFlatForward.referenceNode to
 
    if (time > tmax)
        return segments>0 ? ~(segments) : 0;  // force interpolation above last segment
 
 
See the test cases (eg. QuantLib.Tests) for a few examples.
 
Jens.
 
-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Development
Sent: Monday, May 05, 2003 2:56 PM
To: [hidden email]
Subject: [Quantlib-users] IndexOutOfRangeException in PiecewiseFlatForward

Hi,

 

I am new to QuantLib.

 

I have installed QuantLib.net on my WindowsXP machine.

 

I am getting an exception when I run the last line of the following C# code:

 

            static void Main(string[] args)

            {

                  IBusinessCalendar calendar = TARGET.Instance;

                  DateTime todaysDate = new DateTime(2001, 11, 1);

                  DateTime settlementDate = new DateTime(2001, 11, 3);

                 

                  // deposits

                  double d1wQuote=0.0382;

                  double d1mQuote=0.0372;

                  double d3mQuote=0.0363;

 

                  /*********************

                   ***  RATE HELPERS ***

                   *********************/

                  Actual360 depositDayCounter = Actual360.Instance;

                  int settlementDays = 2;

 

DepositRateHelper d1w = new DepositRateHelper(d1wQuote,1,                                                                          TimeUnit.Weeks,settlementDays, calendar, RollingConvention.ModifiedFollowing, depositDayCounter);

 

DepositRateHelper d1m = new DepositRateHelper(d1mQuote,1, TimeUnit.Months,settlementDays, calendar, RollingConvention.ModifiedFollowing, depositDayCounter);

 

DepositRateHelper d3m = new DepositRateHelper(d3mQuote,3, TimeUnit.Months,settlementDays, calendar, RollingConvention.ModifiedFollowing, depositDayCounter);

                                   

RateHelper[] depos = new RateHelper[3] {d1w, d1m, d3m};

                                   

TermStructure depoTermStruc = new (PiecewiseFlatForward(todaysDate, settlementDate,

                        depos,depositDayCounter,.0001);

                 

Console.WriteLine(depoTermStruc.Discount(30,true));

            }

 

When I inspect the objects during a debugging session I notice that the MaxTime and MaxDate fields of the TermStructure which I have created in the second-last line have System.IndexOutOfRangeException as a value.

 

Separately, are there any examples of QuantLib.net implementation as there are for regular QuantLib.

 

Thankyou in advance for your assistance,

 

Kind Regards,

Richard Howes