The calculation of downside in rolling_sortino() is incorrect because it calculates the downside for the entire series of returns, not just for the rolling period. A correct calculation would be something like this:
downside = returns.rolling(rolling_period).apply(lambda x: (x[x < 0]**2).sum())/rolling_period
This will be slower than other approaches, but I wanted to provide a simple example to illustrate the issue.
Line of code referenced: 7156af7#r57724791
The calculation of downside in
rolling_sortino()is incorrect because it calculates the downside for the entire series of returns, not just for the rolling period. A correct calculation would be something like this:downside = returns.rolling(rolling_period).apply(lambda x: (x[x < 0]**2).sum())/rolling_periodThis will be slower than other approaches, but I wanted to provide a simple example to illustrate the issue.
Line of code referenced: 7156af7#r57724791