1. Value-at-Risk (VaR)
"Value-at-Risk (VaR) is a widely used measure in risk management that estimates the potential loss in the value of a portfolio or position over a specified time horizon at a certain level of confidence."
OR
"The maximum loss in a given holding period to a certain confidence level."
It provides an estimate of the maximum loss that an organization may face under normal market conditions.
There are several methods to calculate VaR
- Historical VaR:
Historical VaR is based on historical data and does not rely on any specific distribution assumption. The historical method looks at one’s prior returns history and orders them from worst losses to greatest gains—following from the premise that past returns experience will inform future outcomes. It calculates VaR using the historical distribution of portfolio returns. The formula for Historical VaR is:
Historical VaR = Portfolio Value * (1 - Confidence Level) * Return at the Selected Percentile
where:
- VaR: Value-at-Risk
- Portfolio Value: Total value of the portfolio being assessed
- Historical Return Percentile::The desired percentile of the historical return distribution, typically based on a confidence level (e.g., 95%, 99%).
- VaR: Value-at-Risk
where:
- VaR: Value-at-Risk
- Portfolio Value: Total value of the portfolio being assessed
- z-score: The number of standard deviations corresponding to the desired level of confidence. For example, for a 95% confidence level, the z-score is 1.96.
- Standard Deviation: The standard deviation of the portfolio returns, which represents the portfolio's volatility.
where:
- VaR: Value-at-Risk
- Portfolio Value: Total value of the portfolio being assessed
- Confidence Level: The desired level of confidence (e.g., 95%, 99%)
- Simulated Returns:A large number of simulated returns generated based on assumed or estimated distributions of asset returns.
- Historical Return Percentile::The desired percentile of the historical return distribution, typically based on a confidence level (e.g., 95%, 99%).
Importance:The value of VaR represents the potential loss or downside risk associated with a portfolio or position.
- A higher VaR value indicates a greater potential loss, indicating a higher level of risk.
- Conversely, a lower VaR value suggests a lower potential loss and, therefore, a lower level of risk.
===> What number are you able to cope with to a given amount of certainity over given amount of time period/holding period as a loss level. So let's say that at 90% percentile. SO 95% chance that my profit is going to be above this value that we are calculating i.e. this Var.
===> So we want to be able to say that $95\%$ certainty that our 'Value at Risk (Var)' will not exceed a certain value.
====> What number are you able to cope with to a given amount of certainity or a given amount of time
===> So Var is associated with maximum loss over a given period of time to a given confidence level.
Example¶
Calculation of parametric VaR and historical VaR
Let's assume you have daily returns for investment over the past 1,000 trading days. You want to calculate the 95% VaR for a $100,000 investment.
- Step 1: Gather the historical returns data.
- Step 2: Order the historical returns in descending order.
- Step 3: Choose the VaR level (e.g., 95%).
- Step 4: Identify the VaR value by locating the return corresponding to the 95th percentile in the ordered return series.
import numpy as np
import pandas as pd
# Assuming you have the daily returns data as an array called 'returns'
returns = [0.01, -0.02, 0.03, -0.01] # Replace with your actual data
# Specify the confidence level (95%)
confidence_level = 0.95
# Calculate the portfolio value
portfolio_value = 100000
# Sort the returns in ascending order
sorted_returns = sorted(returns)
# Determine the index corresponding to the desired percentile
index = int((1 - confidence_level) * len(sorted_returns))
# Retrieve the historical return at the determined index
historical_return = sorted_returns[index]
# Calculate VaR using Historical VaR formula
historical_var = -portfolio_value * historical_return
# Calculate the weighted returns of each asset
weights = np.array([1 / len(returns)] * len(returns))
weighted_returns = np.multiply(returns, weights)
# Calculate the portfolio return
portfolio_return = np.sum(weighted_returns)
# Print the results
print("Historical VaR at", confidence_level * 100, "% confidence level:", historical_var)
print("Portfolio Return:", portfolio_return)
Historical VaR at 95.0 % confidence level: 2000.0 Portfolio Return: 0.002499999999999999
means total loss....
# Parameter VaR: example
import numpy as np
from scipy.stats import norm
def calculate_var(portfolio_value, returns, confidence_level):
# Calculate portfolio returns' standard deviation
returns_std = np.std(returns)
# Determine the z-score corresponding to the desired confidence level
z_score = norm.ppf(1 - confidence_level)
# Calculate VaR using the Parametric VaR formula
var = portfolio_value * z_score * returns_std
return var
# Example usage
portfolio_value = 100000 # Total portfolio value
returns = np.array([0.01, -0.02, 0.03, -0.01]) # Sample returns data
confidence_level = 0.95 # Confidence level of 95%
par_var = - calculate_var(portfolio_value, returns, confidence_level)
print("VaR at 95% confidence level:", par_var)
VaR at 95% confidence level: 3158.5901106311394
Monte Carlo Simulation to calculate VaR and CVaR¶
Monte Carlo Simulation is a versatile and powerful tool in the financial sector. Here are some of the applications and use cases where Monte Carlo Simulation can be utilized:
Portfolio Optimization: Monte Carlo Simulation can be used to optimize investment portfolios by simulating various asset allocation strategies. By generating random samples of asset returns, the simulation can estimate the expected portfolio returns, risk measures such as standard deviation or Value at Risk (VaR), and optimize the portfolio composition to maximize return or minimize risk.
Option Pricing: Monte Carlo Simulation is widely employed in option pricing models, such as the Black-Scholes model. By simulating the future stock price movements based on random samples, the simulation can estimate the option's value and evaluate different option trading strategies.
Risk Management: Monte Carlo Simulation is valuable in assessing and managing risks in the financial sector. It can be used to simulate market risks, credit risks, operational risks, and other types of risks. By generating random scenarios, the simulation can quantify the potential losses, estimate risk measures such as Value at Risk (VaR) or Expected Shortfall (ES), and evaluate risk mitigation strategies.
Financial Planning: Monte Carlo Simulation can aid in financial planning and retirement analysis. By incorporating variables like income, expenses, investment returns, and lifespan, the simulation can generate random scenarios of future financial situations. This helps individuals or financial advisors make informed decisions about saving, spending, and investment strategies.
Stress Testing: Monte Carlo Simulation is utilized for stress testing financial systems and institutions. By simulating extreme scenarios and generating random samples of variables like market shocks or defaults, the simulation can evaluate the resilience and stability of financial systems, identify potential vulnerabilities, and inform regulatory decision-making.
Credit Risk Assessment: Monte Carlo Simulation can be applied to credit risk assessment, especially for loan portfolios and credit derivatives. By simulating default events and loss given default, the simulation can estimate credit risk measures, such as expected loss or probability of default, and evaluate credit portfolio performance under different scenarios.
These are just a few examples of how Monte Carlo Simulation can be employed in the financial sector. Its flexibility and ability to capture uncertainty make it a valuable tool for risk assessment, decision-making, and strategic planning in finance.
Example on Monte Carlo Simulation¶
1. normal distribution¶
# Monte carlo simulation using normal distribution
import numpy as np
import pandas as pd
# Example portfolio simulation using Monte Carlo
num_simulations = 10000
portfolio_value = 1000000
initial_investment = 1000000
expected_return = 0.08 # 8% return
volatility = 0.2
# Generate random returns based on normal distribution
returns = np.random.normal(expected_return, volatility, num_simulations)
# Calculate portfolio values for each simulation
portfolio_values = initial_investment * (1 + returns)
# Sort the simulated portfolio values
sorted_portfolio_values = np.sort(portfolio_values)
# Define the desired confidence level (e.g., 95%)
confidence_level = 0.95
# Calculate the VaR at the desired confidence level
percentile = 1 - confidence_level
index = int(percentile * num_simulations)
var = initial_investment - sorted_portfolio_values[index]
# Create a dataframe to store the portfolio returns
df_portfolio_returns = pd.DataFrame({'Portfolio Return': portfolio_values})
# Print the result
print("VaR at", confidence_level * 100, "% confidence level:", var)
print("Portfolio return for each simulation:\n", df_portfolio_returns)
VaR at 95.0 % confidence level: 242443.6554306997 Portfolio return for each simulation: Portfolio Return 0 9.818251e+05 1 1.174371e+06 2 1.006901e+06 3 1.037849e+06 4 1.167950e+06 ... ... 9995 1.129363e+06 9996 1.470854e+06 9997 1.229015e+06 9998 1.514311e+06 9999 1.223820e+06 [10000 rows x 1 columns]
import matplotlib.pyplot as plt
# Plot histogram of portfolio returns
plt.figure(figsize=(10, 6))
plt.hist(portfolio_values, bins=50, color='skyblue', edgecolor='black')
plt.axvline(var, color='red', linestyle='dashed', linewidth=2, label='VaR at 95%')
plt.xlabel('Portfolio Return')
plt.ylabel('Frequency')
plt.title('normal-Distribution of Portfolio Returns')
plt.legend()
plt.grid(True)
plt.show()
2. t-distribution for returns¶
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Example portfolio simulation using Monte Carlo
num_simulations = 10000
portfolio_value = 1000000
initial_investment = 1000000
expected_return = 0.08 # 8% return
volatility = 0.2
# Generate random returns based on t-distribution
degrees_of_freedom = 10 # Adjust the degrees of freedom as needed
returns1 = np.random.standard_t(degrees_of_freedom, num_simulations)
# Calculate portfolio values for each simulation
portfolio_values1 = initial_investment * (1 + returns1)
# Sort the simulated portfolio values
sorted_portfolio_values1 = np.sort(portfolio_values1)
# Define the desired confidence level (e.g., 95%)
confidence_level = 0.95
# Calculate the VaR at the desired confidence level
percentile = 1 - confidence_level
index = int(percentile * num_simulations)
tvar = initial_investment - sorted_portfolio_values1[index]
# Create a dataframe to store the portfolio returns
df_portfolio_returns1 = pd.DataFrame({'Portfolio Return': portfolio_values1})
# Print the result
print("VaR at", confidence_level * 100, "% confidence level:", tvar)
print("Portfolio return for each simulation:\n", df_portfolio_returns1)
# Plot histogram of portfolio returns
plt.figure(figsize=(10, 6))
plt.hist(portfolio_values1, bins=50, color='skyblue', edgecolor='black')
plt.axvline(tvar, color='red', linestyle='dashed', linewidth=2, label='t-distribution VaR at 95%')
plt.axvline(var, color='blue', linestyle=':', linewidth=2, label='normal-distribution VaR at 95%') # calculated previosuly
plt.xlabel('Portfolio Return')
plt.ylabel('Frequency')
plt.title('t-Distribution of Portfolio Returns')
plt.legend()
plt.grid(True)
plt.show()
VaR at 95.0 % confidence level: 1808807.650447472 Portfolio return for each simulation: Portfolio Return 0 1.610446e+06 1 2.395520e+06 2 3.708464e+04 3 5.411488e+05 4 1.569818e+06 ... ... 9995 1.827206e+06 9996 -4.927888e+05 9997 9.117096e+05 9998 -8.892813e+04 9999 -2.222589e+05 [10000 rows x 1 columns]
Consulsion:¶
If the calculated VaR is lower than the historical returns, it suggests that the estimated potential loss (VaR) at the specified confidence level is less than the actual historical returns observed in the portfolio.
This situation indicates that, based on the given confidence level, the portfolio has historically experienced returns that are higher than the estimated potential loss. In other words, the portfolio has historically performed better than what the VaR calculation predicts in terms of downside risk.
From a risk management perspective, this could be seen as a positive outcome as it suggests that the portfolio has been able to generate higher returns compared to the estimated downside risk. However, it's important to note that past performance does not guarantee future results, and the historical returns alone may not be a reliable indicator of future performance.
It's crucial to consider other risk measures and conduct a comprehensive risk analysis to assess the overall risk profile of the portfolio. Additionally, the VaR calculation should be reviewed and validated to ensure it accurately reflects the portfolio's risk exposure and incorporates relevant factors.