(This article was first published on

I often use R language to write "prototype" program. As you know, It has very high productivity and smart grammar. In this article, I would like to show you how to write the program to evaluate the price of defaultable bond by "reduced-form model".**My Life as a Mock Quant in English**, and kindly contributed to R-bloggers)Before write a program, we need to understand how to price these bond.

Under risk neutral measure, we can evaluate the price of defaultable (discount) bond as below.

In this equation, I set variables as below.

- v(t,T) : The price of defaultable bond with maturity T at time t
- r(t) : Short rate at time t
- delta_(t) : Recovery rate at time t
- tau : default time
- 1{} : Indicator function

For montecarlo simulation, we need to model short rate and default intensity process, I modeled default intensity process and short rate as CIR model.

CIR model assume that some stochastic process obey below Stochastic differential equation.

Each variables have following meaning.

- x(t) : The value of stochastic variable obeying CIR process at time t.
- kappa : The speed of adjustment
- theta : The mean of stochastic variable
- sigma : The volatility of stochastic variable
- W_t : Standard Brownian motion

And next, I set the simulation condition as below.

-------------------------------- Simulation condition -------------------------------

- The number of path : 500
- The number of grid per year : 250
- Recovery rate : 0.7
- Maturity of bond : 2
- The correlation between interest rate and default intensity : 0.3

- kappa : 0.6
- theta : 0.05
- sigma : 0.05
- initial value : 0.05

- kappa : 0.6
- theta : 0.2
- sigma : 0.5
- initial value : 0.2

After these settings, we can write simulation program. The entire of program is folloing that.

(Sorry for the comment written in Japanese, To tell the truth, this article is posted in other site in Japanese...)

(If you have any question, don't hesitate to ask me :))

The result of this program is about 0.830±0.005(It depends on the seed of random number generator).

Enjoy !

To

**leave a comment**for the author, please follow the link and comment on his blog:**My Life as a Mock Quant in English**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...