Introduction

Throughout this document I will be going over the performance of Key market data of indexes that I gathered from seeking alphas “Key Market ETFs” section. By creating equally weighted portfolios utilizing the ETFs you will be able to see the overall performance of each market. Retail Investors would be able to use this information to quickly load and visualize the data to enhance their risk management and potentially find arbitrage opportunities.

About me

My name is Henry Bowers, I graduated from CUNY Baruch College, Zicklin School of Business with a Bachelors of Business Administration in Finance & Investments. I have always had an interest in learning data science for finance to make better informed investment decisions. After taking online courses through Data Camp and reading many articles on R for finance. I decided to take a capstone course in financial econometrics, which was my favorite course in college. Throughout the class I was able to learn even more about risk management and data visualization of time series. I have a growing passion for understanding data science for finance and applying those skills to make better-informed investment decisions for my personal portfolio using computational finance strategies with R programming. Skills I developed include multi-asset portfolio construction, optimization, and quantitative risk management.

Linkedin: https://www.linkedin.com/in/henry-bowers/

Disclosures

Data gathered for research has been downloaded from yahoo finance API, there is other sources to obtain data if you want to pay for a service. for retail investors obtaining data through yahoo finance is one of the best options. Historical returns are also not predictors of future performance. If you decide to run this code at a later date since I did not set an ending date, the data would be gathered from the beginning of the time series up to the present day. Therefore performance of indexes, and statistical measures will change as time goes on. I made this script like this because I wanted this to be a tool to monitor performance form 2019 to the present day of whenever I am running this code again.

U.S Equities Market Performance

Seeking Alpha listed the SP500, Dow Jones, Nasdaq, Mid cap, Small cap and Micro cap ETFs as general measures to view the U.S. Market Equities performance. by utilizing getsymbols from the quantmod library we could download asset data directly from yahoo finance. After getting the data from yahoo finance, in order to proceed with the analysis we first need to get the adjusted close prices. Adjusted close prices takes into considerations of dividends and stock splits which is crucial to take into consideration of visualizing asset time series data. Once we have our prices in a dataframe, the next step would be to calculate the returns of assets. R makes this easily by applying the Return.Calculate function and specifying log returns. after we have our log returns we can proceed to calculating the equal weights of each asset and the calculating the portfolio return. Reason to why I am using equally weighted portfolio as an index instead of assigning weights to each asset is because, assigning equal weights would give the investors a better visual of how well the portfolio actually return over time. For the other markets I will be following the steps mentioned above.

Seeking Alphas Key Market data: https://seekingalpha.com/etfs-and-funds/etf-tables/key_markets

For more information on equally weighted portfolios, The Financial Times posted an amazing article in 2010, https://www.ft.com/content/45618282-d886-11df-8e05-00144feabdc0


US.tickers <- c("SPY", "DIA", "QQQ", "MDY", "IJR", "IWC")

getSymbols(US.tickers, from = "2019-1-1", periodicity = "daily")
[1] "SPY" "DIA" "QQQ" "MDY" "IJR" "IWC"
US.prices <- merge(Ad(SPY), Ad(DIA), Ad(QQQ), Ad(MDY), Ad(IJR), Ad(IWC))

colnames(US.prices) <- US.tickers

US.ret <- Return.calculate(US.prices, method = "log")[-1]

US.weights <- rep(1 / ncol(US.ret), ncol(US.ret))

US_Equities.Port <- Return.portfolio(US.ret, weights = US.weights, rebalance_on = "years")                         

colnames(US_Equities.Port) <- "U.S. Equities"

p1 <- chart.CumReturns(US_Equities.Port, plot.engine = "ggplot2") + theme_classic() + 
  labs(title = "U.S. Equities Portfolio", x = "Date", y = "Cumulative Returns") + 
  scale_y_continuous(labels = scales::percent, breaks = seq(-1,2,0.20))

p2 <- chart.Drawdown(US_Equities.Port, plot.engine = "ggplot2") + theme_classic() + 
  labs(x = "Date", y = "Drawdown", caption = "Data Source: Yahoo Finance") + 
  scale_y_continuous(labels = scales::percent)

grid.arrange(p1, p2)

Since 2019 the U.S. equities portfolio has reach an high of a cumulative return of 75% meanwhile reaching a cumulative loss of -25% during the heart of the pandemic. However the U.S. Equities Portfolio despite global tensions is still trading higher then it was in 2020. Drawdowns represent the amount of loss from the high to low, Investors could take note that the U.S. equities portfolio had a drawdown of 40% during the heart of the pandemic and at the time I made this script has reached roughly 20% in drawdowns because of global tensions and fear of potentially another recession.


