Re: Coupons and Fixed Rate Legs

Posted by John Maiden on
URL: http://quantlib.414.s1.nabble.com/Coupons-and-Fixed-Rate-Legs-tp1151p1160.html

Ok, I've come up with a temporary fix. Since I'm working with the convertible
bond class, the program adds the accrued at every coupon date. I want a daily
(or weekly, monthly, yearly, depending on user preferences) schedule with daily
(or etc) accrued coupons added, so that we know how to compute the convert price
at any time until maturity. What I've done is to set up a coupon schedule that
reflects the actual schedule (in this case, semiannual) using Chiara's comments.
Then I create a new schedule (daily, weekly, etc) that calculates the accrued
for each date. The only weird part of it is that I get a full semi-annual coupon
due the next to last date and the last date. I guess this is what Chiara meant
about the odd coupon.

Code is below for those that are interested:

// TestQuantLib.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <ql/quantlib.hpp>
#include <boost/timer.hpp>

using namespace std;
using namespace QuantLib;

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

                std::vector<Real> coupons(1, 0.0475);
                std::vector<Real> faceAmount_(1, 100);

                Frequency frequency = Semiannual;
                BusinessDayConvention convention = Unadjusted;
               
                Calendar calendar = UnitedStates(UnitedStates::Market::NYSE);
                Date today(29, January, 1999);
                Date nexttoday = calendar.advance(today, Period(frequency), convention, true);

                Date exerciseDate = Date(1, February, 2009);
                Date beforelast = calendar.advance(exerciseDate, -Period(frequency),
convention, true);
               
                Schedule schedule_(today, exerciseDate, Period(frequency), calendar,
convention, convention,
                        true, true, nexttoday, beforelast);

                DayCounter dayCount = Thirty360();

                Leg cashFlows_ = FixedRateLeg(faceAmount_, schedule_, coupons, dayCount,
                        schedule_.businessDayConvention());

                cout << "Beginning Date: " << today << endl;
                cout << "First Coupon: " << nexttoday << endl;
                cout << "Next to Last Coupon: " << beforelast << endl;
                cout << "Stop Date: " << exerciseDate << endl;
                cout << endl;

                for(int i = 0; i < cashFlows_.size(); i++){
                                cout << cashFlows_[i]->date() << "\t" << cashFlows_[i]->amount() << endl;
                }

                                system("PAUSE");

                Size i = 0;
                for(Date d = today; d <= exerciseDate; d += 1){
                        boost::shared_ptr<FixedRateCoupon> testflow =
                                boost::dynamic_pointer_cast<FixedRateCoupon>(cashFlows_[i]);
                        cout << d << "\t" << testflow->accruedAmount(d) << endl;
                        if((d == cashFlows_[i]->date()) && (d <
cashFlows_[cashFlows_.size()-1]->date())){
                                i++;
                        }
                }
       
        } catch (std::exception& e) {
                cout << e.what() << endl;
        }

        system("PAUSE");
        return 0;
}


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users