Skip to content

Instantly share code, notes, and snippets.

@anthonymorast
Created May 18, 2022 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthonymorast/717d17c9364795695567951c6cf22b94 to your computer and use it in GitHub Desktop.
Save anthonymorast/717d17c9364795695567951c6cf22b94 to your computer and use it in GitHub Desktop.
import pandas as pd
if __name__ == '__main__':
input_file = './lowest_risk.csv'
portfolios = pd.read_csv(input_file)
for index, row in portfolios.iterrows():
print(f"Processing portfolio {index + 1}")
print(f"\tExpected Return: {row['return']*100:.2f}%")
print(f"\t\"Risk\": {row['risk']:.2f}")
print(f"\tSelected tickers/weigts:")
weight_dict = {}
for name, data in row.iteritems():
if data > 0 and name != 'return' and name != 'risk':
weight_dict[(name.split(' ')[0])] = data
#print(f"\t\tTicker: {name.split(' ')[0]}\tWeight: {data*100:.2f}%")
weight_dict = sorted(weight_dict.items(), key=lambda x: x[1], reverse=True)
for tuple in weight_dict:
print(f"\t\tTicker: {tuple[0]}\tWeight: {tuple[1]*100:.2f}%")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment