diff --git a/pyfacts/statistics.py b/pyfacts/statistics.py index c2a1d02..bd3a336 100644 --- a/pyfacts/statistics.py +++ b/pyfacts/statistics.py @@ -574,8 +574,10 @@ def sortino_ratio( "closest": closest, "date_format": date_format, } - average_rr_ts = time_series_data.calculate_rolling_returns(**common_params, annual_compounded_returns=False) - average_rr = statistics.mean(average_rr_ts.values) + average_rr_ts = time_series_data.calculate_rolling_returns( + **common_params, annual_compounded_returns=False, if_not_found="nan" + ) + average_rr = statistics.mean(filter(lambda x: str(x) != "nan", average_rr_ts.values)) annualized_average_rr = (1 + average_rr) ** (365 / interval_days) - 1 excess_returns = annualized_average_rr - risk_free_rate