# Calculate approximate duration for a bond

A useful approximation of the duration formula is called the *approximate duration*, which is given by $$(P(down) - P(up)) / (2 * P * \Delta y)$$

where \(P\) is the price of the bond, \(P(down)\) is the price of the bond if yield decreases, \(P(up)\) is the price of the bond if yield increases, and \(\Delta y\) is the expected change in yield.

The full duration formula is more complex. If you're interested, you can refer to the "Fixed Income" chapter of my book as a reference for that formula.

In this exercise, you will calculate the approximate duration of a bond with $100 par value, 10% coupon rate, 20 years to maturity, 10% yield to maturity, and a 1% expected change in yield. To make this calculation, use your familiar `bondprc()`

function, which has been preloaded in the workspace.

This is a part of the course

## “Bond Valuation and Analysis in R”

### Exercise instructions

- Use
`bondprc()`

to calculate the bond price today given 10% yield. Save this to`px`

and then view`px`

. - Use another call to
`bondprc()`

to calculate the bond price (`px_up`

) if the yield increases by 1%. - Use a third call to
`bondprc()`

to calculate the bond price (`px_down`

) if the yield decreases by 1%. - Use your three objects (
`px`

,`px_up`

,`px_down`

) to calculate the approximate duration assuming a 1% change in yields.

### Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

```
# Calculate bond price today
px <- bondprc(p = ___, r = ___, ttm = ___, y = ___)
px
# Calculate bond price if yields increase by 1%
px_up <-
px_up
# Calculate bond price if yields decrease by 1%
px_down <-
px_down
# Calculate approximate duration
duration <- (___ - ___) / (___ * ___ * ___)
duration
```

This exercise is part of the course

## Bond Valuation and Analysis in R

Learn to use R to develop models to evaluate and analyze bonds as well as protect them from interest rate changes.

Interest rate risk is the biggest risk that bond investors face. When interest rates rise, bond prices fall. Because of this, much attention is paid to how sensitive a particular bond's price is to changes in interest rates. In this chapter, we start the discussion with a simple measure of bond price volatility - the Price Value of a Basis Point. Then, we discuss duration and convexity, which are two common measures that are used to manage interest rate risk.

Exercise 1: Bond price volatility and the price value of a basis pointExercise 2: Price value of a basis pointExercise 3: Calculate PV01 of a 10% bondExercise 4: DurationExercise 5: Duration of a zero-coupon bondExercise 6: Calculate approximate duration for a bondExercise 7: Estimating effect on bond price using durationExercise 8: ConvexityExercise 9: Calculate approximate convexity for a bondExercise 10: Estimating effect of convexity on bond priceExercise 11: Estimating the bond price using duration and convexity### What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.