In the previous chapter, Chapter 11, Value at Risk, we learnt that we could apply two methods to estimate a VaR for an individual stock or for a portfolio: it depends on the normality assumption and based on the ranking of historical returns. Monte Carlo Simulation could link those two methods, see the following code:
import numpy as np import numpy as np import scipy as sp import pandas as pd from scipy.stats import norm # position=1e6 # portfolio value std=0.2 # volatility mean=0.08 # mean return confidence=0.99 # confidence level nSimulations=50000 # number of simulations # Method I z=norm.ppf(1-confidence) VaR=position*(mean+z*std) print("Holding=",position, "VaR=", round(VaR,2), "tomorrow") # # Method II: Monte Carlo simulaiton sp.random.seed(12345) ret2=sp.random.normal(mean,std,nSimulations) ret3=np.sort(ret2) m=int(nSimulations*(1-confidence)) VaR2=position*(ret3[m]) print...