Python for Finance: Analyze Big Financial Data

(Elle) #1
                            (to account for different   conventions)

Results
=======
delta_list : array
year fractions
”’

start = date_list[ 0 ]
delta_list = [(date - start).days / day_count
for date in date_list]
return np.array(delta_list)


This function can then be applied as follows:


In  [ 1 ]:  import datetime as dt

In  [ 2 ]:  dates   =   [dt.datetime( 2015 ,     1 ,     1 ),   dt.datetime( 2015 ,  7 ,     1 ),
dt.datetime( 2016 , 1 , 1 )]

In  [ 3 ]:  get_year_deltas(dates)
Out[ 4 ]: array([ 0. , 0.49589041, 1. ])

When modeling the short rate, it becomes clear what the benefit of this is.


Constant Short Rate


We focus on the simplest case for discounting by the short rate; namely, the case where the


short rate is constant through time. Many option pricing models, like the ones of Black-


Scholes-Merton (1973), Merton (1976), and Cox-Ross-Rubinstein (1979), make this


assumption.


[ 66 ]

We assume continuous discounting, as is usual for option pricing


applications. In such a case, the general discount factor as of today, given a future date t


and a constant short rate of r, is then given by D 0 (t) = e


–rt

. Of course, for the end of the


economy we have the special case D 0 (T) = e


–rT

. Note that here both t and T are in year


fractions.


The discount factors can also be interpreted as the value of a unit zero-coupon bond (ZCB)


as of today, maturing at t and T, respectively.


[ 67 ]

Given two dates t ≥ s ≥ 0, the discount


factor relevant for discounting from t to s is then given by the equation Ds(t) = D 0 (t) /


D 0 (s) = e


–rt

/ e


–rs

= e


–rt

· e


rs

= e


–r(t–s)

.


Example 15-2 presents a Python class that translates all these considerations into Python


code.


[ 68 ]

Example 15-2. Class for risk-neutral discounting with constant short rate



DX Library Frame


constant_short_rate.py



from get_year_deltas import *


class constant_short_rate(object):
”’ Class for constant short rate discounting.


            Attributes
==========
name : string
name of the object
short_rate : float (positive)
constant rate for discounting

Methods
=======
Free download pdf