def LPSD_f(returns, Rf): y=returns[returns-Rf<0] m=len(y) total=0.0 for i in sp.arange(m): total+=(y[i]-Rf)**2 return total/(m-1)