Created
January 17, 2020 02:50
-
-
Save romanmichaelpaolucci/b1cfd760dff64bcb4c4f1f541fc08e8e to your computer and use it in GitHub Desktop.
Discrete Portfolio Returns
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 PortfolioReturns: | |
def __init__(self, stocks, discrete_allocation, start_date, end_date): | |
data = PortfolioDataRequest(stocks, start_date, end_date).table | |
self.start_date = start_date | |
self.end_date = end_date | |
starting_value = 0 | |
ending_value = 0 | |
for stock in stocks: | |
try: | |
# Initial value of portfolio | |
starting_value += data[stock][0]*discrete_allocation[stock] | |
# Ending portfolio value | |
ending_value += \ | |
data[stock][len(data[stock])-1]*discrete_allocation[stock] | |
except KeyError: | |
print(stock, ' received a weight of zero.') | |
continue | |
self.returns = [(ending_value - starting_value) / starting_value] | |
def report_returns(self): | |
print( | |
'Portfolio Returns for ', self.start_date, ' to ', self.end_date, | |
' are ', self.returns | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment