, , , , ,

Summary: Everyone seeks fortune. But managing financial affairs is not an easy cook for the general public since that business jargon and the complicated fluctuations in price have confused many investors who merely have the faintest idea of investment. At this point, bonds — a fixed income investment with a defined holding period — draws the attention of many, yet a less risky basket of this kind could still be affected by the ever-changing market.

Thus, we used Python and the universally-acknowledged bond valuation method, Discounted Cash Flow (DCF), to design an efficient and easy-understanding calculator to help green hands to estimate if they can receive the expected proportion of benefit from a given bond.

Understanding Bonds: What is a Bond and How Bonds Work

“A bond is a fixed income investment in which an investor loans money to an entity which borrows the funds for a defined period of time at a fixed interest rate.”


图片 1.png▲ A Bond’s Lifetime (Source: Vanguard)

When entities need to raise funds to finance new projects, maintain ongoing operations, or refinance existing debts, they may issue bonds directly to investors instead of obtaining loans from a bank. And this is how they work:

Firstly, the indebted entity issues a bond at a given price (principal paid) to the investor. In this period, the investor pays the principal for the bond, i.e. having the cash flown out. And then, the investor needs to hold the bond for a certain duration, during which the bond has its value kept increasing at a fixed rate (coupon rate), usually in an annual basis, as a return that bondholders earn for loaning their funds to the entity. Finally, when the holding period ends — in other words, the bond matures (maturity date) — the creditor is paid with the original principal plus the annual coupon payment.


‘Adventurers’: Why Don’t People Hold Bonds Till Maturity?

1) If You Hold a Bond Till Maturity

Based on the features of bonds, the investor can purchase a bond, holding it till maturity. And then the money will be returned as below.

Let’s say the issuance price of a bond is set at par 100 yuan. Given the holding period for 3 years and the coupon rate as 5%, the overall return to the creditor should be:

33.png▲ The overall return of a three-year 5% bond issued at par 100 yuan

2) If You Enter the Market in the Midst

However, many investors tend not to hold bonds till maturity. Instead of purchasing a bond, holding it for a fixed period and waiting for the windfalls, many prefer to transact on the secondary market in the midst of the holding period.

Why would this happen?

Because the bond market is ever-changing.

The fixed-rate bonds will pay the same percentage of its principal over time though, many investors tend not to hold a bond for such a long time since the actual market price of a bond will fluctuate, depending on several factors including the credit quality of the issuer, the variation of demand, the length of time until expiration, and the coupon rate compared to the general interest rate environment at the time. That’s why the bonds’ prices change from time to time.

Bond Valuation: How to Evaluate a Bond

Discounted Cash Flow (DCF) is a valuation method generally used when the actual market price of a valid bond is different from its original principal.

“DCF analysis use future free cash flow projections… [and] a required annual rate, to arrive at present value estimates. A present value estimate is then used to evaluate the potential for investment.”


Calculated as:


Breaking Down Discounted Cash Flow


To apply this formula, the potential investor needs to input some variables related to a bond which the investor is interested in, including his or her expected interest rate, the market price of the bond and the time the investor plans to hold it.

The cash flow can be decided by multiplying the bond’s principal and coupon rate. And then by inputting the expected interest rate, one can calculate the recommended value of this bond. The bond is worth-purchasing if the actual market value is lower than the recommended value, otherwise, it is not.

Example: Which Bond Can Meet Your Expectation?

Driven by China’s Central Bank’s current policy of shrinking the interest rate, Shawn Xu, an investor from mainland China, is planning on purchasing some corporate bonds to diversify his portfolio.

Within his consideration are mainly three bonds, HNA02 (122071), SH (068005) and Luguoji (124714). All these three bonds have a five-year maturity duration and an equivalent original principal of 100 yuan.

According to the information provided by the bonds info platform, Hexun.com, on February 6th, 2018, the market price of HNA02 (122071) is 89.98 yuan with the coupon rate being 6.2%; while that of SH (068005) is 90.83 yuan with a 4.2% coupon rate; as for Luguoji (124714), the current market price is 102.79 yuan and the coupon rate stands at 7.5%.


Given the expected interest rate of Mr. Xu being 8%, he can get the recommended values of the three bonds by inputting their market prices and the five-year holding period into the formula respectively. And then by comparing their recommended values and actual market prices, Mr. Xu will know whether they can meet his expectation or not.


▲ Inputting the elements


▲ Using DCF analyses to evaluate the recommended price of a bond


▲ The recommended prices of the three bonds

The complete final version code can be found here: bond_dcf_version3 . According to the calculation of the formula, the comparisons between recommended values and actual market prices of the three bonds are as followed:


Considering the recommended value of HNA02 (122071) is 92.01 yuan, which is 2.03 yuan higher than its actual market price (89.98 yuan), Mr. Xu stands a greater chance to reach his 8% expected interest rate if he purchases HNA02 (122071).

In comparison, the other two bonds are relatively less worth-purchasing since their recommended values are both lower than their current market prices.

Problems You Might Encounter

  1. Do be careful of the block when you use a function.
  2. An operation can only be run between the same type of values, so before running the function, you need to reconcile the value type.
  3. If you want to use the function that you defined before, the variables of the function should also be input in code together with the function name.
  4. When the variables of a function are list elements, remember to indicate the indexes of the elements in the list if you want to use that.
  5. You can print the return of parts of your code to check if it is implemented step by step.
  6. When you check your function, especially when you used the “if” function, you can try to input different values, making different conditions of the function can be tested.



Notes from Lecturer

The problem selected is interesting and relevant. There is also adequate background information to help readers understand the concerns towards a bond’s value. Validation against real-world data-set is a plus. In terms of implementation, using list-of-dict to present a dataset is a common method and worth sharing with the class. A good direction for extension, which may involve more use of currently learned Python skill, is to solve for “expected_interest” given other parameters. That is, pin down the market price and other parameters, then use iteration (better bi-section method) to solve for “expected_interest”. The refactoring process is also valuable for others to learn. Interested readers can refer to the different versions of the code.

— Pili Hu


Others can learn how to refactor codes from those different versions

Author/ Ma Xinyu, Xu Zishuo, Wang Qian

Editor/  Yucan Xu, Pili Hu