tradytics / eiten

Statistical and Algorithmic Investing Strategies for Everyone
https://www.tradytics.com/
GNU General Public License v3.0
2.75k stars 323 forks source link

Comparison of Portfolio Weights and issue with "only_long" #15

Open sarvotham opened 3 years ago

sarvotham commented 3 years ago

@tradytics

Firstly, thank you for putting this together. I've been working on portfolio optimization through backtesting and this is definitely a simple and great setup. As I was testing your code, I wanted to call out a few things,

  1. The only_long setting does not work. Irrespective of whether this is set to 0 or 1, the resulting weights are long_short lying between (-1, 1). This is the exact command i used as per your description: python portfolio_manager.py --is_test 1 --future_bars 90 --data_granularity_minutes 3600 --history_to_use all --apply_noise_filtering 1 --market_index SPY --only_long 0 --eigen_portfolio_number 3 --stocks_file_path stocks/stocks.txt I only changed only_long to 1 or 0 in my tests and it doesn't alter the weights. Let me know if I'm doing something wrong.

  2. I then used the weights that were returned by your algorithm and plotted it on the efficient frontier created with over 150,000 portfolios (from random weights) on the same ohlc dataset. Below are the weights from your algorithm,

-------- Weights for Eigen Portfolio --------
Symbol: AAPL, Weight: 0.3492
Symbol: AMD, Weight: -0.7297
Symbol: AMZN, Weight: 0.3650
Symbol: FB, Weight: 0.4094
Symbol: MSFT, Weight: 0.3314
Symbol: NFLX, Weight: 0.7475
Symbol: NVDA, Weight: 1.0672
Symbol: TSLA, Weight: -1.5400

-------- Weights for Maximum Sharpe Portfolio (MSR) --------
Symbol: AAPL, Weight: 0.6987
Symbol: AMD, Weight: -0.1833
Symbol: AMZN, Weight: -0.9613
Symbol: FB, Weight: 0.7741
Symbol: MSFT, Weight: 0.7640
Symbol: NFLX, Weight: -0.2281
Symbol: NVDA, Weight: -0.1171
Symbol: TSLA, Weight: 0.2530

-------- Weights for Genetic Algo (GA) --------
Symbol: AAPL, Weight: -1.2315
Symbol: AMD, Weight: 0.9703
Symbol: AMZN, Weight: 1.3787
Symbol: FB, Weight: -1.1198
Symbol: MSFT, Weight: 1.9202
Symbol: NFLX, Weight: 0.2728
Symbol: NVDA, Weight: 0.9967
Symbol: TSLA, Weight: 0.0455

This is what the efficient frontier looks like for the above weights with the backtest data: image

For the portfolios returned by your max sharpe (Eiten max sharpe) and Eigen (Eiten Eigen PF) the sharpe ratios are 0.07 and 0.15 respectively. As you can see, the genetic algorithm weights returned a sharpe ratio of 1.78 and the starred max_sharpe is 1.63 (close, but definitely more room for optimization). The starred max_sharpe is just the best performing random weight portfolio. We can nearly draw a straight line from the risk free return to the GA point cutting through the starred max_sharpe points. I guess the GA has only cranked up the risk for higher returns.

Similary the EF for the future data is as shown below and the max_sharpe in this case is 3.78 (from random weights): image

Let me know if i'm doing anything wrong running this as the performance of max sharpe and eigen portfolio from your algorithm does not correspond to the best performing portfolio even in the back testing case. There is still room to reduce risk and increase returns here.

tradytics commented 3 years ago

Some excellent feedback here. Let me go through all your points and get back to you.

silvavn commented 3 years ago

@sarvotham the problem with only long that it is only applied in the backtest. For you to see the weights they would have to be applied by each strategy individually.