thk-cheng / Backtest_US_Portfolio

Backtesting my current US stocks portfolio

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Backtesting my current US stocks portfolio

The whole project is conducted under R, and the library "tidyquant" is heavily utilized.
For a quick starting guide, please refer to the vignette written by Matt Dancho
https://cran.r-project.org/web/packages/tidyquant/vignettes/TQ00-introduction-to-tidyquant.html

This backtest serves as a regular risk monitoring procedure.
As a high-level overview, below are the main steps for the backtest procedure:

  1. Current weight of the portfolio is retrieved
  2. The period for backtesting is set (Default = 3 years)
  3. Daily stock returns over the past 3 years are obtained from yahoo finance
  4. Monthly portfolio returns are calculated from the daily stock returns by the function tq_portfolio()
  5. Some ETFs/indices that serve as benchmarks are chosen and their data is obtained again through yahoo finance
  6. Various performance metrics (e.g. Historical ES, Annualized Sharpe ratio, beta) are calculated by the function tq_performance()
  7. The time series and density plots of the monthly portfolio return are generated by the function ggplot()
  8. The evolution of wealth level is also investigated for both the portfolio and the benchmark indices
  9. Detailed checks are implemented to ensure the above metrics/plots match my personal risk appetite

This project also serves as a building block for the complete portfolio analysis that will be finalized at a later stage.
Possible future projects include:

  1. Forecasting future returns using GARCH type models
  2. Rebalancing the portfolio automatically using certain kinds of indicators
  3. Conducting portfolio optimization using the dynamic programming approach
  4. Conducting portfolio optimization using LSTM or other kinds of RNN structures