Author Topic: Z-Score values shown in Trade-Log differ to calculated values  (Read 9307 times)

Marc Wengenroth

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Dear pairtradinglab team,

I noticed that Z-Score values shown in the Trade-Log of the backtesting tool do not equal to the values I calculated before, even if my trades have been processed at the right date, in case of the example attached. But in most cases the tool trades at points when my Z-Score treshold definitely hasn´t been reached yet.

Z-Score values shown in the Trade-Log even exceed the maximum Z-Score values of my calculation, what makes me wonder. The values have been calculated exactly in the way described in your description of Ratio model and I verified that I definitely used the same data for the quotes as your tool does.

How is it possible that those values differ from mine?

I attached my calculation, the quotes and the backtesting results.

Kind regards,
Marc

« Last Edit: March 12, 2018, 12:44:47 pm by Marc Wengenroth »

admin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 338
  • Karma: +13/-0
    • Pair Trading Lab
Re: Z-Score values shown in Trade-Log differ to calculated values
« Reply #1 on: March 12, 2018, 05:45:45 pm »
Hi,

please post also the link to the concrete backtest made with PTL so I can compare...you can just paste the URL of the PTL backtest, it is persistent

Marc Wengenroth

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0

admin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 338
  • Karma: +13/-0
    • Pair Trading Lab
Re: Z-Score values shown in Trade-Log differ to calculated values
« Reply #3 on: March 13, 2018, 06:59:13 am »
OK the first problem I see in your sheet is that you calculate the moving average and standard deviation using wrong data. For instance, for 15.5.2017 (row #164) you include the line #164 to both moving average and standard deviation calculation. This is wrong.

The last price point should be only used to determine the Z-score, but this sample cannot be included in the moving average / std dev calculation. You need to shift the floating window by one sample. So the correct period for row #164 is rows 165-194.

Then I see stock prices are a bit different, you use Yahoo, PTL uses Google Finance for non-US stocks.

BTW we tried to reimplement our Ratio model to Quantopian for reference, you can take a look for inspiration (but it is run using intraday prices):
https://www.quantopian.com/algorithms/557c0617c6591162f70004b2

Marc Wengenroth

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: Z-Score values shown in Trade-Log differ to calculated values
« Reply #4 on: March 13, 2018, 08:23:14 am »
Hello and many thanks at first.

Well, I can see that I come closer to the Z-Score your tool calculated but there´s still too much difference.

I guess the Z-Score shown in the Trade-Log is based on calculation with daily close quotes, right? So this is not based on calculation with bid/ask price, right?

How can I get Google quotes?

admin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 338
  • Karma: +13/-0
    • Pair Trading Lab
Re: Z-Score values shown in Trade-Log differ to calculated values
« Reply #5 on: March 13, 2018, 10:16:47 am »
About Google Finance - example here: https://finance.google.com/finance/historical?q=FRA:RWE  (note the Download to spreadsheet link)

The Z-score is calculated using the EOD close price. Bid-ask spread is simulated, too - but the difference will be negligible with 0.01 spread (you may disable the spread in backtest setting to be sure).

Marc Wengenroth

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: Z-Score values shown in Trade-Log differ to calculated values
« Reply #6 on: March 13, 2018, 01:16:58 pm »
Well, I don´t know how you got those prices at Google Finance but as soon as I type in a new stock value then the option to retrieve historical prices isn´t available no more.

I´ve read the Google changed a few things there.


admin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 338
  • Karma: +13/-0
    • Pair Trading Lab
Re: Z-Score values shown in Trade-Log differ to calculated values
« Reply #7 on: March 13, 2018, 08:41:31 pm »
They removed the link to download but it still works if you use the URL directly.

admin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 338
  • Karma: +13/-0
    • Pair Trading Lab

Marc Wengenroth

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: Z-Score values shown in Trade-Log differ to calculated values
« Reply #9 on: March 14, 2018, 01:16:43 pm »
Great, it works...

Well, I compared the Yahoo daily close prices now to the ones from Google that your tool used and I cannot find any noticeable deviations. So the prices do net seem to be the cause for the differing Z-Score values.

You can find it attached.

admin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 338
  • Karma: +13/-0
    • Pair Trading Lab
Re: Z-Score values shown in Trade-Log differ to calculated values
« Reply #10 on: March 14, 2018, 02:51:17 pm »
OK, I will look further during the weekend..

In the mean time, please look at the Quantopian implementation for reference...

admin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 338
  • Karma: +13/-0
    • Pair Trading Lab
Re: Z-Score values shown in Trade-Log differ to calculated values
« Reply #11 on: March 14, 2018, 02:56:12 pm »
One more thing - please perform the same PTL backtest while setting bid-ask spread to 0 for both stocks...

Marc Wengenroth

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: Z-Score values shown in Trade-Log differ to calculated values
« Reply #12 on: March 17, 2018, 10:46:35 am »
Attached the link to another test with zero spread.

https://www.pairtradinglab.com/backtests/Wq0pI_yIK4FVxfRY

Z-score values only changed very little and still differ from my calculation as before.

admin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 338
  • Karma: +13/-0
    • Pair Trading Lab
Re: Z-Score values shown in Trade-Log differ to calculated values
« Reply #13 on: March 17, 2018, 12:39:24 pm »
Looked further. Your sheet is missing some dates - namely 5/1/2017, 4/17/2017, 4/14/2017...this is not your fault, these days are missing for real in the Google Finance data too (missing samples or flexible holidays like Easter).

PTL assumes all weekdays (except static Christmas and New Year) as trading days and always backfills missing samples using values from a previous trading days. Look at the screenshot - appended those rows manually...now the Z-score got really close to the PTL tool...

The reason we do this is a data consistency - Google Finance is not really a reliable data source, often there are different days missing for different symbols, so we backfill all values to be sure there are same samples included for all stocks...