def sortinofilter(funddf, rf, ratio): funddfr = funddf.pct_change().fillna(0.0) indexdfr = funddf.pct_change().fillna(0.0) sortino = {} cols = funddfr.columns for col in cols: p = [] rs = funddfr[col].values for i in range(0, len(rs)): if isnan(rs[i]): continue else: p.append(rs[i]) sortino[col] = fin.sortino(p, rf) x = sortino sorted_x = sorted(x.iteritems(), key=lambda x : x[1], reverse=True) sorted_sortino = sorted_x result = [] for i in range(0, (int)(len(sorted_sortino) * ratio)): result.append(sorted_sortino[i]) return result
def sortinomeasure(funddf, rf): funddfr = funddf.pct_change().fillna(0.0) indexdfr = funddf.pct_change().fillna(0.0) sortino = {} cols = funddfr.columns for col in cols: p = [] rs = funddfr[col].values for i in range(0, len(rs)): if isnan(rs[i]): continue else: p.append(rs[i]) sortino_value = fin.sortino(p, rf) #if np.isinf(sortino_value): # continue sortino[col] = sortino_value return sortino
for i in range(1, len(indexvs)): indexrs.append(indexvs[i] / indexvs[i-1] - 1) rf = 0.025 / 52 jensen = {} sortino = {} for code in fundrs.keys(): rs = fundrs[code] if len(rs) < len(indexrs): continue jensen[code] = fin.jensen(rs, indexrs, rf) sortino[code] = fin.sortino(rs, rf) #print jensen[codes[i]] #print sortino[codes[i]] #print jensen #print sortino #print dates x = jensen sorted_x = sorted(x.iteritems(), key=lambda x : x[1], reverse=True) sorted_jensen = sorted_x x = sortino sorted_x = sorted(x.iteritems(), key=lambda x : x[1], reverse=True)