The Sortino ratio measures the risk-adjusted return of an investment asset, portfolio or strategy. It is a modification of the Sharpe ratio but penalizes only those returns falling below a user-specified target. The Sortino ratio is similar to the Sharpe ratio, except it uses downside deviation for the denominator instead of standard deviation, the use of which doesn't discriminate between upside and downside volatility.
Lorenzo Brancali (2020). Sortino Ratio (https://www.mathworks.com/matlabcentral/fileexchange/35599-sortino-ratio), MATLAB Central File Exchange. Retrieved .
The code should be re-written as follows:
DD = sqrt( sum((F3-MAR).^2) / length(F) )
argh with the editor here... :-)
DD should be sqrt( sum(F3-MAR).^2 / length(F) )
i.e., divide by number of all returns, not just the number of downside returns.
Incorrect calculation of the Downside Deviation (DD) and therefore of the Sortino ratio!
It should be sqrt( sum(F3-MAR).^2 / length(F3) ) and *NOT* sqrt(sum(F3).^2) / length(F3), where F3=nonzeros(F(F<MAR))