-
Basics Part 1 2
-
Lecture1.1
-
Lecture1.2
-
-
Basics Part 2 1
-
Lecture2.1
-
-
Credit Migration 2
-
Lecture3.1
-
Lecture3.2
-
-
Vasicek Model 2
-
Lecture4.1
-
Lecture4.2
-
-
Payments 2
-
Lecture5.1
-
Lecture5.2
-
-
Complete System 2
-
Lecture6.1
-
Lecture6.2
-
Introduction
Welcome to the cadCAD bond simulations course. This course is meant to be a tutorial on a simple application of the new cadCAD library for simulating bond payoffs. It is recommended to first read through materials on the official website at cadCAD to get a feel for what the library does. There will be brief explanations of the functionality in these tutorials as well, but the team at cadCAD has much more detailed explanations of concepts. You can follow installation instructions on the website, but a simple pip install cadCAD should suffice.
So what is cadCAD? It is an open-source Python package that assists in the processes of designing, testing and validating complex systems through simulation. In this tutorial, we will work through some basics, followed by three different aspects of bonds (their payment process, their default, and re-investment of the coupon payments) which will lead into the last lesson which shows how we can build out a full simulation where all three aspects are simultaneously tested.
Let’s begin by defining a very simple model. For now, do not worry about the model as we will cover it in depth in its specific lesson. Just understand that given a rate the function will return a random movement as well as component of pulling towards a specific mean rate. The function is defined below.
import matplotlib.pyplot as plt
from scipy.stats import norm
import numpy as np
import pandas as pd
#Basic vasicek rate change model
#Make sure to use RandomState()
def rate_change(r, a=.5, b=.06, sigma=.02, t=1/12):
delta = a* (b-r) * t + sigma * t ** .5 * norm.ppf(np.random.RandomState().rand())
return delta + r
We can see how the simulated rates would look by running the following…. we assume that the time step is a month so by running a loop with 360 steps we are getting 30 years worth of rates.
#Simple example of random monthly changes to the rate
rates = [.10]
for _ in range(360):
#Every new time step, update the rate by applying the rate change function on the latest rate
rates.append(rate_change(rates[-1]))
rates = pd.Series(rates)
rates.plot(kind='line')
plt.xlabel("Month")
plt.ylabel("Rate")
plt.title("Vasicek Rate Simulation")
plt.show()