Giter VIP home page Giter VIP logo

fedepepe / portfoliostrategybacktestus Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 3.0 7.25 MB

Master thesis project. The improved estimator of the covariance matrix of asset returns is employed to derive a new trading strategy based on a two-step procedure. First, it shrinks the asset universe via a subset selection, leaving only the most suitable assets. Then, it performs the mean-variance analysis. Back-testing is carried out in the U.S. stock market between 2018 and 2020. For comparison purposes, the code also implements also other strategies, such as the widely-used momentum strategy. The proposed technique is observed to deliver a very good and much more stable performance with respect to its competitors.

Python 100.00%
portfolio-construction portfolio-optimization asset-allocation trading-strategies backtesting-trading-strategies

portfoliostrategybacktestus's Introduction

Description

This project implements and backtests a long-only portfolio strategy based on a two-step procedure: in the first one, the algorithm screens the stock data in a rolling window to select a user-defined number of optimal ones, and, in the second, computes the portfolio allocation, using either Markowitz' mean-variance analysis or empirics. In this way, a potentially very large asset universe is shrunk to a few tens of assets, which dramatically reduces the estimation error of the covariance matrix of asset returns.

I perform the asset selection by recasting the Markowitz’ risk minimization problem as a regression problem, as explained in: Fan, J. and Zhang, J. and Yu, K. (2021). Vast Portfolio Selection with Gross-Exposure Constraints. Journal of the American Statistical Association, 107(498):592-606. This enables us to access the vast statistical toolbox associated to regression.

I build upon the approach presented in: Dan Wang, C. and Chen, Z. and Lian Y. and Chen M. (2020). Asset Selection based on High Frequency Sharpe Ratio. Journal of Econometrics, and I further enhance it by adopting the improved covariance matrix estimator, tested in the code in the ImprovingMVPortfolio repository.

The performance of the strategy is compared against the widely-used momentum strategy, its risk-managed counterpart and Dan Wang's method, which are all implemented in the code. The momentum strategy is presented in: Jegadeesh, N. and Titman, S. (1993). Returns to Buying Winners and Selling Losers: Implications for Stock Market Efficiency. Journal of Finance, 48:65–91. For risk-managed momentum, please refer to: Barroso, P. and Santa-Clara, P. (2015). Momentum Has Its Moments. Journal of Financial Economics, 116(1):111–120.

The dataset consists of daily closing prices and realized volatilities observed for U.S. stocks listed in the SP500 index in the time frame spanning between 1/1/2018 and 25/8/2020, including the market collapse due to COVID-19 pandemic.

Back-testing parameters

They are located in the main() method in main.py

endow: (optional) Initial amount of money to be invested. Float

n_stk: Number of stocks to hold in the portfolio. Integer

n_obs_ar: Lengths of rolling window (in trading days). Array of integers

n_reb_ar: Portfolio rebalancing interval (in trading days). Array of integers

algo: Algorithm to use for stock selection. String. Possible choices are: 'mtm', 'rmmtm', 'sev' or 'sev+'

  • mtm: Momentum. Pick stocks with largest value of average return
  • rmmtm: Risk-managed Momentum. Pick stocks with largest value of average Sharpe ratio
  • sev: Dan Wang's stock selection method
  • sev+: Improved Dan Wang's method

wght_mtd: Stock weighting methods for portfolio allocation. List of strings. Possible choices are: 'equal', 'metric', 'mktcap', 'riskpar', 'lotp', 'tp'

  • equal: Equally-weighted portfolio
  • metric: Weights are proportional to momentum or SEV
  • mktcap: Weights are proportional to market capitalization
  • riskpar: Risk-parity portfolio
  • tp: Tangency Portfolio (obtained via mean-variance analysis)
  • lotp: Long-Only Tangency Portfolio (obtained via mean-variance analysis)

trsctn_fee_fix: (optional) Fixed transaction fees

trsctn_fee_prop: (optional) Proportional transaction fees

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.