domokane / FinancePy

A Python Finance Library that focuses on the pricing and risk-management of Financial Derivatives, including fixed-income, equity, FX and credit derivatives.
GNU General Public License v3.0
2.16k stars 322 forks source link

Calculate the accrued interest of the Zero Coupon Bond #146

Closed DominicHong closed 2 years ago

DominicHong commented 2 years ago

Zero Coupon Bonds now have accrued interest.

accrued_interest of zero-coupon bond = (principal - issue price)*(settlement_date - issue_date)/(maturity_date - issue_date)

Added issue_price to Bond.init() Modified Bond.calc_accrued_interest() Modified unit test and golden test for zero bonds.

domokane commented 2 years ago

Hi - I don't understand how that is accrued interest ? Isn't that just a capital gain ?

DominicHong commented 2 years ago

Of course you can count it as capital gain. But it's considered interest in accounting, at least it's the convention in China.  Two considerations: 1, This 'capital gain' increases day by day just as the interest does. On the other hand, the normal coupon is paid only on payment days, just as the capital gain of a zero bond on the maturity day. So capital gain can be interest and interest can be capital gain. They are the same. 2, The trade system ususally uses the same quote convention for both zero bonds and bonds with coupon. The price is quoted in clean price. It would be strange to always have no accrued interest for a clean price.

------------------ Original ------------------ From: "domokane/FinancePy" @.>; Date: Tue, Sep 27, 2022 05:38 PM @.>; @.**@.>; Subject: Re: [domokane/FinancePy] Calculate the accrued interest of the Zero Coupon Bond (PR #146)

Hi - I don't understand how that is accrued interest ? Isn't that just a capital gain ?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

domokane commented 2 years ago
OK. Perhaps you could create a simple zero coupon bond class called bond_zero so that we avoid zero coupon specific functions ?That would be simpler and cleaner in my view as there is no need to use a coupon or frequency to create it. BestDFrom: Dominic HongSent: 27 September 2022 14:36To: domokane/FinancePyCc: domokane; CommentSubject: Re: [domokane/FinancePy] Calculate the accrued interest of the Zero Coupon Bond (PR #146) Of course you can count it as capital gain. But it's considered interest in accounting, at least it's the convention in China.  Two considerations: 1, This 'capital gain' increases day by day just as the interest does. On the other hand, the normal coupon is paid only on payment days, just as the capital gain of a zero bond on the maturity day. So capital gain can be interest and interest can be capital gain. They are the same. 2, The trade system ususally uses the same quote convention for both zero bonds and bonds with coupon. The price is quoted in clean price. It would be strange to always have no accrued interest for a clean price. ------------------ Original ------------------ From: "domokane/FinancePy" ***@***.***>; Date: Tue, Sep 27, 2022 05:38 PM ***@***.***>; ***@***.******@***.***>; Subject: Re: [domokane/FinancePy] Calculate the accrued interest of the Zero Coupon Bond (PR #146) Hi - I don't understand how that is accrued interest ? Isn't that just a capital gain ? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: ***@***.***> —Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: ***@***.***> 
DominicHong commented 2 years ago

Sounds reasonable. How about a subclass of Bond?

domokane commented 2 years ago
I thought of that. But inheritance in my view should be used when a bigger class inherits from a smaller class. Here it would be the reverse as a zero coupon bond has no cashflows and so is much much simpler with fewer and simpler methods. Also I have tried to avoid inheritance for the purpose of making the code more accessible. I realise that there may be some duplication but I don’t care too much as the code is so simple. I would simply copy the bond class and remove all the unnecessary code. From: Dominic HongSent: 27 September 2022 15:46To: domokane/FinancePyCc: domokane; CommentSubject: Re: [domokane/FinancePy] Calculate the accrued interest of the Zero Coupon Bond (PR #146) Sounds reasonable. How about a subclass of Bond?—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: ***@***.***> 
DominicHong commented 2 years ago

Hi, I've created the new BondZero class. Please check it out.

domokane commented 2 years ago

Great! I think it looks good and keeps the bond class cleaner and the design simple. I have checked it and merged it. I will do some more checking later.