-
Notifications
You must be signed in to change notification settings - Fork 28
/
High Frequency Trading.Rmd
518 lines (442 loc) · 31.4 KB
/
High Frequency Trading.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
---
title: "<img src='www/HFT.jpg' width='840'>"
subtitle: "[High Frequency Trading](https://github.com/scibrokes/real-time-fxcm)"
author: "[®γσ, Lian Hu](https://englianhu.github.io/)<img src='www/RYO.jpg' width='24'><img src='www/RYU.jpg' width='24'><img src='www/ENG.jpg' width='24'>®"
date: "`r lubridate::today('Asia/Tokyo')`"
output:
html_document:
number_sections: yes
toc: yes
toc_depth: 4
toc_float:
collapsed: yes
smooth_scroll: yes
code_folding: hide
---
```{r setup, message=FALSE}
#'@ rm(list = ls(all = TRUE))
suppressPackageStartupMessages(library('BBmisc'))
pkgs <- c('devtools', 'knitr', 'kableExtra', 'tint', 'devtools', 'lubridate', 'data.table', 'quantmod', 'shiny', 'R.utils', 'memoise', 'magrittr', 'plyr', 'dplyr', 'stringr', 'purrr', 'TFX', 'TTR', 'quantmod', 'tidyquant', 'tibbletime', 'furrr', 'QuantTools', 'Quandl', 'FinancialInstrument', 'foreach', 'RTAQ', 'rugarch', 'tidyverse', 'htmltools', 'highcharter', 'googleVis', 'formattable', 'DT', 'reticulate', 'highfrequency', 'HighFreq', 'EventStudy')
if(!require('QuantTools')){
devtools::install_bitbucket('quanttools/QuantTools')
}
require('QuantTools')
if(!require('blotter')){
devtools::install_github("braverock/blotter") # dependency
}
require('blotter')
if(!require('quantstrat')){
devtools::install_github("braverock/quantstrat")
}
require('blotter')
# https://stackoverflow.com/questions/44891437/install-quantstrat-for-r-latest-r-version
# https://r-forge.r-project.org/R/?group_id=316
suppressAll(lib(pkgs))
#funs <- c('plotChart2.R', 'read_tick.data.R')
#l_ply(paste0('./function/', funs), source)
cr_code <- c('AUDUSD=X', 'EURUSD=X', 'GBPUSD=X', 'CHF=X', 'CAD=X',
'CNY=X', 'JPY=X')
names(cr_code) <- c('AUDUSD', 'EURUSD', 'GBPUSD', 'USDCHF', 'USDCAD',
'USDCNY', 'USDJPY')
## https://www.alphavantage.co/
## https://www.alphavantage.co/support/#api-key
api = 'UL7EPVVEGDVC3TXC'
options(warn = -1)
rm(pkgs)
conflict_prefer('filter', 'dplyr')
conflict_prefer('mutate', 'dplyr')
conflict_prefer('rename', "dplyr")
```
# Introduction
## Introduce High Frequency Trading
High frequency trading is an automated trading platform used by large investment banks, hedge funds and institutional investors which utilizes powerful computers to transact a large number of orders at extremely high speeds. These high frequency trading platforms allow traders to execute millions of orders and scan multiple markets and exchanges in a matter of seconds, thus giving the institutions that use the platforms a huge advantage in the open market.
Read more: [What is high-frequency trading?](http://www.investopedia.com/ask/answers/09/high-frequency-trading.asp#ixzz4wVO6j7e4)
[QTS Capital Management, LLC.](http://www.qtscm.com/pool/) is a quantitative trading fund where mostly made profit monthly. The author of <span style='color:goldenrod'>*量化交易 - 如何建立自己的算法交易事业*</span>
## Introduce Relevant Papers
By refer to <span style='color:goldenrod'>*Ryo Eng Lian Hu (2017)*</span>^[reference paper 1], I tried to compare few Kelly funds for financial trading.
<span style='color:goldenrod'>*Understanding the Kelly Capital Growth Investment Strategy*</span> describe that the suggestion fractional Kelly for high frequency trading is low due to nowadays all quantitative are programmed trading. Professor William Ziemba describe that the founder of PIMCO fund probably using Kelly model since he used to read the \<\<<span style='color:goldenrod'>*Beat the Dealers*</span>\>\> where introduce the Kelly criterion model. The *6.2 Correction in Next Paper* inside <span style='color:goldenrod'>*binary.com Interview Question I - Tick-Data-HiLo For Daily Trading </span><span style='color:red'>(Blooper)</span>* propose a dynamic fractional Kelly model where $0.5 \leq f \leq 1$ and perhaps will in [Application of Kelly Criterion model in Sportsbook Investment](https://github.com/scibrokes/kelly-criterion).
![](www/Kelly-HFT.jpg)
<span style='color:goldenrod'>*Financial Risk Modelling and Portfolio Optimization with R (2nd Edt)*</span> and <span style='color:goldenrod'>*如何用R语言开始量化投资*</span> introduce some useful r packages for quantitative trading. <span style='color:goldenrod'>*原则 - 雷·达里奥*</span> is the autobiography of Ray Dalio, he describe how he use the quantitative modelling and $\alpha$ model to evaluate the risk and invest. Besides, he also introduce how to manage his \$160 billion world leading Bridgewater hedge fund .^[Refer to [Ray Dalio](https://www.forbes.com/profile/ray-dalio/#6c7b541a663a).] This paper is not talk about management while you can try to refer to [Analyse the Finance and Stocks Price of Bookmakers](https://github.com/scibrokes/analyse-the-finance-and-stocks-price-of-bookmakers) will touch about the financial statement and stock price.
<span style='color:goldenrod'>*解密复兴科技 - 基于隐蔽马尔科夫模型的时序分析方法*</span> decode the World number 1's profitable statistical model. The *Markov Hidden Model* and *Autoregressive Markov Switching Model* will be most interest and will start study in another paper. I was think of using HMM or bernoulli distribution to determine the value $f$ for dynamic fractional Kelly.
[Hidden Markov Mdel](https://community.rstudio.com/t/hidden-markov-mdel/13741) and [Getting Started with Hidden Markov Models in R](http://blog.revolutionanalytics.com/2014/03/r-and-hidden-markov-models.html) introduce HMM model.
<span style='color:goldenrod'>*binary.com Interview Question I - Interday High Frequency Trading*</span> suggest a better model for interday trading, <span style='color:goldenrod'>*binary.com Interview Question I - Multivariate GARCH Models*</span> compares the multivariate GARCH models. Now I try to fit the high-frequency univariate model into multivariate model for intraday trading.
[一个量化交易策略师成长历程](https://www.jianshu.com/p/f6b0b91c530a) shared the author's experience. There has couple of papers for high-frequency quantitative trading.
[Convert multivariate XTS to TS in R](https://stackoverflow.com/questions/44250867/convert-multivariate-xts-to-ts-in-r) using `wavethresh` package.
# Data
[An R interface to `zipline`](https://www.quantopian.com/posts/an-r-interface-to-zipline) introduce a r package `flyingfox` which is others than `Quandl` who provides a channel to get datasets. [Tushare Pro 新版发布,数据更稳定质量更好](http://tushare.org/classifying.html) is another data providing website. By the way, [金融阶 - 金融人才猎聘专家](https://www.jrjhr.com) is a recruitment website for financial market.
[【邢不行|量化小讲堂系列20-Python量化入门】10年400倍策略分享(附视频逐行代码讲解](https://www.jianshu.com/p/5ecd088fc7bd) introduce a website [预测者网](https://www.yucezhe.com) and [一个量化交易策略师成长历程](https://www.jianshu.com/p/f6b0b91c530a) sharing alot of high-frequency trading models in Python language.
I gather the tick-data via [FXCMTickData](https://github.com/fxcm/MarketData) for high frequency trading.
- AUDUSD
- EURUSD
- GBPUSD
- USDCHF
- USDCAD
- <s>USDCNY</s>
- USDJPY
<span style='color:goldenrod'>*binary.com Interview Question I - Tick-Data-HiLo For Daily Trading </span><span style='color:red'>(Blooper)</span>* try to use the intraday of USDJPY and filter to get only highest `bid` and lowest `ask` to determine if there is a buy or a sell transaction (or no transaction) within a day. The reason of the paper tag as <span style='color:red'>*(Blooper)*</span> had explained inside that paper.
Below I gather and filter the dataset.
```{r get-data, eval=FALSE}
------------- eval=FALSE ---------------
#'@ names(cr_code) <- c('USDAUD', 'USDEUR', 'USDGBP', 'USDCHF', 'USDCAD', 'USDCNY', 'USDJPY')
yr <- c(2015, 2016, 2017, 2018)
## get currency dataset online.
while(TRUE) {
## https://www.epochconverter.com/years
llply(names(cr_code), function(x) {
dr <- paste0('data/', x, '/')
llply(yr, function(i) {
if(i == 2015|i == 2017) wk <- 1:53 else wk <- 1:52
if(i == 2018) wk <- 1:27
llply(wk, function(j) {
lnk <- paste0(
'https://tickdata.fxcorporate.com/', x, '/', i, '/', j, '.csv.gz')
if(!dir.exists(dr)) dir.create(dr)
if(!file.exists(paste0(dr, 'Y', i, 'W', j, '.csv.gz'))) {
tryCatch(download.file(lnk, destfile = paste0(
dr, 'Y', i, 'W', j, '.csv.gz')), error = function(e) NULL)
Sys.sleep(3)
}
})
})
})
}
## extract data.
while(TRUE) {
## https://www.epochconverter.com/years
llply(names(cr_code), function(x) {
dr <- paste0('data/', x, '/')
llply(yr, function(i) {
if(i == 2015|i == 2017) wk <- 1:53 else wk <- 1:52
llply(wk, function(j) {
if (file.exists(paste0(dr, 'Y', i, 'W', j, '.csv.gz'))) {
if (!file.exists(paste0(dr, 'Y', i, 'W', j, '.csv'))) {
R.utils::gunzip(paste0(dr, 'Y', i, 'W', j, '.csv.gz'),
remove = FALSE)
cat(paste0(dr, 'Y', i, 'W', j, '.csv.gz extracted!\n'))
Sys.sleep(3)
}
}
})
})
})
}
## saved *.csv file as *.rds files after tidy the dataset to ease the time for reading.
llply(names(cr_code), function(x) {
dr <- paste0('data/', x, '/')
fls <- dir(dr, pattern = '.csv$')
for(i in seq(length(fls))) {
nm <- str_replace_all(fls, '.csv', '')
if(!file.exists(paste0(dr, nm[i], '.rds'))) {
assign(nm[i], read.csv(paste0(dr, fls[i]), skipNul = TRUE) %>% tbl_df)
## save dataset.
eval(parse(text = paste0("saveRDS(", nm[i], ", '", dr, nm[i], ".rds')")))
eval(parse(text = paste0("rm(", nm[i], ")")))
cat(paste0(dr, nm[i], '.rds saved!\n'))
}
}; rm(i, fls, nm)
})
```
Now I read the dataset.
```{r get-data2, eval=FALSE}
api = 'UL7EPVVEGDVC3TXC'
getSymbols('AAPL', src='av', api.key=api, periodicity='intraday')
[1] "AAPL"
> AAPL
AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume
2018-09-21 14:20:00 218.5000 218.5600 218.4485 218.5600 33984
2018-09-21 14:21:00 218.5400 218.6800 218.5400 218.6300 36442
2018-09-21 14:22:00 218.6100 218.6100 218.5500 218.5700 39655
2018-09-21 14:23:00 218.5900 218.6095 218.5405 218.5800 26996
2018-09-21 14:24:00 218.5700 218.5900 218.5300 218.5300 31365
2018-09-21 14:25:00 218.5100 218.5600 218.4800 218.5300 34767
2018-09-21 14:26:00 218.5100 218.5100 218.4315 218.5100 39779
2018-09-21 14:27:00 218.5100 218.6000 218.4800 218.6000 39382
2018-09-21 14:28:00 218.6200 218.8230 218.6200 218.6745 71979
2018-09-21 14:29:00 218.6900 218.7600 218.6800 218.7100 45259
2018-09-21 14:30:00 218.7000 218.7599 218.6710 218.7400 41134
2018-09-21 14:31:00 218.7300 218.7700 218.7200 218.7700 25844
2018-09-21 14:32:00 218.7700 218.8450 218.7700 218.7850 27297
2018-09-21 14:33:00 218.7600 218.8000 218.7100 218.7710 52443
2018-09-21 14:34:00 218.7800 218.8025 218.7400 218.7400 32647
2018-09-21 14:35:00 218.7500 218.7900 218.7200 218.7710 38021
2018-09-21 14:36:00 218.7500 218.8999 218.7500 218.8999 62275
2018-09-21 14:37:00 218.9030 218.9100 218.8000 218.8000 43461
2018-09-21 14:38:00 218.7800 218.8400 218.7700 218.8200 25461
2018-09-21 14:39:00 218.8200 218.8700 218.7450 218.7761 49465
2018-09-21 14:40:00 218.7700 218.7700 218.7100 218.7150 26869
2018-09-21 14:41:00 218.7300 218.7300 218.6500 218.6621 67905
2018-09-21 14:42:00 218.6500 218.7500 218.6500 218.7300 43442
2018-09-21 14:43:00 218.7000 218.7000 218.6200 218.6210 52546
2018-09-21 14:44:00 218.6100 218.6300 218.5800 218.6100 27367
2018-09-21 14:45:00 218.6150 218.6300 218.5700 218.5999 37900
2018-09-21 14:46:00 218.5900 218.6300 218.5900 218.6100 36636
2018-09-21 14:47:00 218.6000 218.6000 218.5000 218.5000 43167
2018-09-21 14:48:00 218.5100 218.5800 218.5100 218.5200 30185
2018-09-21 14:49:00 218.5400 218.6050 218.5400 218.6050 34990
2018-09-21 14:50:00 218.6000 218.6050 218.5300 218.6000 33447
2018-09-21 14:51:00 218.5900 218.6450 218.5900 218.6100 39141
2018-09-21 14:52:00 218.6200 218.6800 218.5900 218.5900 46639
2018-09-21 14:53:00 218.6100 218.6100 218.3900 218.3900 83973
2018-09-21 14:54:00 218.3600 218.3800 218.2500 218.3500 65875
2018-09-21 14:55:00 218.3500 218.5500 218.3200 218.3900 72210
2018-09-21 14:56:00 218.4100 218.4700 218.2600 218.2600 72153
2018-09-21 14:57:00 218.2500 218.3000 218.2100 218.2100 74540
2018-09-21 14:58:00 218.2000 218.3000 218.1300 218.2850 65109
2018-09-21 14:59:00 218.2900 218.3056 218.2600 218.2600 33631
2018-09-21 15:00:00 218.2400 218.2800 218.2000 218.2100 59607
2018-09-21 15:01:00 218.2200 218.2200 218.0800 218.1000 61726
2018-09-21 15:02:00 218.0800 218.2800 218.0800 218.2800 81928
2018-09-21 15:03:00 218.2700 218.2772 218.2200 218.2768 61194
2018-09-21 15:04:00 218.2300 218.3100 218.0900 218.1000 85275
2018-09-21 15:05:00 218.1300 218.3400 218.1300 218.3100 56549
2018-09-21 15:06:00 218.3270 218.4700 218.3200 218.4010 82286
2018-09-21 15:07:00 218.3900 218.4100 218.2500 218.2500 80785
2018-09-21 15:08:00 218.2400 218.4000 218.2400 218.4000 98302
2018-09-21 15:09:00 218.3901 218.3901 218.3300 218.3700 75259
2018-09-21 15:10:00 218.3700 218.4200 218.2700 218.2900 85356
2018-09-21 15:11:00 218.3100 218.3200 218.2005 218.2800 67891
2018-09-21 15:12:00 218.2700 218.3450 218.2650 218.3200 60686
2018-09-21 15:13:00 218.3100 218.3200 218.2700 218.2700 63494
2018-09-21 15:14:00 218.2700 218.3400 218.2600 218.3300 96811
2018-09-21 15:15:00 218.3300 218.3300 218.1800 218.2300 125809
2018-09-21 15:16:00 218.2300 218.2600 218.2000 218.2064 76260
2018-09-21 15:17:00 218.2100 218.2300 218.1400 218.1500 75762
2018-09-21 15:18:00 218.1500 218.1900 218.1500 218.1750 56416
2018-09-21 15:19:00 218.1800 218.2100 218.1400 218.1450 80890
2018-09-21 15:20:00 218.1425 218.1600 218.1000 218.1200 97995
2018-09-21 15:21:00 218.1200 218.1300 218.0400 218.1000 86499
2018-09-21 15:22:00 218.1000 218.1200 218.0000 218.0920 177390
2018-09-21 15:23:00 218.1000 218.1000 218.0000 218.0100 120953
2018-09-21 15:24:00 218.0200 218.0301 217.9950 218.0050 168307
2018-09-21 15:25:00 218.0000 218.0200 217.9800 217.9800 107075
2018-09-21 15:26:00 217.9650 217.9700 217.8650 217.9100 104929
2018-09-21 15:27:00 217.9000 218.0000 217.8900 218.0000 168161
2018-09-21 15:28:00 218.0000 218.0700 218.0000 218.0100 103741
2018-09-21 15:29:00 218.0100 218.0100 217.9000 217.9300 81131
2018-09-21 15:30:00 217.9400 217.9800 217.8400 217.8900 131950
2018-09-21 15:31:00 217.8900 217.9000 217.7900 217.8000 132312
2018-09-21 15:32:00 217.7950 217.8700 217.7900 217.7900 120763
2018-09-21 15:33:00 217.7950 217.8000 217.7500 217.7600 119381
2018-09-21 15:34:00 217.7500 217.7898 217.7500 217.7750 136987
2018-09-21 15:35:00 217.7700 217.7700 217.5700 217.5801 142235
2018-09-21 15:36:00 217.5900 217.6900 217.5900 217.6300 155248
2018-09-21 15:37:00 217.6300 217.6400 217.5600 217.5900 153417
2018-09-21 15:38:00 217.5900 217.6300 217.5000 217.5500 221224
2018-09-21 15:39:00 217.5600 217.5600 217.5000 217.5100 128736
2018-09-21 15:40:00 217.5100 217.5500 217.3100 217.3300 198596
2018-09-21 15:41:00 217.3200 217.4000 217.3100 217.3250 144722
2018-09-21 15:42:00 217.3200 217.3752 217.2900 217.3500 164287
2018-09-21 15:43:00 217.3500 217.4100 217.2974 217.4100 178535
2018-09-21 15:44:00 217.4072 217.5600 217.3600 217.5500 153469
2018-09-21 15:45:00 217.5600 217.6400 217.4700 217.4800 251440
2018-09-21 15:46:00 217.4600 217.5450 217.3800 217.5100 165780
2018-09-21 15:47:00 217.5100 217.5500 217.3900 217.4600 140120
2018-09-21 15:48:00 217.4600 217.4600 217.3700 217.4100 156036
2018-09-21 15:49:00 217.4100 217.4400 217.3700 217.4200 145193
2018-09-21 15:50:00 217.4000 218.1000 217.3700 217.5900 931511
2018-09-21 15:51:00 217.5600 217.6650 217.4700 217.5900 339615
2018-09-21 15:52:00 217.5800 217.6350 217.4700 217.5200 195801
2018-09-21 15:53:00 217.5000 217.8600 217.5000 217.8250 321956
2018-09-21 15:54:00 217.8299 217.9425 217.8200 217.8700 294660
2018-09-21 15:55:00 217.8600 217.9000 217.6600 217.8600 443371
2018-09-21 15:56:00 217.8666 218.0900 217.8666 217.8900 395279
2018-09-21 15:57:00 217.8900 217.9400 217.7100 217.8550 330932
2018-09-21 15:58:00 217.8500 218.0400 217.7700 218.0100 488382
2018-09-21 15:59:00 218.0250 218.3500 217.6400 217.6500 1657917
> dim(AAPL)
[1] 100 5
> getSymbols('JPY=X', src='av', api.key=api, periodicity='intraday')
[1] "JPY=X"
> `JPY=X`
JPY=X.Open JPY=X.High JPY=X.Low JPY=X.Close JPY=X.Volume
2018-09-21 15:21:00 112.514 112.522 112.510 112.521 0
2018-09-21 15:22:00 112.520 112.533 112.513 112.531 0
2018-09-21 15:23:00 112.533 112.543 112.527 112.534 0
2018-09-21 15:24:00 112.536 112.547 112.510 112.540 0
2018-09-21 15:25:00 112.544 112.544 112.530 112.538 0
2018-09-21 15:26:00 112.538 112.539 112.519 112.531 0
2018-09-21 15:27:00 112.528 112.531 112.525 112.531 0
2018-09-21 15:28:00 112.527 112.533 112.526 112.531 0
2018-09-21 15:29:00 112.532 112.533 112.522 112.526 0
2018-09-21 15:30:00 112.525 112.527 112.518 112.524 0
2018-09-21 15:31:00 112.525 112.528 112.517 112.526 0
2018-09-21 15:32:00 112.522 112.532 112.522 112.532 0
2018-09-21 15:33:00 112.533 112.533 112.521 112.531 0
2018-09-21 15:34:00 112.531 112.534 112.516 112.516 0
2018-09-21 15:35:00 112.522 112.525 112.513 112.519 0
2018-09-21 15:36:00 112.518 112.525 112.505 112.525 0
2018-09-21 15:37:00 112.520 112.532 112.518 112.532 0
2018-09-21 15:38:00 112.524 112.540 112.524 112.537 0
2018-09-21 15:39:00 112.538 112.541 112.530 112.537 0
2018-09-21 15:40:00 112.537 112.538 112.528 112.533 0
2018-09-21 15:41:00 112.532 112.532 112.515 112.515 0
2018-09-21 15:42:00 112.530 112.530 112.516 112.516 0
2018-09-21 15:43:00 112.520 112.524 112.512 112.524 0
2018-09-21 15:44:00 112.522 112.526 112.516 112.525 0
2018-09-21 15:45:00 112.525 112.533 112.500 112.522 0
2018-09-21 15:46:00 112.523 112.534 112.519 112.532 0
2018-09-21 15:47:00 112.532 112.535 112.520 112.533 0
2018-09-21 15:48:00 112.534 112.547 112.530 112.541 0
2018-09-21 15:49:00 112.533 112.547 112.533 112.545 0
2018-09-21 15:50:00 112.546 112.559 112.540 112.555 0
2018-09-21 15:51:00 112.559 112.562 112.543 112.560 0
2018-09-21 15:52:00 112.558 112.562 112.549 112.552 0
2018-09-21 15:53:00 112.553 112.566 112.548 112.566 0
2018-09-21 15:54:00 112.564 112.566 112.549 112.555 0
2018-09-21 15:55:00 112.551 112.551 112.520 112.545 0
2018-09-21 15:56:00 112.545 112.549 112.538 112.543 0
2018-09-21 15:57:00 112.543 112.550 112.531 112.548 0
2018-09-21 15:58:00 112.549 112.553 112.543 112.550 0
2018-09-21 15:59:00 112.547 112.567 112.545 112.564 0
2018-09-21 16:00:00 112.562 112.573 112.557 112.568 0
2018-09-21 16:01:00 112.570 112.573 112.563 112.570 0
2018-09-21 16:02:00 112.570 112.574 112.565 112.570 0
2018-09-21 16:03:00 112.570 112.571 112.559 112.571 0
2018-09-21 16:04:00 112.570 112.571 112.565 112.565 0
2018-09-21 16:05:00 112.530 112.570 112.530 112.570 0
2018-09-21 16:06:00 112.562 112.568 112.562 112.563 0
2018-09-21 16:07:00 112.564 112.564 112.555 112.555 0
2018-09-21 16:08:00 112.520 112.555 112.520 112.550 0
2018-09-21 16:09:00 112.547 112.551 112.545 112.551 0
2018-09-21 16:10:00 112.550 112.552 112.535 112.540 0
2018-09-21 16:11:00 112.544 112.544 112.538 112.543 0
2018-09-21 16:12:00 112.543 112.544 112.536 112.538 0
2018-09-21 16:13:00 112.538 112.538 112.529 112.530 0
2018-09-21 16:14:00 112.526 112.542 112.510 112.539 0
2018-09-21 16:15:00 112.540 112.547 112.535 112.542 0
2018-09-21 16:16:00 112.542 112.544 112.534 112.543 0
2018-09-21 16:17:00 112.537 112.554 112.537 112.554 0
2018-09-21 16:18:00 112.553 112.553 112.537 112.549 0
2018-09-21 16:19:00 112.551 112.551 112.544 112.551 0
2018-09-21 16:20:00 112.552 112.560 112.539 112.551 0
2018-09-21 16:21:00 112.555 112.556 112.551 112.555 0
2018-09-21 16:22:00 112.555 112.559 112.530 112.558 0
2018-09-21 16:23:00 112.559 112.560 112.552 112.558 0
2018-09-21 16:24:00 112.557 112.558 112.544 112.544 0
2018-09-21 16:25:00 112.544 112.544 112.533 112.541 0
2018-09-21 16:26:00 112.541 112.590 112.541 112.587 0
2018-09-21 16:27:00 112.589 112.590 112.580 112.589 0
2018-09-21 16:28:00 112.589 112.592 112.573 112.587 0
2018-09-21 16:29:00 112.588 112.592 112.560 112.582 0
2018-09-21 16:30:00 112.591 112.596 112.580 112.595 0
2018-09-21 16:31:00 112.595 112.596 112.577 112.589 0
2018-09-21 16:32:00 112.588 112.589 112.572 112.588 0
2018-09-21 16:33:00 112.585 112.594 112.585 112.594 0
2018-09-21 16:34:00 112.596 112.597 112.585 112.596 0
2018-09-21 16:35:00 112.596 112.600 112.570 112.597 0
2018-09-21 16:36:00 112.597 112.608 112.580 112.602 0
2018-09-21 16:37:00 112.602 112.602 112.585 112.600 0
2018-09-21 16:38:00 112.601 112.602 112.587 112.597 0
2018-09-21 16:39:00 112.600 112.603 112.592 112.600 0
2018-09-21 16:40:00 112.597 112.607 112.593 112.604 0
2018-09-21 16:41:00 112.604 112.607 112.601 112.604 0
2018-09-21 16:42:00 112.605 112.605 112.581 112.599 0
2018-09-21 16:43:00 112.598 112.598 112.550 112.584 0
2018-09-21 16:44:00 112.586 112.586 112.570 112.582 0
2018-09-21 16:45:00 112.582 112.586 112.543 112.549 0
2018-09-21 16:46:00 112.553 112.561 112.540 112.554 0
2018-09-21 16:47:00 112.555 112.558 112.510 112.543 0
2018-09-21 16:48:00 112.547 112.548 112.534 112.546 0
2018-09-21 16:49:00 112.546 112.547 112.540 112.547 0
2018-09-21 16:50:00 112.547 112.567 112.520 112.560 0
2018-09-21 16:51:00 112.561 112.561 112.547 112.555 0
2018-09-21 16:52:00 112.553 112.558 112.546 112.557 0
2018-09-21 16:53:00 112.554 112.558 112.541 112.549 0
2018-09-21 16:54:00 112.558 112.558 112.549 112.557 0
2018-09-21 16:55:00 112.557 112.558 112.533 112.541 0
2018-09-21 16:56:00 112.550 112.583 112.538 112.557 0
2018-09-21 16:57:00 112.547 112.556 112.502 112.517 0
2018-09-21 16:58:00 112.517 112.543 112.505 112.522 0
2018-09-21 16:59:00 112.530 112.584 112.523 112.539 0
2018-09-21 17:00:00 112.544 112.544 112.544 112.544 0
> dim(`JPY=X`)
[1] 100 5
```
```{r read-data}
```
# Modelling
- [Is there a random element in Markov Chain?](https://stackoverflow.com/questions/52867314/is-there-a-random-element-in-markov-chain) use `ChannelAttribution` package for Markov Chain modelling.
- [如何用R软件求随机生成的一个100维0-1向量(即向量的元素由0和1组成),中1连续出现的最大次数](http://ask.pinggu.org/q-57886.html) introduced using `rle` to count the states.
# Model Comparison
Here we plot a graph for high volume data points.
- [Question: R Plotting Line Graph With Large Dataset](https://www.biostars.org/p/47288/)
- [More efficient plot functions in R when millions of points are present?](https://stats.stackexchange.com/questions/7348/more-efficient-plot-functions-in-r-when-millions-of-points-are-present?answertab=votes#tab-top)
- [Visualizing Big Data with R](https://beta.rstudioconnect.com/jmcphers/datavis-talk/datavis.html)
```{r graph-Hi}
```
```{r}
```
```{r graph-Lo}
```
```{r graph-Cl}
```
# Conclusion
## Speech
## Future Works
The *Markov Hidden Model* and *Autoregressive Markov Switching Model* in <span style='color:goldenrod'>*解密复兴科技 - 基于隐蔽马尔科夫模型的时序分析方法*</span> will be in another study.
API skill need to learn in order to write a real algothmic trading website.
```{r options, echo = FALSE}
## Set options back to original options
options(warn = 0)
```
# Appendix
## Documenting File Creation
It's useful to record some information about how your file was created.
- File creation date: 2018-09-04
- File latest updated date: `r today('Asia/Tokyo')`
- `r R.version.string`
- R version (short form): `r getRversion()`
- [**rmarkdown** package](https://github.com/rstudio/rmarkdown) version: `r packageVersion('rmarkdown')`
- File version: 1.0.1
- Author Profile: [®γσ, Eng Lian Hu](https://beta.rstudioconnect.com/content/3091/ryo-eng.html)
- GitHub: [Source Code](https://github.com/englianhu/binary.com-interview-question)
- Additional session information:
```{r info, echo=FALSE, warning=FALSE, results='asis'}
sys1 <- session_info()$platform %>%
unlist %>% data.frame(Category = names(.), session_info = .)
rownames(sys1) <- NULL
sys2 <- data.frame(Sys.info()) %>%
mutate(Category = rownames(.)) %>%
.[2:1]
names(sys2)[2] <- c('Sys.info')
rownames(sys2) <- NULL
if (nrow(sys1) == 7 & nrow(sys2) == 8) {
sys1 %<>% rbind(., data.frame(
Category = 'Current time',
session_info = paste(as.character(lubridate::now('Asia/Tokyo')), 'JST')))
} else {
sys2 %<>% rbind(., data.frame(
Category = 'Current time',
Sys.info = paste(as.character(lubridate::now('Asia/Tokyo')), 'JST')))
}
cbind(sys1, sys2) %>%
kable(caption = 'Additional session information:') %>%
kable_styling(bootstrap_options = c('striped', 'hover', 'condensed', 'responsive'))
rm(sys1, sys2)
```
## Reference
01. [**Betting Strategy and Model Validation - Part II** *by ®γσ, Lian Hu (2017)*](https://englianhu.github.io/2017/10/Betting_Strategy_and_Model_Validation_-_Part_02/)
02. [**binary.com : Job Application - Quantitative Analyst** *by ®γσ, Lian Hu (2017)*](https://github.com/englianhu/binary.com-interview-question)
03. [**What is high-frequency trading?** *by Investopedia Staff*](http://www.investopedia.com/ask/answers/09/high-frequency-trading.asp)
04. [Understanding the Kelly Capital Growth Investment Strategy](https://github.com/scibrokes/kelly-criterion/blob/master/references/Understanding%20the%20Kelly%20Capital%20Growth%20Investment%20Strategy.pdf)
05. [如何用R语言开始量化投资](https://github.com/scibrokes/real-time-fxcm/blob/master/reference/%E5%A6%82%E4%BD%95%E7%94%A8R%E8%AF%AD%E8%A8%80%E5%BC%80%E5%A7%8B%E9%87%8F%E5%8C%96%E6%8A%95%E8%B5%84.pdf)
06. [解密复兴科技 - 基于隐蔽马尔科夫模型的时序分析方法](https://github.com/scibrokes/real-time-fxcm/blob/master/reference/%E8%A7%A3%E5%AF%86%E5%A4%8D%E5%85%B4%E7%A7%91%E6%8A%80%20-%20%E5%9F%BA%E4%BA%8E%E9%9A%90%E8%94%BD%E9%A9%AC%E5%B0%94%E7%A7%91%E5%A4%AB%E6%A8%A1%E5%9E%8B%E7%9A%84%E6%97%B6%E5%BA%8F%E5%88%86%E6%9E%90%E6%96%B9%E6%B3%95.pdf)
07. [原则 - 雷·达里奥](https://github.com/scibrokes/analyse-the-finance-and-stocks-price-of-bookmakers/blob/master/reference/%E5%8E%9F%E5%88%99%20-%20%E9%9B%B7%C2%B7%E8%BE%BE%E9%87%8C%E5%A5%A5.pdf)
08. [binary.com Interview Question I - Tick-Data-HiLo For Daily Trading <span style='color:red'>(Blooper)</span>](http://rpubs.com/englianhu/binary-Q1TD)
09. [Markov-Switching Autoregressive Models for Wind Times Series (ppt)](https://github.com/englianhu/binary.com-interview-question/blob/master/reference/Markov-Switching%20Autoregressive%20Models%20for%20Wind%20Time%20Series%20(ppt).pdf)
10. [Markov-Switching Autoregressive Models for Wind Times Series](https://github.com/englianhu/binary.com-interview-question/blob/master/reference/Markov-Switching%20Autoregressive%20Models%20for%20Wind%20Time%20Series.pdf)
12. [Modelling Exchange Rates using Regime Switching Models](https://github.com/englianhu/binary.com-interview-question/blob/master/reference/Modelling%20Exchange%20Rates%20using%20Regime%20Switching%20Models.pdf)
13. [Financial Risk Modelling and Portfolio Optimization with R (2nd Edt)](https://github.com/englianhu/binary.com-interview-question/blob/master/reference/Financial%20Risk%20Modelling%20and%20Portfolio%20Optimization%20with%20R%20(2nd%20Edt).pdf)
14. [量化交易 - 如何建立自己的算法交易事业](https://github.com/englianhu/data-analysis/blob/master/reference/%E9%87%8F%E5%8C%96%E4%BA%A4%E6%98%93%20-%20%E5%A6%82%E4%BD%95%E5%BB%BA%E7%AB%8B%E8%87%AA%E5%B7%B1%E7%9A%84%E7%AE%97%E6%B3%95%E4%BA%A4%E6%98%93%E4%BA%8B%E4%B8%9A.pdf)
15. [Developing High-Frequency Equities Trading Models]()
16. [JPMorgan最新:量子机器学习的金融应用](https://zhuanlan.zhihu.com/p/424053731) ([Quantum Machine Learning for Finance.pdf](Quantum Machine Learning for Finance.pdf))
17. [知乎:高频量化交易为什么这么强调低延迟?](https://www.zhihu.com/question/511736350/answer/2511420377)
18. [如何缓解量化交易中存在的"低信噪比"现象?](https://www.zhihu.com/question/534058888)
19. [我叫文辉,一位一直从事于CPU行业的IC工程师](https://www.wenhui.space/tags/cpu)
20. [issuu 超标量处理器设计 姚永斌编著 Sample](https://issuu.com/xiuxiuebook/docs/____________________________________e8d42263cfc20b)
21. [超标量处理器设计](https://blog.csdn.net/weixin_47955824/category_11811483.html)
22.
23.
---
[<img src="www/Scibrokes.png" height="14"/> Sςιβrοκεrs Trαdιηg®](http://www.scibrokes.com)<br>
<span style='color:RoyalBlue'>**[<img src="www/Scibrokes.png" height="14"/> 世博量化®](http://www.scibrokes.com)企业知识产权及版权所有,盗版必究。**</span>