Requirement already satisfied: networkx==2.6.3 in /root/venv/lib/python3.7/site-packages (2.6.3)
WARNING: You are using pip version 20.1.1; however, version 21.3.1 is available.
You should consider upgrading via the '/root/venv/bin/python -m pip install --upgrade pip' command.
Define time slots for training and testing (FH = First Half, SH = Second Half)
Q1: Sharpe Ratio of the Assets
Strategy 1
Q2: Pick up the top 4-5 assets with the highest Sharpe Ratios for the training set
Q3: Calculate the covariance matrix for these assets.
Q4: Make an equal weight portfolio of these assets and test their performance on your testing data now.
Std Portfolio (Training Data): 0.03851472544817102
Annual Return Portfolio (Training Data): 0.1081562868372679
Sharpe Ratio (Training Data): 2.8081801331496705
Std Portfolio (Test Data): 0.05800265411156607
Annual Return Portfolio (Test Data): 0.02994088701938935
Sharpe Ratio (Test Data): 0.5161985684620415
Strategy 2
Q5: Pick up the top 200 assets with the highest Sharpe Ratios for the training set.
Q6: Run the Minimum Spanning Tree method on this set a number of times until you have only about 4-5 assets left.
Assets left after run 1 : 105
Assets left after run 2 : 55
Assets left after run 3 : 29
Assets left after run 4 : 12
Assets left after run 5 : 7
Assets left after run 6 : 2
Number of runs: 6
Assets in the end:
Index(['DK0060158590', 'IE00B2QWCY14'], dtype='object')
After running the MST for 6 times with the condition "assets left > 4", only 2 assets are left. Hence, we re-run it with a condition of "assets left > 7" to stop the code after the fifth run and work with the remaining 7 assets (see output above).
Assets left after run 1 : 105
Assets left after run 2 : 55
Assets left after run 3 : 29
Assets left after run 4 : 12
Assets left after run 5 : 7
Number of runs: 5
Assets in the end:
Index(['DK0016272602', 'DK0060158590', 'DK0010106111', 'IE00B2QWCY14',
'DK0060188902', 'DK0060498509', 'LU1028171848'],
dtype='object')
Q7: Calculate the covariance matrix for these assets now and compare with the covariance matrix from strategy 1.
Covariance matrix STRATEGY 1:
Covariance matrix STRATEGY 2:
OBSERVATIONS:
Q8: Make an equal weight portfolio of these assets and test their performance on your testing data now.
Std Portfolio (Training Data): 0.08124555846807419
Annual Return Portfolio (Training Data): 0.15687144976855813
Sharpe Ratio (Training Data): 1.930831084510318
Std Portfolio (Test Data): 0.10308362222274055
Annual Return Portfolio (Test Data): 0.08006564056056129
Sharpe Ratio (Test Data): 0.7767057349571732
Q9: Calculate average return, std for the two strategies and compare.
STRATEGY 2: Std Portfolio: 0.10308362222274055 Annual Return Portfolio: 0.08006564056056129
STRATEGY 1: Std Portfolio: 0.05800265411156607 Annual Return Portfolio: 0.02994088701938935
Q10: Calculate and compare the Sharpe ratio for the two strategies.
STRATEGY 2: Sharpe Ratio: 0.7767057349571732
STRATEGY 1: Sharpe Ratio: 0.5161985684620415
Q11: Calculate and compare maximum drawdown for the two strategies.
Strategy 3
Q12: Run the Hierarchical Clustering method on this set to make three clusters.
Q13: Pick the asset with the highest Sharpe ratio from the two smaller clusters.
Q14: Run the Minimum Spanning Three method on the biggest cluster a number of times until you are left with 3-4 assets only.
Assets left after run 1 : 58
Assets left after run 2 : 33
Assets left after run 3 : 18
Assets left after run 4 : 11
Assets left after run 5 : 7
Assets left after run 6 : 5
Assets left after run 7 : 4
Number of runs: 7
Assets in the end:
Index(['DK0016272602', 'DK0060497378', 'DK0060786994', 'LU1028171848'], dtype='object')
Q15: Calculate the covariance matrix for these assets now and compare with the covariance matrix from strategy 1 and 2.
Cov Matrix Strategy 3
Cov Matrix Strategy 2
Cov Matrix Strategy 1
Q16: Make an equal weight portfolio of these assets and test their performance on your testing data now.
Std Portfolio (Training Data): 0.08987856973738308
Annual Return Portfolio (Training Data): 0.1863151926734649
Sharpe Ratio (Training Data): 2.0729657049267782
Std Portfolio (Test Data): 0.11456401518379115
Annual Return Portfolio (Test Data): 0.09144362888168733
Sharpe Ratio (Test Data): 0.798188058745911
Q17: Calculate average return, std for the two strategies and compare
STRATEGY 2: Std Portfolio: 0.10308362222274055 Annual Return Portfolio: 0.08006564056056129
STRATEGY 3: Std Portfolio: 0.11456401518379115 Annual Return Portfolio: 0.09144362888168733
Q18: Calculate and compare the Sharpe ratio for the two strategies
STRATEGY 3: Sharpe Ratio: 0.798188058745911
STRATEGY 2: Sharpe Ratio: 0.7767057349571732