随机游走

Python 投资组合风险管理入门

Dakota Wixom

Quantitative Analyst | QuantCourse.com

随机游走

在金融中,随机游走通常比物理中的更简单:

Python 投资组合风险管理入门

Python 中的随机游走

假设您有一个 StockReturns 对象,为股票收益率的时间序列。

要模拟随机游走:

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 ... ])
Python 投资组合风险管理入门

蒙特卡洛模拟

单一资产从 T0 时股价 $10 开始的多次蒙特卡洛模拟。预测 1 年(x 轴为 252 个交易日):

Python 投资组合风险管理入门

Python 中的蒙特卡洛 VaR

计算 100 次蒙特卡洛模拟的 VaR(95):

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
Python 投资组合风险管理入门

Passons à la pratique !

Python 投资组合风险管理入门

Preparing Video For Download...