Introduction
Risk¶
To understand risk we are going to start with simulated data. The code below can just be run and it will create some data to be used in this process.
import numpy as np
#Create the market returns
np.random.seed(1)
market_returns = np.random.normal(0.000325, .02, 500)
With market returns, we could simulate the hypothetical path. If our market that these returns represent was worth $100, then the following code is going to represent its evolution over time.
#Use P to denote current price
P = 100
#The ts variable will hold the time series of the asset price, at time 0 it is equal to P
ts = [P]
#Iterate through all the returns
for r in market_returns:
#The new market value is P * (1+r)
P = P * (1+r)
#Append to the time series
ts.append(P)
import matplotlib.pyplot as plt
#Graphically it looks like this
plt.plot(range(len(ts)),ts)
plt.xlabel("t")
plt.ylabel("Market Value")
plt.title("Market Value over 500 Trading Days")
plt.show()
Holding period return is equal to either of the following, the final ending price divided by the starting price or the multiplication of all the returns plus 1, with one subtracted after the multiplication:
$$ HP_t = \frac{P_t}{P_0} - 1$$$$ HP_t = [\prod_{i=1}^{N} (1+r_i)] - 1$$
where
$$ P_i = \text{The asset price at time i} $$$$ r_i = \text{The return at time i} $$$$ N = \text{The number of returns} $$
#Method 1
HPR = ts[-1] / ts[0] - 1
print(HPR)
from numpy import prod
#Method 2
#We can use prod from numpy
HPR = prod([r+1 for r in market_returns]) - 1
print(HPR)