table.AnnualizedReturns(US_Equities.Port, Rf = 0.0303/252, digits = 2)
                             U.S. Equities
Annualized Return                     0.12
Annualized Std Dev                    0.24
Annualized Sharpe (Rf=3.03%)          0.34

At the time I made this script the 10 year treasury had a rate of 3.03%, therefore given the U.S. Equities Portfolio Annualized Return and Standard Deviation the volatility of the stock, the Sharpe ratio is 0.34. In accordance to with modern portfolio theory by Harry Markowitz if an investment portfolio has a Sharpe ratio less then 1 it would mean the portfolio is bad and is not worth the investment opportunity given the level of risk.

Global Equities Market Performance


Global.tickers <- c("ACWI", "ADRE", "SPDW", "VEA", "IEFA")

getSymbols(Global.tickers, from = "2019-1-1", periodicity = "daily")
[1] "ACWI" "ADRE" "SPDW" "VEA"  "IEFA"
Global.prices <- merge(Ad(ACWI), Ad(ADRE), Ad(SPDW), Ad(VEA), Ad(IEFA))

colnames(Global.prices) <- Global.tickers

Global.ret <- Return.calculate(Global.prices, method = "log")[-1]

Global.weights <- rep(1 / ncol(Global.ret), ncol(Global.ret))

Global_Equities.Port <- Return.portfolio(Global.ret, weights = Global.weights, rebalance_on = "years")

colnames(Global_Equities.Port) <- "Global Equities"

p3 <- chart.CumReturns(Global_Equities.Port, plot.engine = "ggplot2") + theme_classic() + 
  labs(title = "Global Equities Portfolio", x = "Date", y = "Cumulative Returns") + 
  scale_y_continuous(labels = scales::percent, breaks = seq(-1,2,0.10)) 

p4 <- chart.Drawdown(Global_Equities.Port, plot.engine = "ggplot2") + theme_classic() + 
  labs(x = "Date", y = "Drawdown", caption = "Data Source: Yahoo Finance") + 
  scale_y_continuous(labels = scales::percent)

grid.arrange(p3, p4)

When looking at the global equities portfolio performance we could notice they have a similar return pattern compared to the U.S. equities portfolio, however the global equities portfolio reached a high of nearly 50% cumulative returns, meanwhile reaching cumulative losses of -20%. Most drawdowns the global equity portfolio experience was -30% and that was during the beginning of COVID-19 when it first hit the market.


table.AnnualizedReturns(Global_Equities.Port, Rf = 0.0303/252, digits = 2)
                             Global Equities
Annualized Return                       0.07
Annualized Std Dev                      0.21
Annualized Sharpe (Rf=3.03%)            0.16

Taking a look at the Sharpe ratio for the global equities portfolio, it is far lower then that of the U.S. equities portfolio, showcasing a Sharpe ratio of 0.16. Since global tensions are affecting the market more, equities outside of then U.S. are being more affected by the war in Ukraine leading to higher volatility and much lower returns.

Bond Market Performance


Bonds.tickers <- c("TLT", "BND", "TIP", "PHB", "BWX")

getSymbols(Bonds.tickers, from = "2019-1-1", periodicity = "daily")
[1] "TLT" "BND" "TIP" "PHB" "BWX"
Bonds.prices <- merge(Ad(TLT), Ad(BND), Ad(TIP), Ad(PHB), Ad(BWX))

colnames(Bonds.prices) <- Bonds.tickers

Bonds.ret <- Return.calculate(Bonds.prices, method = "log")[-1]

Bonds.weights <- rep(1 / ncol(Bonds.ret), ncol(Bonds.ret))

Bonds.Port <- Return.portfolio(Bonds.ret, weights = Bonds.weights, rebalance_on = "years")

colnames(Bonds.Port) <- "Bonds"

p5 <- chart.CumReturns(Bonds.Port, plot.engine = "ggplot2") + theme_classic() + 
  labs(title = "Bonds Portfolio", x = "Date", y = "Cumulative Returns") + 
  scale_y_continuous(labels = scales::percent, breaks = seq(-1,2,0.05))

p6 <- chart.Drawdown(Bonds.Port, plot.engine = "ggplot2") + theme_classic() + 
  labs(x = "Date", y = "Drawdown", caption = "Data Source: Yahoo Finance") + 
  scale_y_continuous(labels = scales::percent)

grid.arrange(p5, p6)

Bonds as we are taught are suppose to be the safe investment oppose to equities, when equities go down, bonds should rise right? Looking back since 2019 Investing into this particular bond index portfolio would not have been a bad choice. 20% cumulative growth is better then nothing. However because of global tensions, there is a massive fear of defaults amongst corporations and potentially another recession coming. Bonds have also reached the same level they were once at before during the heart of the pandemic.


