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("\nValue at Risk (Monte Carlo Simulation Method):\n")
cat("Strategy 1 Portfolio VaR: ", round(portfolio_var_montecarlo_strategy1, 6), " Euro\n")
cat("Strategy 2 Portfolio VaR: ", round(portfolio_var_montecarlo_strategy2, 6), " Euro\n")
Before this question the above coding was done...........According to the above give me code for Your supervisor is interested to identify certain factors that may be helpful to explain your Portfolio return. Henceforth, you need to identify certain factors that might influence your chosen Portfolio's and comment on the explainability of the chosen factors.
Note: Kindly mention the data source from where you have fetched data for the factors.
Hint: You have to regress your Portfolio Return on your chosen factors
Insert the code chunk below............. i have historical data of VIX and DXY_US …these are the names of file …VIX has column Date and AdjClose and DXY_US has column date and price …All this is historical monthly data between April 30, 2008, to January 29, 2021…
To perform the regression analysis to identify factors that may explain the returns of your portfolios, we will use the historical data of VIX (a measure of market volatility expectation) and DXY (the US Dollar Index, which measures the value of the US dollar against a basket of foreign currencies) as your chosen factors. The explanation of the portfolio returns through these factors might offer insights into how market volatility and the strength of the US dollar influence your portfolio's performance.
Given that your datasets are named VIX with columns Date and AdjClose, and DXY_US with columns date and price, you will first need to merge these datasets with your portfolio return datasets based on the date. Then, you can perform linear regression analysis with your portfolio returns as the response variable and VIX and DXY as explanatory variables.
Below is an R code snippet customized for your requirements. Note that the actual merging and regression might need some tweaks depending on the exact format of your date columns across all datasets.
# Assume portfolio_return_strategy1 and portfolio_return_strategy2 are your portfolio returns calculated in the previous steps
# Load the VIX and DXY_US data
VIX <- read.csv("path/to/VIX.csv", stringsAsFactors = FALSE)
DXY_US <- read.csv("path/to/DXY_US.csv", stringsAsFactors = FALSE)
# Convert date columns to Date class in all datasets
VIX$Date <- as.Date(VIX$Date, format = "%B %d, %Y")
DXY_US$date <- as.Date(DXY_US$date, format = "%B %d, %Y")
# Your portfolio returns should also have a corresponding Date column for merging
# Assuming the portfolio returns are already aligned by date and in the same frequency (monthly in this case)
# Merge VIX and DXY_US datasets on Date
market_factors <- merge(VIX, DXY_US, by.x = "Date", by.y = "date")
# Now, merge your portfolio returns for Strategy 1 and 2 with the market_factors
# Assuming portfolio_return_strategy1 and portfolio_return_strategy2 have a Date column
portfolio_and_factors_s1 <- merge(portfolio_return_strategy1, market_factors, by = "Date")
portfolio_and_factors_s2 <- merge(portfolio_return_strategy2, market_factors, by = "Date")
# Perform linear regression to identify the influence of VIX and DXY on Portfolio Returns for Strategy 1
lm_s1 <- lm(Return ~ AdjClose + price, data = portfolio_and_factors_s1)
summary(lm_s1)
# Perform the same for Strategy 2
lm_s2 <- lm(Return ~ AdjClose + price, data = portfolio_and_factors_s2)
summary(lm_s2)
# Note: Replace 'Return' in lm() with the actual column name of your portfolio returns in the merged dataset
# You might need to adjust column names and formats accordingly
Replace "path/to/VIX.csv" and "path/to/DXY_US.csv" with the actual paths to your VIX and DXY_US datasets. Also, adjust the format = "%B %d, %Y" according to the date format present in your datasets, if needed. This code assumes your portfolio return data frames (portfolio_return_strategy1 and portfolio_return_strategy2) already contain a Date column that matches the format and range of VIX and DXY_US.
This regression analysis will provide coefficients that estimate the sensitivity of your portfolio returns to changes in market volatility (VIX) and USD strength (DXY), along with statistics that indicate the explanatory power of these factors (R-squared, p-values).
Keep in mind the importance of data preprocessing to ensure the date ranges align and no NA values disrupt the analysis.