Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

backtest simulation behaviour #43

Closed
skunk73 opened this issue Aug 24, 2016 · 7 comments
Closed

backtest simulation behaviour #43

skunk73 opened this issue Aug 24, 2016 · 7 comments

Comments

@skunk73
Copy link

skunk73 commented Aug 24, 2016

zenbot trade frequency on simulations is always one every hour at most even with rs.check_period set to 1m (and rs.min_*_wait set to 0), eg:

$ jq ".actions[].timestamp" sims/2016-08-24/btc-usd_1m
"05/26/2016 03:01:00 PM CEST"
"06/07/2016 06:01:00 PM CEST"
"06/08/2016 09:01:00 PM CEST"
"06/14/2016 05:01:00 PM CEST"
"06/15/2016 08:01:00 PM CEST"
"06/19/2016 07:01:00 AM CEST"
"06/23/2016 08:01:00 PM CEST"
"06/25/2016 10:01:00 PM CEST"
"06/28/2016 02:01:00 AM CEST"
"06/29/2016 07:01:00 AM CEST"
"06/30/2016 11:01:00 AM CEST"
"07/03/2016 10:01:00 AM CEST"
"07/04/2016 03:01:00 PM CEST"
"07/05/2016 03:02:00 PM CEST"
"07/07/2016 01:01:00 AM CEST"
"07/09/2016 02:01:00 PM CEST"
"07/11/2016 05:01:00 AM CEST"
"07/14/2016 01:01:00 AM CEST"
"07/15/2016 10:01:00 AM CEST"
"07/16/2016 03:01:00 PM CEST"
"07/17/2016 03:02:00 PM CEST"
"07/18/2016 06:01:00 PM CEST"
"07/20/2016 07:01:00 AM CEST"
"07/22/2016 01:01:00 PM CEST"
"07/23/2016 01:02:00 PM CEST"
"07/25/2016 08:01:00 AM CEST"
"07/26/2016 09:01:00 PM CEST"
"07/31/2016 04:01:00 AM CEST"
"08/03/2016 01:01:00 PM CEST"
"08/04/2016 08:01:00 PM CEST"
"08/06/2016 12:01:00 AM CEST"
"08/11/2016 09:01:00 PM CEST"
"08/13/2016 09:01:00 AM CEST"
"08/14/2016 09:02:00 AM CEST"
"08/16/2016 06:01:00 AM CEST"
"08/17/2016 04:01:00 PM CEST"

as you can see trades happens always every hour start + (1m x 1 or 2)...
moreover, if setting rs.check_period to 5m trades still happens every hour start + (5m x 1 or 2):

$ jq ".actions[].timestamp" sims/2016-08-24/btc-usd_5m
"05/26/2016 03:05:00 PM CEST"
"06/07/2016 06:05:00 PM CEST"
"06/08/2016 09:05:00 PM CEST"
"06/14/2016 05:05:00 PM CEST"
"06/15/2016 08:05:00 PM CEST"
"06/19/2016 07:05:00 AM CEST"
"06/23/2016 08:05:00 PM CEST"
"06/25/2016 10:05:00 PM CEST"
"06/28/2016 02:05:00 AM CEST"
"06/29/2016 07:05:00 AM CEST"
"06/30/2016 11:05:00 AM CEST"
"07/03/2016 10:05:00 AM CEST"
"07/04/2016 03:05:00 PM CEST"
"07/05/2016 03:10:00 PM CEST"
"07/07/2016 01:05:00 AM CEST"
"07/09/2016 02:05:00 PM CEST"
"07/11/2016 05:05:00 AM CEST"
"07/14/2016 01:05:00 AM CEST"
"07/15/2016 10:05:00 AM CEST"
"07/16/2016 03:05:00 PM CEST"
"07/17/2016 03:10:00 PM CEST"
"07/18/2016 06:05:00 PM CEST"
"07/20/2016 07:05:00 AM CEST"
"07/22/2016 01:05:00 PM CEST"
"07/23/2016 01:10:00 PM CEST"
"07/25/2016 08:05:00 AM CEST"
"07/26/2016 09:05:00 PM CEST"
"07/31/2016 04:05:00 AM CEST"
"08/03/2016 01:05:00 PM CEST"
"08/04/2016 08:05:00 PM CEST"
"08/06/2016 12:05:00 AM CEST"
"08/11/2016 09:05:00 PM CEST"
"08/13/2016 09:05:00 AM CEST"
"08/14/2016 09:10:00 AM CEST"
"08/16/2016 06:05:00 AM CEST"
"08/17/2016 04:05:00 PM CEST"

so the trades are almost identical but shifted to the 5th or the 10th minute...
on the other hand online trades happens (correctly) at any time whenever the conditions are met, eg:

08/23/2016 12:56:00 AM CEST [      action] m24531775 buy {
  "type": "buy",
  "asset": "BTC",
  "currency": "EUR",
  "exchange": "gdax",
  "price": 520.61,
  "fee": 1.225,
  "market": true,
  "size": 0.9412035880985766,
  "rsi": 70.04739336492952,
  "roi": 1.0003260597302503,
  "performance": null,
  "waited": null,
  "id": "c9b959930a9d59ce",
  "time": 1471906560000,
  "timestamp": "08/23/2016 12:56:00 AM CEST"
}

thus backtest simulation results won't reflect the results of the online trader because they'll trade at different timestamps and frequencies...

@carlos8f
Copy link
Contributor

interesting, I'll investigate.

but worth noting I changed check_period to 5m and the ROI jumped up. experimented with other check_periods but that was the best one by far. Also changed the reporting period in the sim to 1h, to speed up the sim.

@skunk73
Copy link
Author

skunk73 commented Aug 24, 2016