table.AnnualizedReturns(Bonds.Port, Rf = 0.0303/252, digits = 2)
                             Bonds
Annualized Return             0.01
Annualized Std Dev            0.07
Annualized Sharpe (Rf=3.03%) -0.32

Bond portfolio has a negative Sharpe Ratio ratio reaching -0.32, indicating a clear standpoint to stay away from the portfolio since the risk free rate is generating higher returns.

Commodity Market Performance

Now we gonna dive into an interesting index, commodities. I should note that the ETFs listed below trades futures of commodities. Futures is an interesting topic, in short futures contracts are expectations of prices. Simple example, say you expect gas prices to rise to hedge against this you could buy futures of oil and if oil rises, then you will make profit. This is a very simple textbook example, in the real world it gets more complicated than that.


Commodities.tickers <- c("DBB", "GLD", "SLV", "PPLT", "DBA", "DBO", "UNG", "CORN", "SOYB")

getSymbols(Commodities.tickers, from = "2019-1-1", periodicity = "daily")
[1] "DBB"  "GLD"  "SLV"  "PPLT" "DBA"  "DBO"  "UNG"  "CORN" "SOYB"
Commodities.prices <- merge(Ad(DBB), Ad(GLD), Ad(SLV), Ad(PPLT), Ad(DBA), Ad(DBO), Ad(UNG), Ad(CORN), Ad(SOYB))

colnames(Commodities.prices) <- Commodities.tickers

Commodities.ret <- Return.calculate(Commodities.prices, method = "log")[-1]

Commodities.weights <- rep(1 / ncol(Commodities.ret), ncol(Commodities.ret))

Commodities.Port <- Return.portfolio(Commodities.ret, weights = Commodities.weights, rebalance_on = "years")

colnames(Commodities.Port) <- "Commodities"

p7 <- chart.CumReturns(Commodities.Port, plot.engine = "ggplot2") + theme_classic() + 
  labs(title = "Commodities Portfolio", x = "Date", y = "Cumulative Returns") + 
  scale_y_continuous(labels = scales::percent, breaks = seq(-1,2,0.10))

p8 <- chart.Drawdown(Commodities.Port, plot.engine = "ggplot2") + theme_classic() + 
  labs(x = "Date", y = "Drawdown", caption = "Data Source: Yahoo Finance") + 
  scale_y_continuous(labels = scales::percent)

grid.arrange(p7, p8)

Because of global tensions, with the war in ukraine, prices are increasing, especially as some of us may be hurting by is the price of oil. As oil prices increases, the futures expectations of oil will generally increase as well. Since a lot of the U.S. oil companies have ended doing business with Russia for their unethical acts for starting a meaningless war, prices of oil have shot up in value. Therefore leading to a large increase in cumulative performance for this portfolio.


table.AnnualizedReturns(Commodities.Port, Rf = 0.0303/252, digits = 2)
                             Commodities
Annualized Return                   0.12
Annualized Std Dev                  0.16
Annualized Sharpe (Rf=3.03%)        0.57

Astonishing to find out how Commodities have achieved a much higher Sharpe ratio compared to all the other portfolios mentioned, however it is still below 1. Given the level of risk, commodities portfolio is producing better risk adjusted returns.

Comparing top 3 portfolios


top3.returns <- cbind(US_Equities.Port, Global_Equities.Port, Commodities.Port)


p9 <- chart.CumReturns(top3.returns, plot.engine = "ggplot2") + theme_classic() + 
  labs(title = "Top 3 Portfolio Performance", x = "Date", y = "Cumulative Returns") + 
  scale_y_continuous(labels = scales::percent, breaks = seq(-1,2,0.20))

p10 <- chart.Drawdown(top3.returns, plot.engine = "ggplot2") + theme_classic() + 
  labs(x = "Date", y = "Drawdown", caption = "Data Source: Yahoo Finance") + 
  scale_y_continuous(labels = scales::percent)

grid.arrange(p9, p10)

Throughout the time series, U.S. Equities and global equities have outperformed the commodities portfolio. however there is something to notice. Although they have been outperforming, the commodities portfolio has historically been increasing slowly and when looking at the present day, the commodities portfolio has started to outperform the global equities portfolio and reach the same level of the U.S. equities portfolios. If the commodities portfolio continues to grow at the rate it is now and the U.S. Equities portfolio continues to decline at his current rate, I wont be shocked to find out that a simple portfolio of commodity ETFs are outperforming the broad market of U.S. equities.


table.AnnualizedReturns(top3.returns, Rf = 0.0303/252, digits = 2)
                             U.S..Equities Global.Equities Commodities
