def top_N_bias(bias_dict, df, save_path, N): ## top N bias sorted_bias_dict = dict(sorted(bias_dict.items(), key=operator.itemgetter(1), reverse=False)[:N]) for fund_name in sorted_bias_dict: print fund_name ma_dict, df_period, df_short = f.MA(fund_name,df) rate = sorted_bias_dict[fund_name] f.plot_line(fund_name,str(rate)+'_'+fund_name, df_period, df_short, save_path)
print attr[2], attr[0], row[attr[2]], row[attr[0]] print '--index--' biasF_rate_dict = BIAS_ratio(indexF_list, three_year, 20) top_N_bias(biasF_rate_dict, three_year, 'Foreign/output/index', 60) print '--stock--' biasF_rate_dict = BIAS_ratio(stockF_list, three_year, -4) top_N_bias(biasF_rate_dict, three_year, 'Foreign/output/stock', 60) print '--balance--' biasF_rate_dict = BIAS_ratio(balanceF_list, three_year, 0) top_N_bias(biasF_rate_dict, three_year, 'Foreign/output/balance', 60) #print '--bond--' #biasF_rate_dict = BIAS_ratio(bondF_list, three_year, 0) #top_N_bias(biasF_rate_dict, three_year, 'Foreign/output/bond', 60) print '-------------targeted-------------' ## bought Foreign necessary = ['富蘭克林坦伯頓全球投資系列-全球平衡基金美元A(Qdis)股','富達基金-新興歐非中東基金(美元)','富蘭克林坦伯頓全球投資系列-亞洲成長基金美元A(Ydis)股','富蘭克林坦伯頓全球投資系列-全球債券總報酬基金美元A(acc)股'] for name in necessary: ma_dict, df_period, df_short = f.MA(name,three_year) f.plot_line(name,name,df_period,df_short,'Foreign/output/observation')