Given the complexity and specifics of the task, let's address each aspect methodically but remember, for complete solutions including data download and actual empirical calculations, these steps would need to be adapted to your specific data and scenario as we are not running actual R code here. Here's a guideline on how you could structurally approach both strategies using R:
Strategy 1: Reward to Risk Ratio
This strategy focuses on the calculation of the Reward to Risk ratio, ranking the assets based on this metric.
Step 1: Calculate Reward to Risk Ratio
# Assuming 'price_data' contains the historical prices with dates and 'annual_rf' is the risk-free rate
# Calculate log returns
returns_data <- price_data %>%
select(-Date) %>% # Excluding the 'Date' column for calculations
mutate(across(everything(), ~log(. / lag(.)))) %>%
na.omit() # Removing NAs for missing previous values in lag
# Calculate metrics
returns_metrics <- returns_data %>%
summarise(across(everything(), list(
median_ret = ~median(., na.rm = TRUE),
std_dev = ~sd(., na.rm = TRUE),
mean_ret = ~mean(., na.rm = TRUE)
)))
# Calculate Reward to Risk ratio
returns_metrics$reward_to_risk <- returns_metrics$median_ret / returns_metrics$std_dev
# Add tickers for identification
returns_metrics$ticker <- rownames(returns_metrics)
Step 2: Rank and Choose Assets
# Ranking based on Reward to Risk, breaking ties with mean return
ranked_assets <- returns_metrics %>%
arrange(desc(reward_to_risk), desc(mean_ret))
# Ensuring at least one commodity and one forex are included:
# Assuming commodities and forex tickers are identified
commodities <- c("WTI", "NG", "XAU", "W1", "EH")
forex <- c("USDINR", "EURUSD", "USDCAD", "USDCHF", "NZDUSD")
# Selecting one from each as per constraints
selected_commodity <- filter(ranked_assets, ticker %in% commodities) %>% head(1)
selected_forex <- filter(ranked_assets, ticker %in% forex) %>% head(1)
# Removing selected from the pool
ranked_assets <- filter(ranked_assets, !(ticker %in% c(selected_commodity$ticker, selected_forex$ticker)))
# Selecting the top remaining three assets
selected_others <- head(ranked_assets, 3)
# Combining selected assets
selected_assets <- rbind(selected_commodity, selected_forex, selected_others)
Exporting
write.csv(selected_assets, "Selected_Assets_Strategy1.csv")
Strategy 2: Price/Earning Ratio
This strategy focuses on the Price to Earning (P/E) ratio for asset selection.
# P_E_ratio already calculated and stored in a vector called P_E_ratio
# Convert P_E_ratio to a data frame for easy manipulation
pe_data <- as.data.frame(t(P_E_ratio))
colnames(pe_data) <- c("PE_Ratio")
pe_data$ticker <- rownames(pe_data)
# Ensure at least one commodity and one forex
# Assuming you have the commodities and forex arrays from before
selected_commodity_pe <- filter(pe_data, ticker %in% commodities) %>% arrange(PE_Ratio) %>% head(1)
selected_forex_pe <- filter(pe_data, ticker %in% forex) %>% arrange(PE_Ratio) %>% head(1)
# Removing selected from the pool and selecting the top 3 low P/E ratio assets
pe_data <- filter(pe_data, !(ticker %in% c(selected_commodity_pe$ticker, selected_forex_pe$ticker)))
selected_others_pe <- arrange(pe_data, PE_Ratio) %>% head(3)
# Combining selected assets
selected_assets_pe <- rbind(selected_commodity_pe, selected_forex_pe, selected_others_pe)
# Exporting
write.csv(selected_assets_pe, "Selected_Assets_Strategy2.csv")
These code snippets provide an outline for performing the required analyses and selections based on the two strategies mentioned. Ensure you adapt them to your specific context, especially concerning the identification of commodity and forex assets, and have the correct paths and data structures in place.