M squared is a risk adjusted return useful to judge the size of relative performance between differents portfolios. With it you can compare portfolios with different levels of risk.
MSquared(Ra, Rb, Rf = 0, ...)$$M^2 = r_P + SR * (\sigma_M - \sigma_P) = (r_P - r_F) * \frac{\sigma_M}{\sigma_P} + r_F$$
where \(r_P\) is the portfolio return annualized, \(\sigma_M\) is the market risk and \(\sigma_P\) is the portfolio risk
Carl Bacon, Practical portfolio performance measurement and attribution, second edition 2008 p.67-68
data(portfolio_bacon)
print(MSquared(portfolio_bacon[,1], portfolio_bacon[,2])) #expected 0.10062
#> benchmark.return....
#> benchmark.return.... 0.10062
data(managers)
print(MSquared(managers['1996',1], managers['1996',8]))
#> SP500 TR
#> SP500 TR 0.2544876
print(MSquared(managers['1996',1:5], managers['1996',8]))
#> HAM1 HAM2 HAM3 HAM4 HAM5
#> MSquared (Risk free = 0) 0.2544876 NA 0.4028725 0.1982483 NA