joelowj / Machine-Learning-and-Reinforcement-Learning-in-Finance

Machine Learning and Reinforcement Learning in Finance New York University Tandon School of Engineering
246 stars 120 forks source link

Eigen Portfolio construction via PCA (75/100) #4

Closed joelowj closed 5 years ago

joelowj commented 6 years ago

Current submission

Asset Returns Calculation 15/15 Calculate Variances of Returns 15/15 Eigen Portfolio Weights 15/15 Second Eigen Portfolio Weights 15/15 Eigen Portfolios: Sorted by Sharpe Ratio 25/25 Portfolio with the Highest Sharpe Ratio 15/15

Having issue clearing the grader for sorted by Sharpe ratio. The sorted sharpe ratio portfolio I am getting is 42, 104, 2, 94, 9, ... We know that 42 is definitely right, since 42 cleared the section of Portfolio with the Highest Sharpe Ratio.

joelowj commented 5 years ago

e97d5cdadd4824d1ad3e566df8c0568742f0e39b, managed to cleared Eigen Portfolios: Sorted by Sharpe Ratio by changing the calculation for annualized_return from

annualized_return = ts_returns.mean() * periods_per_year

to

n_years = ts_returns.shape[0] / periods_per_year annualized_return = np.power(np.prod(1 + ts_returns),(1 / n_years)) - 1

However, results will have NaN value which I then used results.dropna(inplace=True) to remove the NaN value. This helps to cleared Eigen Portfolios: Sorted by Sharpe Ratio but Portfolio with the Highest Sharpe Ratio would fail the grader. This can be easily resolved by using

idx_highest_sharpe = np.nanargmax(sharpe_metric)

to obtained the idx with the highest sharpe instead of

idx_highest_sharpe = np.argmax(sharpe_metric).