tatn <- fread('TATN_1min.csv')
tatn[, c("timestamp", "mid.price") := .(ymd_hms(timestamp, tz="Europe/Moscow"), (bid.price + ask.price)/2)]
head(tatn)
##              timestamp bid.price ask.price mid.price
## 1: 2018-01-03 10:01:00    478.15    478.15    478.15
## 2: 2018-01-03 10:02:00    477.10    477.10    477.10
## 3: 2018-01-03 10:03:00    477.80    477.80    477.80
## 4: 2018-01-03 10:04:00    478.20    478.20    478.20
## 5: 2018-01-03 10:05:00    477.30    477.30    477.30
## 6: 2018-01-03 10:06:00    478.90    478.90    478.90
ggplot(tatn, aes(x=timestamp, y=mid.price)) + 
  geom_line() +
  scale_x_datetime(date_breaks = '10 week', date_label="%Y-%m-%d") + 
  theme(axis.text.x = element_text(angle=45, hjust=1))

phi <- 0.00057
rho <- 0.000001
ts_tatn <-obadiah::trading.strategy(tatn, phi,rho , tz="Europe/Moscow")
nrow(ts_tatn)
## [1] 25272
head(ts_tatn[order(-bps.return,), .(opened.at, open.price, closed.at, close.price, bps.return)], 12)
##               opened.at open.price           closed.at close.price  bps.return
##  1: 2018-04-09 13:17:00     577.00 2018-04-09 13:28:00      597.05 347.4870017
##  2: 2018-04-27 18:33:00     666.60 2018-04-27 18:46:00      685.25 279.7779778
##  3: 2018-04-09 12:28:00     597.45 2018-04-09 12:44:00      583.25 237.6767930
##  4: 2018-04-10 16:41:00     634.10 2018-04-10 16:56:00      648.35 224.7279609
##  5: 2018-04-09 12:58:00     587.15 2018-04-09 13:09:00      575.80 193.3066508
##  6: 2019-05-28 18:39:00     689.90 2019-05-28 18:46:00      702.80 186.9836208
##  7: 2018-12-26 12:16:00     706.40 2018-12-26 12:34:00      719.60 186.8629672
##  8: 2018-12-04 16:35:00     750.00 2018-12-04 17:08:00      763.90 185.3333333
##  9: 2018-11-26 10:38:00     706.90 2018-11-26 10:43:00      693.90 183.9015419
## 10: 2018-11-06 10:26:00     788.70 2018-11-06 10:44:00      802.90 180.0431089
## 11: 2018-04-10 10:01:00     598.10 2018-04-10 10:06:00      608.85 179.7358301
## 12: 2019-05-14 17:36:00     718.30 2019-05-14 17:55:00      705.70 175.4141724
obadiah::plotPositionTrellis(head(ts_tatn[order(-bps.return)],12), tatn, around=600)

nrow(ts_tatn[bps.return > 200]) # i.e. spike greater than 2%
## [1] 4
nrow(ts_tatn[bps.return > 150])
## [1] 38
nrow(ts_tatn[bps.return > 100])
## [1] 248