Python for Finance: Analyze Big Financial Data

(Elle) #1

To get discount factors from the new object, a time list with year fractions is needed:


In  [ 52 ]: time_list   =   [0.0,   0.5,    1.0,    1.25,   1.75,   2.0]        #   in  year    fractions
In [ 53 ]: sr.get_discount_factors(time_list)
Out[53]: array([ 1. , 0.97530991, 0.95122942, 0.93941306, 0.91621887,
0.90483742])

Using this object, it is quite simple to generate a plot as before (see Figure 13-2). The


major difference is that we first update the attribute rate and then provide the time list t


to the method get_discount_factors:


In  [ 54 ]: for r in    [0.025, 0.05,   0.1,    0.15]:
sr.rate = r
plt.plot(t, sr.get_discount_factors(t),
label=‘r=%4.2f’ % sr.rate, lw=1.5)
plt.xlabel(‘years’)
plt.ylabel(‘discount factor’)
plt.grid(True)
plt.legend(loc= 0 )

Figure 13-2. Discount factors for different short rates over five years

Generally, discount factors are “only” a means to an end. For example, you might want to


use them to discount future cash flows. With our short rate object, this is an easy exercise


when we have the cash flows and the dates/times of their occurrence available. Consider


the following cash flow example, where there is a negative cash flow today and positive


cash flows after one year and two years, respectively. This could be the cash flow profile


of an investment opportunity:


In  [ 55 ]: sr.rate =   0.05
cash_flows = np.array([- 100 , 50 , 75 ])
time_list = [0.0, 1.0, 2.0]

With the time_list object, discount factors are only one method call away:


In  [ 56 ]: disc_facts  =   sr.get_discount_factors(time_list)
In [ 57 ]: disc_facts
Out[57]: array([ 1. , 0.95122942, 0.90483742])

Present values for all cash flows are obtained by multiplying the discount factors by the


cash flows:


In  [ 58 ]: #   present values
disc_facts * cash_flows
Out[58]: array([-100. , 47.56147123, 67.86280635])

A typical decision rule in investment theory says that a decision maker should invest into a


project whenever the net present value (NPV), given a certain (short) rate representing the

Free download pdf