Bug in dirtyPriceFromYield() function...

Posted by Toyin Akin on
URL: http://quantlib.414.s1.nabble.com/BinomialEuropeanEngine-C-SWIG-tp4960p4963.html

Hi,

within the Bond.cpp class, the main function used for Yield-to-maturity
calculation, dirtyPriceFromYield(), gives incorrect values when the
Compounding type is SimpleThenCompounded.

This Compounding type is useful because it corresponds to the Mossmuller
Yield calculation method (as opposed to the Compounded method which
corresponds to the ISMA Yield calculation).

Basically, the discount() function of the InterestRate object always uses
the Simple method for all periods because of the way dates are passed in
(start and end dates are always equal to the frequency period).

If however you fixed the start date to the settledate (instead of the
lastDate variable) and then computed the discount(), then all is well. You
would then have to change

discount *=

to

discount =

One other question, a query really, within the same function, you have the
logic

couponDate - 1*Years;

Should this be

couponDate - (12/frequency)*Months ?

Toy out.

>From: "Toyin Akin" <[hidden email]>
>To: [hidden email]
>CC: [hidden email]
>Subject: [Quantlib-users] Problem in bond long coupon calculations...
>Date: Sun, 03 Sep 2006 04:50:09 +0100
>
>Hi,
>
>For regular bond calculations (using unadjusted dates, equal coupon
>periods,
>same coupon amount paid for each period) where we have either a long first
>or last coupon period, the yearFraction() method of the DayCounter classes
>often produce the wrong values.
>
>for example, if you have a long final coupon period of 6 month frequency
>and
>the dates are
>
>Penultimate coupon date = 40441 = 20/9/2010
>Maturity date = 40623 = 21/3/2011
>
>Penultimate coupon date + 6 months = 60622 = 20/3/2011
>
>A typical DayCounter class will have as variable values
>
>PeriodStart = 20/9/2010
>PeriodEnd =  21/3/2011
>
>refPeriodStart = 20/9/2010
>refPeriodEnd =  20/3/2011
>
>Bascially a long end period by one day.
>
>For a bond (especially for most government bonds where adjusted dates are
>not used), the usual way to compute the yearfraction for long periods would
>be to count all 6 month periods (in our case) as 0.5, and whatever is left
>we apply the yearFraction() function on this period.
>
>ie
>
>A = 20/9/2010 -> 20/3/2011 = 0.5
>B = 20/3/2011 -> 21/3/2011 = yearFraction(20/3/2011, 21/3/2011, 20/3/2011,
>20/3/2011 + 6M)
>
>TotalYearFraction = A + B.
>
>Currently, most of the DayCounter classes will return a value less than 0.5
>for the same period.
>
>I'm thinking maybe a neat solution around this would be to create a
>templated class which would take a DayCounter as the template parameter and
>derive from this. When a long period is detected, it will perform the
>computation above, else delegate to normal operations. The nice thing about
>this route is that the user can create the templated object and pass it to
>the firstPeriodDayCount variable of the FixedRateCouponVector function().
>
>It might be a good idea to use this same firstPeriodDayCount for a possible
>long/short **LAST** coupon period and thus rename the firstPeriodDayCount
>parameter to accuralPeriodDayCount.
>
>Thoughts...
>
>Toy out.
>
>
>
>-------------------------------------------------------------------------
>Using Tomcat but need to do more? Need to support web services, security?
>Get stuff done quickly with pre-integrated technology to make your job
>easier
>Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
>http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>_______________________________________________
>QuantLib-users mailing list
>[hidden email]
>https://lists.sourceforge.net/lists/listinfo/quantlib-users