just a matter of luck because on that particular data the trades at hh:05:00 are more favorable than those at hh:01:00...
if you check the number of trades don't differ between 1m and 5m check_periods and both trades happens on the same day/hour but shifted by 4 minutes.

@carlos8f
Copy link
Contributor

@skunk73 I probably won't be able to fix this until tomorrow. If you have any leads on what's wrong in the code, or how to fix it, that would help!

@skunk73
Copy link
Author

skunk73 commented Aug 24, 2016

it seems you're using hourly ticks to run the simulation instead of 1m, 5m or whatever the value of check_periods is...
it's evident when you run the sim with the -v flag.
I'll give a look to the code tomorrow but I'm not that familiar with nodejs and mongodb...

@carlos8f
Copy link
Contributor

it seems you're using hourly ticks to run the simulation

It only appears that way because the reporter (in verbose sim mode) only reports on 1h ticks (to throttle output), but the trade logic functions are fed all reducer tick sizes (1m, 5m, 15m, 1h, 6h, 1d). you can verify this with the patch

diff --git a/default_logic.js b/default_logic.js
index 121b9b7..1b27b75 100644
--- a/default_logic.js
+++ b/default_logic.js
@@ -52,8 +52,8 @@ module.exports = function container (get, set, clear) {
       rs.exchange = sMatch[1]
       rs.asset = sMatch[2]
       rs.currency = sMatch[3]
-      if (options.verbose && get('command') === 'run') {
-        get('logger').info('trader', c.default_selector.grey, get_tick_str(tick.id), 'running logic'.grey, rs.asset.grey, rs.currency.grey, {feed: 'trader'})
+      if (options.verbose && get('command') === 'sim') {
+        get('logger').info('trader', c.default_selector.grey, get_tick_str(tick.id), 'running logic'.grey, get_timestamp(tick.time), rs.asset.grey, rs.currency.grey, {feed: 'trader'})
       }
       rs.rsi_period = '1h'
       rs.rsi_up = 70
08/24/2016 12:55:23 PM PDT [      trader] gdax.BTC-USD 15m1627333 running logic 05/30/2016 02:15:00 AM PDT BTC USD
08/24/2016 12:55:23 PM PDT [      trader] gdax.BTC-USD m24409995 running logic 05/30/2016 02:15:00 AM PDT BTC USD
08/24/2016 12:55:23 PM PDT [      trader] gdax.BTC-USD 5m4881999 running logic 05/30/2016 02:15:00 AM PDT BTC USD
08/24/2016 12:55:23 PM PDT [      trader] gdax.BTC-USD m24409996 running logic 05/30/2016 02:16:00 AM PDT BTC USD
08/24/2016 12:55:23 PM PDT [      trader] gdax.BTC-USD m24409997 running logic 05/30/2016 02:17:00 AM PDT BTC USD
08/24/2016 12:55:23 PM PDT [      trader] gdax.BTC-USD m24409998 running logic 05/30/2016 02:18:00 AM PDT BTC USD
08/24/2016 12:55:23 PM PDT [      trader] gdax.BTC-USD m24409999 running logic 05/30/2016 02:19:00 AM PDT BTC USD
08/24/2016 12:55:23 PM PDT [      trader] gdax.BTC-USD m24410000 running logic 05/30/2016 02:20:00 AM PDT BTC USD
08/24/2016 12:55:23 PM PDT [      trader] gdax.BTC-USD 5m4882000 running logic 05/30/2016 02:20:00 AM PDT BTC USD
08/24/2016 12:55:23 PM PDT [      trader] gdax.BTC-USD m24410001 running logic 05/30/2016 02:21:00 AM PDT BTC USD
08/24/2016 12:55:23 PM PDT [      trader] gdax.BTC-USD m24410002 running logic 05/30/2016 02:22:00 AM PDT BTC USD
08/24/2016 12:55:23 PM PDT [      trader] gdax.BTC-USD m24410003 running logic 05/30/2016 02:23:00 AM PDT BTC USD
08/24/2016 12:55:23 PM PDT [      trader] gdax.BTC-USD m24410004 running logic 05/30/2016 02:24:00 AM PDT BTC USD
08/24/2016 12:55:23 PM PDT [      trader] gdax.BTC-USD m24410005 running logic 05/30/2016 02:25:00 AM PDT BTC USD
08/24/2016 12:55:23 PM PDT [      trader] gdax.BTC-USD 5m4882001 running logic 05/30/2016 02:25:00 AM PDT BTC USD
08/24/2016 12:55:23 PM PDT [      trader] gdax.BTC-USD m24410006 running logic 05/30/2016 02:26:00 AM PDT BTC USD
08/24/2016 12:55:23 PM PDT [      trader] gdax.BTC-USD m24410007 running logic 05/30/2016 02:27:00 AM PDT BTC USD
08/24/2016 12:55:23 PM PDT [      trader] gdax.BTC-USD m24410009 running logic 05/30/2016 02:29:00 AM PDT BTC USD
08/24/2016 12:55:23 PM PDT [      trader] gdax.BTC-USD 15m1627334 running logic 05/30/2016 02:30:00 AM PDT BTC USD
08/24/2016 12:55:23 PM PDT [      trader] gdax.BTC-USD m24410010 running logic 05/30/2016 02:30:00 AM PDT BTC USD
08/24/2016 12:55:23 PM PDT [      trader] gdax.BTC-USD 5m4882002 running logic 05/30/2016 02:30:00 AM PDT BTC USD

@carlos8f
Copy link
Contributor

Hmm, so I think the simulator is running correctly, but the RSI calculation isn't using proper smoothing and that's what's causing the RSI to spike on the hour. Fixing this might take refactoring the RSI to be a chain-like computation on ticks rather than a single tick reducer function.

@carlos8f
Copy link
Contributor

fixed in 3.5.15

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants