def fund_maxsemivariance(funddf): fundsemivariance = {} funddfr = funddf.pct_change().fillna(0.0) codes = funddfr.columns for code in codes: rs = [] for r in funddfr[code].values: if not isnan(r): rs.append(r) max_semivariance = 0 for i in range(5, len(rs) + 1): semivariance = fin.semivariance(rs[0 : i]) if semivariance > max_semivariance: max_semivariance = semivariance fundsemivariance[code] = max_semivariance return fundsemivariance
def fund_semivariance(funddf): fundsemivariance = {} funddfr = funddf.pct_change().fillna(0.0) codes = funddfr.columns for code in codes: rs = [] for r in funddfr[code].values: if not isnan(r): rs.append(r) fundsemivariance[code] = fin.semivariance(rs) return fundsemivariance