Last active
January 23, 2020 22:48
-
-
Save romanmichaelpaolucci/fe495c27407748ac2de95f627b700ede to your computer and use it in GitHub Desktop.
Portfolio Optimization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PortfolioOptimization: | |
""" | |
Class for optimizing a historic portfolio | |
""" | |
def __init__(self, table): | |
mu = expected_returns.mean_historical_return(table) | |
S = risk_models.sample_cov(table) | |
# Optimise for maximal Sharpe ratio | |
ef = EfficientFrontier(mu, S) | |
ef.max_sharpe() # Raw weights | |
self.cleaned_weights = ef.clean_weights() | |
print(self.cleaned_weights) | |
ef.portfolio_performance(verbose=True) | |
latest_prices = discrete_allocation.get_latest_prices(table) | |
self.allocation, self.leftover = discrete_allocation.portfolio( | |
self.cleaned_weights, latest_prices, total_portfolio_value=10000 # This value can be adjusted to your actual portfolio value | |
) | |
def report_discrete_allocation(self): | |
print(self.allocation) | |
print("Funds remaining: ${:.2f}".format(self.leftover)) | |
def get_cleaned_weights(self): | |
return self.cleaned_weights |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Jesus, please check my github for the comprehensive implementation
https://github.com/RomanMichaelPaolucci/Automatic_Portfolio_Optimization