Discussion of article "Mathematics in trading: Sharpe and Sortino ratios" - page 2

 
Ivan Titov #:
Did I understand correctly that Sharpe.mqh only calculates the annual Sharpe ratio? Monthly Sortino will not work?

The article contains the answer to your question.

 
Andrey Khatimlianskii #:

Again, what is a "low number"? Seems to me that 70-80 is low, but you don't have a penalty on such passes.

Are the numbers compared to other passes?

Is it normalised by the length of the test interval?

Most likely some fixed value is set, otherwise you would have to recalculate the whole table of results many times.

I agree with your arguments above.

 
Andrey Khatimlianskii #:
They coincide, but not always

If you set the weekly timeframe in the tester, they almost always do not match:

On the monthly timeframe, the spread is even greater:


 
Rashid Umarov #:

The article contains the answer to your question.

I did not find the answer to my question in the article, but judging by the code Sharpe.mqh Sortino is not in it. That's why I've attached the amended code with the Sortino calculation option below. At the same time I have optimised the code in terms of unnecessary function calls.

In my opinion, the disadvantage of the Sortino coefficient is that only yields below the risk-free rate (zero in this case) are taken for its calculation. But a positive return on one of the periods below the calculated average for the tested strategy is also a risk. That's why I added a coefficient calculation that takes into account only returns below the average. I haven't found an analogue, so I modestly named it Titov's coefficient)). When I find it, I will rename it.

In the original, it is inconvenient that the calculation period depends on the current timeframe. That's why I added setting the calculation period (if it is not explicitly set, the current timeframe is taken):

Returns.SetTF(PERIOD_MN1);

I have not found in any source the necessity to use the logarithm of the yield when calculating the Sharpe ratio and bring it to the annual value. Therefore, I added the possibility to disable these options.

For some reason, the article's examples ignore periods with zero returns. This distorts the result. Therefore, I added an option to include such periods in the calculation.

Example of using the Sharpe ratio calculation as in the original:

#include <Sortino.mqh>
CReturns Returns;

..

void OnTick()
{
        Returns.OnTick();
        ..
}


double OnTester(void)
{
        return(Returns.OnTester(DEF_SHARPE));
}

Example of calculation of Sortino coefficient with all other things being equal:

#include <Sortino.mqh>
CReturns Returns;

..

void OnTick()
{
        Returns.OnTick();
        ..
}


double OnTester(void)
{
        return(Returns.OnTester(DEF_SORTINO));
}

For myself, I decided to assess the risk of below-average returns on monthly intervals:

#include <Sortino.mqh>
CReturns Returns;

..

int OnInit()
{
        Returns.SetTF(PERIOD_MN1);
        ..
}


void OnTick()
{
        Returns.OnTick();
        ..
}


double OnTester(void)
{
        return(Returns.OnTester(DEF_TITOV, false, false, false));
}
Files:
Sortino.mqh  10 kb
 
Ivan Titov #:
I haven't found in any source the need to use the logarithm of returns when calculating the Sharpe ratio

To answer with a quote

Using the logarithm of returns in the calculation of the Sharpe ratio is not strictly necessary, but can be useful to simplify calculations and improve the statistical properties of the data, especially when dealing with long time periods or highly volatile assets. Logarithmic returns are often used because they provide a better approximation of the normal distribution of returns and simplify calculations when compiling portfolios.

I would add - try it without logarithms and tell me about the unusual side effect. You should encounter it.

 
Ivan Titov #:
I have not found in any source the necessity of calculating the Sharpe ratio and bringing it to an annualised value.

Another quote

As for bringing the Sharpe ratio to an annualised value, this is done to standardise the ratio to allow comparison between different investment strategies and portfolios, regardless of the original time scale of the investment. This is a common practice that helps investors measure investment performance against a common standard, especially when comparisons are made between different asset types or strategies with different trading frequencies

 
Rashid Umarov #:
I'll respond with a quote

By sources, I meant information on Sharpe and Sortino ratios outside of this article.

Rashid Umarov #:
As for bringing the Sharpe ratio to an annualised value, this is done to standardise the ratio, allowing it to be compared between different investment strategies and portfolios, regardless of the original time scale of the investment.
The Sharpe ratio is the ratio of the average return on the segments of a given period to the standard deviation on the same segments. That is, the length of the segments does not matter much for the possibility of comparing strategies with each other. In my opinion, it is just advisable to choose it to be several times longer than the average duration of a trade in order to remove unnecessary noise.
Rashid Umarov #:
try it without logarithms and tell me about the unusual side effect. You should encounter it

I tried it: nothing unusual. But I found one mistake, I attach the corrected version.

Files:
Sortino.mqh  10 kb
 
Rashid Umarov #:

I'll respond with a quote

I'll add for myself - try it without logarithms and tell me later about the unusual side-effect. You should encounter it.

Curiously, for such equity this script gives a Sharpe of 2.08:

And for this one (the same with reinvestment) 3.66:

Although it is obvious that the quality of the 2nd equity is worse (reinvest always worsens the quality of equity).

And if instead of logarithms of equity increments we use the increments themselves:

         log_return = (m_equities[i] - prev_equity); // increment 
         //log_return = MathLog(m_equities[i] / prev_equity); // increment logarithm

We get 3.85 for the first and 2.1 for the second. Much more adequate.

 
In addition, the Sharpe on logarithms depends significantly on the size of the initial deposit. In the above example (equity 1) with an initial deposit of 4000 it gives 2.08. With a deposit of 400000 it gives 3.83. Although the shape of equity has not changed in any way (trading with a fixed lot).
 

Sharpe on logarithms does not depend on the deposit size only in case of trading with reinvestment.

But in this case the Sharpe on simple increments does not depend on the deposit size.

Therefore, I don't understand why I should use Sharpe on logarithms.