Stress Testing and Scenario Analysis
Stress Testing and Scenario Analysis
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.stats import norm
[*********************100%***********************] 4 of 4 completed
data.head()
Date
Next steps: Generate code with data toggle_off View recommended plots New interactive sheet
# Portfolio returns
portfolio_returns = returns.dot(weights)
num_simulations = 1000
simulated_shocks = np.random.normal(-0.05, 0.02, (num_simulations, len(tickers))) # Mean drop 5%, StdDev 2%
stressed_returns = simulated_shocks.dot(weights)
# Plot
sns.histplot(stressed_returns, kde=True, bins=50, color="blue")
plt.axvline(-VaR_MC, color='red', linestyle="--", label="95% VaR")
plt.axvline(-ES_MC, color='green', linestyle="--", label="95% Expected Shortfall")
plt.legend()
plt.title("Monte Carlo Simulation of Market Stress Scenarios")
plt.show()