Recalculate with explicit column creation for RewardToRisk assets <- assets %>%…
- User
Recalculate with explicit column creation for RewardToRisk
assets <- assets %>% mutate(RewardToRisk = MedianReturn / StandardDeviation)
Now proceed with Strategy 1 selection, ensuring the RewardToRisk column exists.
strategy1_selection <- assets %>% arrange(desc(RewardToRisk)) %>% group_by(Category) %>% mutate(rank = row_number()) %>% ungroup() %>% filter((Category == “Forex” & rank == 1) | (Category == “Commodities” & rank == 1) | Category == “Stocks”) %>% arrange(desc(RewardToRisk)) %>% head(5)
if(nrow(filter(strategy1_selection, Category == “Forex”)) < 1 || nrow(filter(strategy1_selection, Category == “Commodities”)) < 1){ print(“Adjust selection to meet criteria”) } else { print(“Strategy 1 Selection:”) print(strategy1_selection) }
Attempt Strategy 2 selection
strategy2_selection <- assets %>% arrange(PERatio) %>% group_by(Category) %>% mutate(rank = row_number()) %>% ungroup() %>% filter((Category == “Forex” & rank == 1) | (Category == “Commodities” & rank == 1) | Category == “Stocks”) %>% arrange(PERatio) %>% head(5)
if(nrow(filter(strategy2_selection, Category == “Forex”)) < 1 || nrow(filter(strategy2_selection, Category == “Commodities”)) < 1){ print(“Adjust selection to meet criteria”) } else { print(“Strategy 2 Selection:”) print(strategy2_selection) }
Export (Choose accordingly based on your selected strategy)
write.csv(strategy1_selection, “Strategy1Selection.csv”) write.csv(strategy2_selection, “Strategy2Selection.csv”) # Use write.xlsx for .xlsx files, but that requires the openxlsx or writexl package.
Continuing above Perform Data exploration {Correlation, Histogram, Q-Q plot, Box-plot} on the chosen assets for the two strategies and draw an inference from it.
Insert the code chunk below.
- Assistant
- User
USe histPlot, plot_qq, boxPlot and correlation for above code
- Assistant
- User
library(corrplot) # For correlation plots Error in library(corrplot) : there is no package called ‘corrplot’
- Assistant
It looks like you haven't installed the
corrplotpackage yet, which is why you're seeing the error when trying to load it. In R, before you can use a package that is not part of the default R installation, you need to install it first using theinstall.packages()function. This needs to be done only once (unless you're updating the package to a newer version later on). Once installed, you can load it withlibrary()each time you start a new R session and wish to use its functionality.Here's how to install and then load
corrplot:r# Install the corrplot package install.packages("corrplot") # Now, load the corrplot package library(corrplot)After running the
install.packages("corrplot")command, R will download and install the package from CRAN. Depending on your internet speed and computer, this might take a few moments. Watch the console for messages about the installation progress and for any potential errors. Common issues include network problems or lack of permission to install into the R library folder, the latter being especially relevant if you're using a shared or managed system. - User
Q4. Marks - 20 Compare the weight allocation for the assets chosen under two Strategies of Portfolio Universe Selection. Additionally comment on the Portfolio Return, Portfolio risk measures estimated while allocating weight using the Objective Function as mentioned below.
Global Minimum Variance Portfolio - without short selling Tangency Portfolio - with short selling Constituted Portfolio’s Portfolio Strategy Portfolio Objective Strategy 1 Global Minimum Variance Portfolio - without short selling Strategy 1 Tangency Portfolio - with short selling Strategy 2 Global Minimum Variance Portfolio - without short selling Strategy 2 Tangency Portfolio - with short selling Insert the code chunk below.
- Assistant