"""         Transform output into dataframe         """
agg_out = pd.DataFrame(columns = allsecurities.columns.values.tolist())
for k, v in client_portfolio.portfolio.items():
    current_security = allsecurities.loc[k].to_frame(name = allsecurities.loc[k].name).T
    agg_out = pd.concat([agg_out, current_security], axis = 0)

"""         Visualization         """    
print ("Check browser for visualization")
visual.visualize(kmean_out, option_list, 'temp-plot.html')
visual.visualize(agg_out, option_list_agg, 'temp-plot2.html')

"""         Recommendations         """
# TODO: fix data frame index - security - name confusion
option_list['Name'] = option_list.index
option_list_agg['Name'] = option_list_agg.index
#option_list.reset_index(level = 0, inplace = True)
ranked_options = rank_by_preferences([1,3,4,5,6], option_list, None, False).index.values.tolist()
ranked_options_agg = rank_by_preferences([1,3,4,5,6], option_list_agg, None, False).index.values.tolist()
print ("\nRecommendations from KMeans")
ranked_options_kmeans = pd.DataFrame(columns = Y.columns.values.tolist())
for i in range(0, len(ranked_options)):
    opt = Y.loc[ranked_options[0]]
    ranked_options_kmeans = pd.concat([ranked_options_kmeans, Y.loc[ranked_options[i]]], axis = 0)

print ("\nTop 5 recommendations from AgglomerativeClustering")
print (Y.loc[ranked_options_agg[0]])
print (Y.loc[ranked_options_agg[1]])
print (Y.loc[ranked_options_agg[2]])
print (Y.loc[ranked_options_agg[3]])
print (Y.loc[ranked_options_agg[4]])
Ejemplo n.º 2
0
''' sharpe portfolio ''' # picks stock with highest sharpe ratio
portfolio = []
for i in range(0, len(groups)):
    max_sh, idx = 0, 0
    for j in range (0, len(groups[i])):
        if stocks.iloc[groups[i][j]].Sharpe_Ratio > max_sh:
            max_sh = stocks.iloc[groups[i][j]].Sharpe_Ratio
            idx = groups[i][j]
    portfolio.append(stocks.iloc[idx].Name)
pd.Series(portfolio, name = 'Stocks').to_hdf("../../evaluation/portfolios_ml/fundamental/ml_fundamental_portfolio_kmeans_1.hdf5", "dataset1/x")
    
''' random portfolio '''
portfolio = []
for i in range(0, len(groups)):
    j = choice(groups[i])
    portfolio.append(stocks.iloc[j].Name)
pd.Series(portfolio, name = 'Stocks').to_hdf("../../evaluation/portfolios_ml/fundamental/ml_fundamental_portfolio_kmeans_2.hdf5", "dataset1/x")

''' preferences portfolio '''
portfolio = []
for i in range(0, len(groups)):
    grouped_stocks = pd.DataFrame()
    for j in range (0, len(groups[i])):
        row = stocks.iloc[groups[i][j]]
        grouped_stocks = grouped_stocks.append(row)
    ranking = rank_by_preferences(preferences, grouped_stocks, economy, False)
    portfolio.append(ranking.iloc[0].Name)
pd.Series(portfolio, name = 'Stocks').to_hdf("../../evaluation/portfolios_ml/fundamental/ml_fundamental_portfolio_kmeans_3.hdf5", "dataset1/x")
    
''' similarity portfolio '''
Ejemplo n.º 3
0
pyfancy.pyfancy().cyan("Generating random economy...").output()
economy = 'Mid'
#economy = choice(['Mid', 'Late', 'Recession', 'Early'])
if setTimer:
    time.sleep(1)
print('We are using cycle {} for economy'.format(economy))

options = [0, 1, 2, 3, 4]
compliments = [
    "Briliant!", "Well done!", "Excellent!", "Magnificent!",
    "You're investements are growing!"
]
user_in = 'start'

all_preferences = rank_by_preferences([1, 2, 3, 4, 5, 6, 7], allsecurities,
                                      economy, False).index.values.tolist()

preferences_default = True

while (user_in != 'exit'):
    print("\n")
    print(choice(compliments))
    print("What would you like to do next?..\n")
    print("1 -  Visualize portfolio")
    print("2 -  Visualize client")
    print("3 -  Set / reset preferences")
    print("4 -  Fill portfolio")
    print("5 -  Save portfolio")
    print("0 - Exit")

    user_in = [int(x) for x in input('Insert your options.. ').split()]