-
-
Save anthonymorast/e594b93651f70fc289d6660a16afa2ab to your computer and use it in GitHub Desktop.
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
import pandas as pd | |
def calculate_risk(current_ratio, quick_ratio, payout_ratio): | |
return (payout_ratio * 10) - (current_ratio + quick_ratio) | |
def calculate_return(annualized_growth_rate, div_yld, price, div_cash_flow_period): | |
total_cash_flow = 0 | |
div_amt = price * div_yld # annual | |
for _ in range(div_cash_flow_period): | |
total_cash_flow += div_amt | |
div_amt *= (1 + annualized_growth_rate) | |
return total_cash_flow / price # % return | |
def generate_pdf_from_data(data, div_cash_flow_period): | |
results = { | |
'ticker': [], | |
'expected_return': [], | |
'risk': [] | |
} | |
for ticker in data: | |
results["ticker"].append(ticker) | |
results["expected_return"].append( | |
calculate_return(data[ticker]["annualDividendGrowth"], data[ticker]["annualDividend"], data[ticker]["price"], div_cash_flow_period) | |
) | |
results["risk"].append(calculate_risk(data[ticker]["currentRatio"], data[ticker]["quickRatio"], data[ticker]["payoutRatio"])) | |
pd.DataFrame.from_dict(results).to_csv("./mpt2.csv", index=False) | |
if __name__ == '__main__': | |
div_cash_flow_period = 5 | |
data = { | |
"AAPL": { | |
"price": 145.54, | |
"annualDividend": .92, | |
"annualDividendGrowth": .10, # 10 % | |
"payoutRatio": .152, # 15.2 % | |
"currentRatio": 1.1, | |
"quickRatio": 1.0 | |
}#, | |
#... | |
} | |
generate_pdf_from_data(data, div_cash_flow_period) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment