Write a SQL query to identify the top-performing portfolios over a rolling three-month window, accounting for risk-adjusted returns.
Use the provided monthly portfolio returns and monthly risk-free rates. A portfolio qualifies only when three consecutive monthly observations are available. Return the top two portfolios for each eligible month.
Output
- One row per qualifying portfolio and month, with
month_end, portfolio_id, portfolio_name, rolling_return, rolling_volatility, risk_adjusted_return, and performance_rank.
- Use average monthly return divided by sample standard deviation of monthly excess returns as the risk-adjusted return.
- Sort by
month_end ascending, then performance_rank ascending, then portfolio_id ascending.