Discussion of article "R-squared as an estimation of quality of the strategy balance curve" - page 4

 

Conclusions about some statistical relationship may be incorrect if outliers are not handled - outliers detection.

 
Dennis Kirichenko:

Conclusions about some statistical relationship may be wrong if outliers detection is not performed.

If R^2 is used as a criterion for Optimisation (OnTester), then any analysis of LR residuals and their coefficients is to be scrapped.

Since additional analysis increases the precious time of Optimisation, and it is of little use, the situation will not change dramatically: the same "smooth" equity curves will be at the top, which were initially desired.

 
СанСаныч Фоменко:

The author shows a complete lack of understanding of chance processes. All conclusions of the article have nothing to do with the very concept of chance and mislead people.

Let me explain this opinion.

At the very beginning of the article, a definition is given:

Linear regression is a linear dependence of one variable y on another independent variable x, expressed by the formula y = ax+b. In this formula, a is the multiplier and b is the bias coefficient

Linear regression is NOT expressed by the formula

y = ax+b is a linear equation formula,

but is expressed by the formula

y = ax+b + error

The error must be NORMALLY DISTRIBUTED, and if it is not, there are many nuances that arise that very much limit the application of linear regression.

It is extremely important to realise that linear regression coefficients, unlike linear equation, are NOT constants, they are chance values and if you take a standard linear regression fit, e.g. in R, then always for linear regression coefficients the deviation from that value of coefficients, as well as the probability (probability in the null hypothesis of NOT EVIDENCE OF THIS COEFFICIENT) is specified. Once again: unlike a linear equation, linear regression coefficients may not exist at all. That is why the R2 coefficient discussed in the article makes sense only for regressions in which the probability of non-existence of the regression coefficients is below 10%. On financial series, I have never seen that the coefficients of linear regression are meaningful and, therefore, it is possible to use this very linear regression.

San Sanych, don't interfere. We mould as we know how!

p.s. It is obvious that you read diagonally. R^2 is calculated not for charts of quotes, but for equity. Its main task is to show even equity. That's it. Whether it corresponds to random or not - let the user decide:

fxsaber:

If we make R^2 as a criterion for Optimisation (OnTester), then any analysis of LR residuals and their coefficients is to hell with it.

Since additional analysis increases the precious time of Optimisation, and it is of little use, the situation will not change dramatically: the same "smooth" equity curves will be at the top, which were initially desired.

+
 

Anyway, the wrong sign is taken from here:

We started with 100,000. Commission 0. The sum on transactions +513, but the total balance 99 755.90, ie somewhere missing 757.1$

How's that?

 
Vasiliy Sokolov:

In short, the wrong sign is taken from here:

I would restate it somewhat. The remark on the correctness of the sign concerned the general case - not only equity. If you compare the first and last values by equity, as you have done, then the incorrect sign is likely to be defeated in this case. It would be better to deal with the general case.

We started with 100 000. Commission 0. The sum on deals +513, but the total balance is 99 755.90, i.e. $757.1 is missing somewhere.

How's that?

HTML report would help to understand.

 
fxsaber:

I would restate it somewhat. The remark on the correctness of the sign was about the general case - not only equity. If you compare the first and the last value by equity, as you did, then the incorrectness of the sign will probably be defeated in this case. It would be better to deal with the general case.

An HTML report would help to understand it.

Unfortunately, it shows the same result as for the balance. The totals in both cases coincide completely: +513$. But in general they should coincide, because after testing all trades are closed and equity is compared with balance.

fxsaber:

HTML-report would help to understand.

I will send it now.

 

?:%:?? I've got it. I forgot to take swap into account (Swap to profit is not summarised)!

 

Done. Fixed the balance calculation function. Now each transaction also takes into account the swap:

//+------------------------------------------------------------------+
//| Returns the R^2 score calculated based on the balance of the strategy |
//+------------------------------------------------------------------+
double CustomR2Balance(ENUM_CORR_TYPE corr_type = CORR_PEARSON)
{
   HistorySelect(0, TimeCurrent());
   double deals_equity[];
   double sum_profit = 0.0;
   int current = 0;
   int total = HistoryDealsTotal();
   for(int i = 0; i < total; i++)
   {
      ulong ticket = HistoryDealGetTicket(i);
      double profit = HistoryDealGetDouble(ticket, DEAL_PROFIT);
      double swap = HistoryDealGetDouble(ticket, DEAL_SWAP);
      if(profit == 0.0 && swap == 0.0)
         continue;
      if(ArraySize(deals_equity) <= current)
         ArrayResize(deals_equity, current+16);
      sum_profit += profit + swap;
      deals_equity[current] = sum_profit;
      current++;
   }
   ArrayResize(deals_equity, current);
   return CustomR2Equity(deals_equity, corr_type);
}

Fixed equity calculation so that its final value is synchronised with the actual result:

//+------------------------------------------------------------------+
//|| Adds equity monitoring|
//+------------------------------------------------------------------+
double CStrategyList::OnTester(void)
{
   switch(m_custom_type)
   {
      case CUSTOM_NONE:
         return 0.0;
      case CUSTOM_R2_BALANCE:
         return CustomR2Balance(m_corr_type);
      case CUSTOM_R2_EQUITY:
      {
         double equity[];
         m_equity_exp.GetEquityArray(equity);
         int total = ArrayResize(equity, ArraySize(equity)+1);
         equity[total-1] = AccountInfoDouble(ACCOUNT_EQUITY);
         return CustomR2Equity(equity, m_corr_type);
      }
   }
   return 0.0;
}

Since the equity collection interval can be large, the last known value may differ from the actual value. Therefore, we add an additional last value equal to the final result.

p.s. Corrections have been made to the article. The article has been sent to the moderator for updating.
 
Vasiliy Sokolov:

?:%:?? I've got it. I forgot to take swap into account (Swap is not summed up to profit)!

I would continue not to take into account

Forum on trading, automated trading systems and testing trading strategies.

Discussion of the article "R-square as an assessment of the quality of the strategy balance curve"

fxsaber, 2017.10.24 15:18

Code to calculate "equity", suitable for R^2. Written in MT4 style, it's not hard to translate to MT5...

static double GetOrderProfit( void )
  {
    return((OrderProfit()/* + OrderCommission() + OrderSwap()*/) / OrderLots()); // commission and swap are sometimes useful to ignore
  }

Swap has almost nothing to do with the evaluation of the TS profitability and only introduces distortions when evaluating robustness.

 
fxsaber:

I would continue to disregard

Swap has almost nothing to do with assessing the profitability of a TS and only introduces distortions when assessing robustness.

That's a controversial statement. But that's not even the point here. It's just the boundary conditions. Swap size is not large, but when it is near zero, its accounting or not can affect the final sign.