Annualized Return                     0.12            0.07        0.12
Annualized Std Dev                    0.24            0.21        0.16
Annualized Sharpe (Rf=3.03%)          0.34            0.16        0.57

Interesting to find out that the U.S equities and commodities portfolio have reached the same annualized return, yet because the commodities portfolio is experiencing lower levels of volatility it has also achieved a higher Sharpe ratio.

Testing a Strategy

Looking at the portfolio returns, the best performing portfolios at the time of this data is U.S. equities and commodities. Next I will construct a simple equally weighted portfolio combining U.S. equities mixed with commodities and then backtesting the performance against U.S. equities portfolio acting as our benchmark for this test.


strategy.ret <- merge(US_Equities.Port, Commodities.Port)

strategy.weights <- rep(1 / ncol(strategy.ret), ncol(strategy.ret))

strategy.Port <- Return.portfolio(strategy.ret, weights = strategy.weights, rebalance_on = "years")

colnames(strategy.Port) <- "Strategy"

stratVBM <- cbind(strategy.Port, US_Equities.Port)

p11 <- chart.CumReturns(stratVBM, plot.engine = "ggplot2") + theme_classic() + 
  labs(title = "Strategy Vs Benchmark", x = "Date", y = "Cumulative Returns", subtitle = "Benchmark = U.S. Equities") + 
  scale_y_continuous(labels = scales::percent, breaks = seq(-1,2,0.20))

p12 <- chart.Drawdown(stratVBM, plot.engine = "ggplot2") + theme_classic() + 
  labs(x = "Date", y = "Drawdown", caption = "Data Source: Yahoo Finance") + 
  scale_y_continuous(labels = scales::percent)

grid.arrange(p11, p12)

As we can take note, the benchmark has outperformed throughout the years compared to the strategy, however when looking at the current performance, the strategy officially outperform the benchmark slightly. This is due to the fact of commodities increasing which increased the portfolio overall return.


table.AnnualizedReturns(stratVBM, Rf = 0.0303/252, digits = 2)
                             Strategy U.S..Equities
Annualized Return                0.13          0.12
Annualized Std Dev               0.17          0.24
Annualized Sharpe (Rf=3.03%)     0.56          0.34

Finally arrive at a conclusion, the strategy outperformed by 1%, yet having a higher Sharpe ratio as well.

Correlations

In statistics we learned the importance of correlation which is testing to find if variables have a relationship to each other. In finance a correlation matrix is used to test the relationships of returns between assets.


rets <- cbind(strategy.Port, Commodities.Port, US_Equities.Port, Global_Equities.Port, Bonds.Port)

asset_rets = cor(rets)
corrplot(asset_rets, method = 'number') 

From this correlation matrix, can notice how the strategy has a high correlation towards the U.S. equities portfolio. This would simply mean that when the U.S. equities portfolio declines or increases there is very high chance that the strategy portfolio would also follow this trend since it has a correlation to the U.S. equities portfolio of 0.90.

Expected Shortall

Expected shortfall (ES) also known as Conditional Value at risk (CVaR) or even Expected Tail Loss (ETL), is the expected potential losses of an asset based on the returns. I will be showcasing the modified method of CVaR since it takes into consideration of the higher moments of non normal distributions i.e skewness and kurtosis. when calculating CVaR or ETL we need to set an argument for the probability level. I will be using a P-value of 0.99 as a confidence interval to showcase the absolute worse case scenario of losses for the assets.


CVaR.Mod <- CVaR(rets, p = 0.99, method = "modified")

CVaR <- data.frame(CVaR.Mod)

rownames(CVaR) <- "Mod99"

CVaR <- abs(CVaR)

CVaR$Type <- "Mod99"


plotCVaR <- melt(CVaR, variable.name = "Portfolios", value.name = "CVaR")
plotCVaR
   Type      Portfolios       CVaR
1 Mod99        Strategy 0.05771255
2 Mod99     Commodities 0.03338038
3 Mod99   U.S..Equities 0.08932980
4 Mod99 Global.Equities 0.08343386
5 Mod99           Bonds 0.02835277
ggplot(plotCVaR, aes(x = Type, y = CVaR, fill = Portfolios)) +
  geom_bar(stat = "identity", position = "dodge") +
  labs(title = "Portfolios Expected Losses",
       caption = "Data Source: Yahoo Finance", x = "CVaR Modified") +
  scale_fill_brewer(palette = "Set3") +
  scale_y_continuous(labels = scales::percent) +
  theme_classic()

When it comes to which portfolio may experience higher potential losses, have to remember that these are expected values and they are not 100% accurate. However they could be very close. Based off this analysis of CVaR, the U.S. equities portfolio and global equities portfolio may experience the higher losses both around 8%, Meanwhile the strategy portfolio has potential loss of nearly 6% in value.