forked from Sandy4321/Betting-Strategy-and-Model-Validation
-
Notifications
You must be signed in to change notification settings - Fork 7
/
BS and MV - Extention.Rmd
156 lines (116 loc) · 6.01 KB
/
BS and MV - Extention.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
---
title: "<img src='https://raw.githubusercontent.com/scibrokes/betting-strategy-and-model-validation/master/figure/SmartOdds.png' width='840'>"
subtitle: "[<span style='color:blue'>Betting Strategy and Model Validation II (Extention)</span>](https://github.com/scibrokes/betting-strategy-and-model-validation)"
author: "[<span style='color:blue'>®γσ, Lian Hu</span>](https://englianhu.github.io/) <img src='https://raw.githubusercontent.com/scibrokes/betting-strategy-and-model-validation/master/www/ENG.jpg' width='24'> <img src='https://raw.githubusercontent.com/scibrokes/betting-strategy-and-model-validation/master/www/RYO.jpg?raw=true' width='24'>白戸則道®"
date: "`r Sys.Date()`"
output:
tufte::tufte_html:
toc: yes
toc_depth: 4
self_contained: no
tufte::tufte_book:
citation_package: natbib
latex_engine: xelatex
tufte::tufte_handout:
citation_package: natbib
latex_engine: xelatex
link-citations: yes
---
```{r setup}
#'@ rm(list = ls(all = TRUE))
suppressPackageStartupMessages(library('BBmisc'))
pkgs <- c('knitr', 'kableExtra', 'tint', 'devtools', 'lubridate', 'data.table', 'quantmod', 'plyr', 'stringr', 'magrittr', 'dplyr', 'tidyverse', 'htmltools', 'highcharter', 'googleVis', 'formattable', 'DT', 'fst')
funs <- c('plotChart2.R')
suppressAll(lib(pkgs))
l_ply(paste0('./function/', funs), source)
## Set option to below if you want to plot an independent webpage with graph
#'@ op <- options(gvis.plot.tag=NULL)
op <- options(gvis.plot.tag = 'chart')
options(gvis.plot.tag = 'chart', warn = -1)
rm(pkgs)
```
# 1. Introduction
By refer to *Ryo Eng Lian Hu (2017)*^[reference paper 1], I tried to model few Kelly funds for financial trading. Today I am zooming on the Kellys fund.
# 2. Data
Firstly, we need to load a large size data.
- [Fast data loading from files to R](http://appsilondatascience.com/blog/rstats/2017/04/11/fast-data-load.html)
- [`fst`: Fast serialization of R data frames](http://blog.revolutionanalytics.com/2017/02/fst-fast-serialization-of-r-data-frames.html)
- [fstpackage.github.io *Lightning Fast Serialization of Data Frames for R*](http://www.fstpackage.org/)
```{r read-data}
## http://appsilondatascience.com/blog/rstats/2017/04/11/fast-data-load.html
## http://blog.revolutionanalytics.com/2017/02/fst-fast-serialization-of-r-data-frames.html
#'@ BR <- readRDS('./data/BR.rds')
#'@ BRSum <- fread('./data/BRSum.csv')
## https://stackoverflow.com/questions/16300344/how-to-flatten-a-list-of-lists-in-r?answertab=votes#tab-top
#'@ BRM <- do.call(c, unlist(BR$KM, recursive = FALSE))
Date <- readRDS('./data/K1.rds')$data$Date
#'@ BRM1 <- llply(BRM, function(x) x[-c(1:5)])
#'@ BRM1 <- bind_cols(BRM1)
#'@ saveRDS(BRM1, './data/BRM1.rds')
BRM1 <- try(readRDS('./data/BRM1.rds'), silent = TRUE)
#'@ rm(BR, BRM)
```
```{r arrange-data}
## build data frame
BRM.Hi <- tryCatch(data.table(Date, Hi(BRM1)), error = function(e) Hi(BRM1))
BRM.Lo <- tryCatch(data.table(Date, Lo(BRM1)), error = function(e) Lo(BRM1))
BRM.Cl <- tryCatch(data.table(Date, Cl(BRM1)), error = function(e) Cl(BRM1))
BR.Hi <- fread('./data/BRSum.Hi.csv')
BR.Lo <- fread('./data/BRSum.Lo.csv')
BR.Cl <- fread('./data/BRSum.Cl.csv')
```
# 3. 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}
#'@ plotChart2(Hi(BRM1), chart.type = 'Hi')
#'@ hchart(BRM.Hi, 'line')
## https://cran.r-project.org/web/packages/googleVis/vignettes/googleVis_examples.html
Line <- gvisLineChart(Hi(BRM1))
plot(Line)
```
```{r}
ggplot(data = BRM.Hi, aes()) + geom_line() + geom_point(size = 4, shape = 21, fill = 'white')
```
```{r graph-Lo}
Line <- gvisLineChart(Lo(BRM1))
plot(Line)
```
```{r graph-Cl}
Line <- gvisLineChart(Cl(BRM1))
plot(Line)
```
# 4. Conclusion
```{r stopPar, echo = FALSE}
## Set options back to original options
options(op)
options(warn = 0)
```
# 5. Appendix
## 5.1 Documenting File Creation
It's useful to record some information about how your file was created.
- File creation date: 2017-10-16
- File latest updated date: `r Sys.Date()`
- `r R.version.string`
- R version (short form): `r getRversion()`
- [<span style='color:blue'>**rmarkdown** package</span>](https://github.com/rstudio/rmarkdown) version: `r packageVersion('rmarkdown')`
- [<span style='color:blue'>**tufte** package</span>](https://github.com/rstudio/tufte) version: `r packageVersion('tufte')`
- File version: 1.0.1
- Author Profile: [<span style='color:blue'>®γσ, Eng Lian Hu</span>](https://beta.rstudioconnect.com/englianhu/ryo-eng/)
- GitHub: [<span style='color:blue'>Source Code</span>](https://github.com/englianhu/binary.com-interview-question)
- Additional session information
```{r info, echo = FALSE, warning = FALSE, results = 'asis'}
suppressMessages(require('dplyr', quietly = TRUE))
suppressMessages(require('formattable', quietly = TRUE))
lubridate::now()
sys1 <- devtools::session_info()$platform %>% unlist %>% data.frame(Category = names(.), session_info = .)
rownames(sys1) <- NULL
sys1 %>% formattable %>% as.htmlwidget
data.frame(Sys.info()) %>% mutate(Category = rownames(.)) %>% .[2:1] %>% rename(Category = Category, Sys.info = Sys.info..) %>% formattable %>% as.htmlwidget
rm(sys1)
```
## 5.2 Reference
01. [<span style='color:blue'>Betting Strategy and Model Validation - Part II</span>](https://englianhu.github.io/2017/10/Betting_Strategy_and_Model_Validation_-_Part_02/)
**Powered by - Copyright® Intellectual Property Rights of <img src='https://raw.githubusercontent.com/englianhu/binary.com-interview-question/master/www/oda-army2.jpg?raw=true' width='24'> [<span style='color:blue'>Scibrokes®</span>](http://www.scibrokes.com)個人の経営企業**