how to get discretely compounded zero rates

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

how to get discretely compounded zero rates

jing lu
Hello All,

I would like to know how to request monthly compounded zero rates from
a termstructure  using the zeroRate member function. From example in
test-suites I see one can request continuously compounded zero rates
with termStructure_->zeroRate(testDate, rfdc,Continuous, NoFrequency);
However if I use termStructure_->zeroRate(testDate, rfdc,Compounded, Monthly);
the program crashes. Can anyone help to explain how to setup Compounding
and Frequency parameters for this method to get monthly compounded rate.

Thanks,

Jing





Boardwalk for $500? In 2007? Ha!
Play Monopoly Here and Now (it's updated for today's economy) at Yahoo! Games.
-------------------------------------------------------------------------
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
Reply | Threaded
Open this post in threaded view
|

Re: how to get discretely compounded zero rates

Luigi Ballabio
On Thu, 2007-06-28 at 13:57 -0700, jing lu wrote:
> I would like to know how to request monthly compounded zero rates from
> a termstructure  using the zeroRate member function. From example in
> test-suites I see one can request continuously compounded zero rates
> with termStructure_->zeroRate(testDate, rfdc,Continuous, NoFrequency);
> However if I use termStructure_->zeroRate(testDate, rfdc,Compounded,
> Monthly);
> the program crashes.

Jing,
        in your program, can you wrap the call in a try/catch block, as in:

try {
        termStructure_->zeroRate(testDate, rfdc,Compounded, Monthly);
} catch (std::exception& e) {
        std::cout << e.what() << std::endl;
}

so that the actual error message is printed out?

Luigi


--

Grabel's Law:
2 is not equal to 3 -- not even for large values of 2.



-------------------------------------------------------------------------
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
Reply | Threaded
Open this post in threaded view
|

Re: how to get discretely compounded zero rates

John Maiden
I'm working on creating a yield curve myself, and had a problem
just copying and pasting the code from CompoundForward.cpp in the
test suite. If this is what you did, then when you are loading
the rates and dates vectors, use pushback, i.e.

Size i;
for (i=0; i<deposits; i++) {
  rates.push_back(depositData[i].rate/100);
  dates.push_back(calendar.advance(settlement,
  Period(depositData[i].n,
  depositData[i].units),
  convention));
}

Hopefully this was your problem.

I'm new to calculating yield curves, and am having
trouble calculating the forward rates myself. I tried using the
code below, and couldn't get rates beyond the ones I loaded.
How do you get the program to extrapolate future rates?

struct Datum {
    Integer n;
    TimeUnit units;
    Rate rate;
};

int _tmain(int argc, _TCHAR* argv[])
{
try{

Datum depositData[] = {
        { 3, Months, 4.813194 },
        { 6, Months, 4.914039 },
        { 12, Months, 4.958746 }
        };

        Calendar calendar;
        Natural settlementDays;
        Date today, settlement;
        BusinessDayConvention convention;
        DayCounter dayCounter;
        Frequency frequency;

        Size deposits;
        std::vector<Rate> rates;
        std::vector<Date> dates;
        boost::shared_ptr<CompoundForward> termStructure;

        deposits = LENGTH(depositData);

        calendar = UnitedStates();
        settlementDays = 0;
        today = calendar.adjust(Date::todaysDate());
        Settings::instance().evaluationDate() = today;
        settlement = calendar.advance(today,settlementDays,Days);
        convention = ModifiedFollowing;
        dayCounter = Actual365Fixed();
        frequency = Semiannual;

        Size i;
        for (i=0; i<deposits; i++) {
                rates.push_back(depositData[i].rate/100);
                dates.push_back(calendar.advance(settlement,  
                Period(depositData[i].n,
                depositData[i].units),
                convention));
                }

        termStructure = boost::shared_ptr<CompoundForward>(
                new CompoundForward(settlement,dates,rates,
                calendar,convention,
                frequency,dayCounter));

        Date tty = calendar.advance(today, 18, Months, convention);

        cout << termStructure->forwardRate(today, tty, dayCounter, Continuous,
frequency) << endl;

        } catch (std::exception& e) {
                cout << e.what() << endl;
        }

        system("PAUSE");
        return 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
Reply | Threaded
Open this post in threaded view
|

Re: how to get discretely compounded zero rates

John Maiden
This is probably a naive question, but why don't I
get the same forward rate (the last item in the
Data struct) if I try

Date tty = termStructure->maxDate();

cout << termStructure->forwardRate(today, tty, dayCounter, Continuous,
frequency) << endl;

As far as I know, the program only calculates
a linear fit between the forward values. Where
would it change the actual forward values?


-------------------------------------------------------------------------
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
Reply | Threaded
Open this post in threaded view
|

Re: how to get discretely compounded zero rates

Luigi Ballabio
On Fri, 2007-06-29 at 20:29 +0000, John Maiden wrote:
> This is probably a naive question, but why don't I
> get the same forward rate (the last item in the
> Data struct) if I try
>
> Date tty = termStructure->maxDate();
>
> cout << termStructure->forwardRate(today, tty, dayCounter, Continuous,
> frequency) << endl;

John,
        try dropping the CompoundForward curve and using an
InterpolatedZeroCurve or a instead. The CompoundForward is a rather old
contribution, was a bit ad-hoc, and I'm not sure that it still works
correctly.

Luigi


--

The Feynman Problem Solving Algorithm:
1) Write down the problem.
2) Think very hard.
3) Write down the solution.



-------------------------------------------------------------------------
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