Hi,
Thanks for your response.
We compare true yield in BBG.
As you said, I had to set
BusinessDayConvention paymentConvention = Unadjusted
to avoid discrepancies.
Ultimately we implemented a new method isSettlementLastCouponPeriod()
in ql/instruments/bonds/fixedratebond.hpp which returns whether the settlement falls into the last coupon period or not.
Then we did…
bool bIsSettlementLastCouponPeriod = bond.isSettlementLastCouponPeriod(settlementDate);
Compounding compoundingMethod = bIsSettlementLastCouponPeriod ? SimpleThenCompounded : Compounded;
Real ql_clean_price = BondFunctions::cleanPrice( bond, ql_yield, bondDayCount, compoundingMethod, frequency, settlementDate);
Now QuantLib yield match 100% with Bloomberg.
Duration and convexity don’t match with Bloomberg. It appears that QuantLib doesn’t take the weight of present values into account in computing these two figures
whereas Bloomberg does.
Thanks
-Senevi
From: Jean-Mathieu Vermosen [mailto:[hidden email]]
Sent: Wednesday, November 06, 2013 2:37 PM
To: [hidden email]
Subject: Re: [Quantlib-users] Yield, Macaulay duration and Convexity calculation for Notes/Bonds
Hey there,
Which yield are you comparing to in BBG ? Treasury yield convention doesn’t adjust payments for holidays, so make sure that
BusinessDayConvention paymentConvention = ModifiedFollowing;
you passed to the FixedRateBond constructor is not creating discrepancies in the cash-flow table (Just checked the code, it’s used in FixedRateLeg class for cash-flow generation). Otherwise you would prefer to compare to the true yield
under the YA screen (after turning the flag to Following: ModifiedFollowing is for the swap guy).
The duration/convexity figures looks quite far from there target. As far as I remember Bloomberg is not adjusting for convention across bonds of different setup (except for the frequency in some screens). Then it might requires further
investigation or to contact our friends from the hep desk to check the convention behind...
Best,
Jean-Mathieu Vermosen
On Nov 4, 2013, at 10:25 AM, Senevi J Kankanamge Don <[hidden email]> wrote:
Hi,
I am attempting to use QuantLib library in order to calculate yield, Macaulay duration and convexity for US Treasury Notes and Bonds.
This is how the values compare in Bloomberg and QuantLib for one example where the price is 99.8984375.
Bloomberg QuantLib
Yield 0.302775 0.3027679582
Macaulay Duration 1.928 1.9129221698
Convexity 0.047 0.0460608896
Can you please let me know what I need to change in my code in order to get the results matching with Bloomberg?
This is a snippet of my code.
double ql_price = 99.8984375;
Date settlementDate = Date(25, Oct, 2013);
Date firstCouponDate = Date(31, Mar, 2014);
Date datedDate = Date(30, Sep, 2013);
Date maturityDate = Date(30, Sep, 2015);
//
// Parameters required to define the bond
//
Natural settlementDays = 0;
Real faceAmount = 100;
DayCounter bondDayCount = ActualActual(ActualActual::Bond);
BusinessDayConvention paymentConvention = ModifiedFollowing;
Real redemption = 100.0;
Compounding compoundingMethod = SimpleThenCompounded;
DateGeneration::Rule dateGeneration = DateGeneration::Forward;
Frequency frequency = Semiannual;
Real accuracy = 1.0e-11;
Size maxEvaluations = 100;
//
// Create the Schedule
//
Schedule fixedBondSchedule(
datedDate, // Dated Date
maturityDate, // Maturity Date
Period(Semiannual), // Period
UnitedStates(UnitedStates::GovernmentBond), // Calendar
Unadjusted, // BusinessDayConvention - convention
Unadjusted, // BusinessDayConvention - terminationDateConvention
dateGeneration, // DateGeneration::Rule rule
false, // endOfMonth
firstCouponDate); // First Date
//
// Create the Fixed Rate Bond
//
FixedRateBond bond(
settlementDays, // Settlement Days
faceAmount, // Face Amount
fixedBondSchedule, // Schedule
std::vector<Rate>(1, ql_coupon), // Coupons
bondDayCount, // DayCounter
paymentConvention, // BusinessDayConvention
redemption); // Redemption
Real ql_yield = BondFunctions::yield( bond, ql_price, bondDayCount, compoundingMethod, frequency, settlementDate, accuracy, maxEvaluations);
InterestRate interestRate(ql_yield, bondDayCount, compoundingMethod, frequency );
Real ql_convexity = BondFunctions::convexity( bond, interestRate, settlementDate );
Compounding compoundingMethod4Duration = Compounded;
Time ql_duration = BondFunctions::duration( bond, ql_yield, bondDayCount, compoundingMethod4Duration, frequency, Duration::Macaulay, settlementDate );
Thanks
-Senevi
------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
| Free forum by Nabble | Edit this page |