cat("Weights for Strategy 1:\n")
for (i in 1:nrow(strategy1_selection)) {
cat(strategy1_selection$Asset[i], ":", round(weights_strategy1[i], 2), "%\n")
}
cat("\n")
Print weights for Strategy 2
cat("Weights for Strategy 2:\n")
for (i in 1:nrow(strategy2_selection)) {
cat(strategy2_selection$Asset[i], ":", round(weights_strategy2[i], 2), "%\n")
}
Global Minimum Variance Portfolio - without short selling
For GMVP, the weights are calculated based on minimizing portfolio variance
The weights are inversely proportional to the asset's risk (standard deviation)
cat("\nGlobal Minimum Variance Portfolio Weights (without short selling):\n")
for (i in 1:nrow(strategy1_selection)) {
cat(strategy1_selection$Asset[i], ":", round(gmvp_weights[i], 2), "%\n")
}
cat("\nGlobal Minimum Variance Portfolio Weights (without short selling) for Strategy 2:\n")
for (i in 1:nrow(strategy2_selection)) {
cat(strategy2_selection$Asset[i], ":", round(gmvp_weights_strategy2[i], 2), "%\n")
}
Tangency Portfolio - with short selling
For the Tangency Portfolio, weights are calculated based on maximizing the Sharpe ratio
This involves short selling to achieve the optimal risk-return trade-off
cat("\nTangency Portfolio Weights (with short selling) for Strategy 1:\n")
for (i in 1:nrow(strategy1_selection)) {
cat(strategy1_selection$Asset[i], ":", round(strategy1_tangency_weights[i], 2), "%\n")
}
cat("\nTangency Portfolio Weights (with short selling) for Strategy 2:\n")
for (i in 1:nrow(strategy2_selection)) {
cat(strategy2_selection$Asset[i], ":", round(strategy2_tangency_weights[i], 2), "%\n")
}
Portfolio Return and Risk Measures
Portfolio Return is the weighted sum of individual asset returns
cat("Tangency Portfolio Return (Strategy 2): ", round(tangency_portfolio_return_strategy2, 6), "\n")
cat("Tangency Portfolio Risk (Strategy 2): ", round(tangency_portfolio_risk_strategy2, 6), "\n")
The above is the final code i used ....now can you please give me code for For the constituted portfolio's compare and contrast the estimates of Value at Risk in "Euro" using parametric method, historical method and Monte Carlo simulation method.
Insert the code chunk below.
Certainly! Computing the Value at Risk (VaR) for a portfolio in Euros involves several steps and depends on the data you have. Below, I'll outline code samples for calculating VaR using the parametric method, the historical method, and the Monte Carlo simulation method. For these examples, assume you have returns in Euros, or you will convert them to Euros using appropriate exchange rates where necessary.
1. Parametric (Analytical) Method
This method assumes that returns are normally distributed.
# Assuming portfolio_return and portfolio_risk are in Euros
# Set the confidence level, common choices are 0.95 or 0.99
confidence_level <- 0.95
# Calculate VaR using the parametric method
VaR_parametric <- qnorm(1 - confidence_level) * portfolio_risk * -1
cat("Value at Risk (Parametric Method):", VaR_parametric, "Euros\n")
2. Historical Method
This method does not assume any distribution and uses historical returns directly.
# Assuming you have a vector of historical returns in Euros, "historical_returns"
historical_returns <- sort(historical_returns) # Ensure returns are sorted ascending
# Calculate the index of the VaR in the sorted returns
VaR_index <- ceiling((1 - confidence_level) * length(historical_returns))
# Look up the historical VaR
VaR_historical <- historical_returns[VaR_index]
cat("Value at Risk (Historical Method):", VaR_historical, "Euros\n")
3. Monte Carlo Simulation Method
This method involves simulating a large number of possible outcomes for the portfolio returns, based on the distribution of returns.
# Number of simulations
n <- 10000
# Assuming a mean and standard deviation of portfolio returns in Euros
mean_return <- portfolio_return
std_dev_return <- portfolio_risk
# Generate random draws from a normal distribution (or other distribution as necessary)
simulated_returns <- rnorm(n, mean_return, std_dev_return)
# Sort simulated returns
sorted_returns <- sort(simulated_returns)
# Identify the VaR at the specified confidence level
VaR_MonteCarlo <- sorted_returns[VaR_index]
cat("Value at Risk (Monte Carlo Simulation):", VaR_MonteCarlo, "Euros\n")
In these samples:
Adjust portfolio_return and portfolio_risk to match the specific return and risk figures of the portfolio for which you're calculating VaR.
For the historical method, historical_returns should be a vector of past returns for the portfolio, converted to Euros if not already.
The parametric method assumes normality which may not always hold, hence consider the nature of your asset returns distribution while choosing the method.
Monte Carlo simulation allows flexibility with the distribution assumption but requires computational resources for a large number of simulations to be accurate.
Remember, VaR is a measure that provides an estimate of potential losses with a certain confidence level over a specific period. Different methods may yield different VaR estimates, each with its own assumptions and limitations.