Random walks

Introduction to Portfolio Risk Management in Python

Dakota Wixom

Quantitative Analyst | QuantCourse.com

Random walks

Most often, random walks in finance are rather simple compared to physics:

Introduction to Portfolio Risk Management in Python

Random walks in Python

Assuming you have an object StockReturns which is a time series of stock returns.

To simulate a random walk:

mu = np.mean(StockReturns)
std = np.std(StockReturns)
T = 252
S0 = 10
rand_rets = np.random.normal(mu, std, T) + 1
forecasted_values = S0 * (rand_rets.cumprod())
forecasted_values
array([ 9.71274884,  9.72536923, 10.03605425 ... ])
Introduction to Portfolio Risk Management in Python

Monte Carlo simulations

A series of Monte Carlo simulations of a single asset starting at stock price $10 at T0. Forecasted for 1 year (252 trading days along the x-axis):

Introduction to Portfolio Risk Management in Python

Monte Carlo VaR in Python

To calculate the VaR(95) of 100 Monte Carlo simulations:

mu = 0.0005
vol = 0.001
 T = 252
sim_returns = []
for i in range(100):
    rand_rets = np.random.normal(mu, vol, T)
    sim_returns.append(rand_rets)
var_95 = np.percentile(sim_returns, 5)
var_95
-0.028
Introduction to Portfolio Risk Management in Python

Let's practice!

Introduction to Portfolio Risk Management in Python

Preparing Video For Download...