-
Notifications
You must be signed in to change notification settings - Fork 4
/
README.Rmd
95 lines (73 loc) · 3.39 KB
/
README.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
---
output:
md_document:
variant: markdown_github
html_document:
variant: markdown_github
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo=FALSE, warning=FALSE}
library(knitr)
opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
fig.align = "center",
fig.retina = 2,
out.width = "100%",
dpi = 96
)
knit_hooks$set(pngquant = hook_pngquant)
```
# intradayModel
Our package uses state-of-the-art state-space models to facilitate the modeling and forecasting of financial intraday signals. It currently offers a univariate model for intraday trading volume, with new features on intraday volatility and multivariate models in development. It is a valuable tool for anyone interested in exploring intraday, algorithmic, and high-frequency trading.
## Installation
To install the latest stable version of **intradayModel** from [CRAN](https://cran.r-project.org/web/packages/intradayModel/index.html), run the following commands in R:
```{r, eval=FALSE}
install.packages("intradayModel")
```
To install the development version of **intradayModel** from [GitHub](https://github.com/convexfi/intradayModel), run the following commands in R:
```{r, eval=FALSE}
install.packages("devtools")
devtools::install_github("convexfi/intradayModel")
```
Please cite **intradayModel** in publications:
```{r, eval=FALSE}
citation("intradayModel")
```
## Quick Start
To get started, we load our package and sample data: the 15-minute intraday trading volume of AAPL from 2019-01-02 to 2019-06-28, covering 124 trading days. We use the first 104 trading days for fitting, and the last 20 days for evaluation of forecasting performance.
```{r, message = FALSE}
library(intradayModel)
data(volume_aapl)
volume_aapl[1:5, 1:5] # print the head of data
volume_aapl_training <- volume_aapl[, 1:104]
volume_aapl_testing <- volume_aapl[, 105:124]
```
Next, we fit a univariate state-space model using `fit_volume()` function.
```{r}
model_fit <- fit_volume(volume_aapl_training)
```
Once the model is fitted, we can analyze the hidden components of any intraday volume based on all its observations. By calling `decompose_volume()` function with `purpose = "analysis"`, we obtain the smoothed daily, seasonal, and intraday dynamic components. It involves incorporating both past and future observations to refine the state estimates.
```{r}
analysis_result <- decompose_volume(purpose = "analysis", model_fit, volume_aapl_training)
# visualization
plots <- generate_plots(analysis_result)
plots$log_components
```
To see how well our model performs on new data, we call `forecast_volume()` function to do one-bin-ahead forecast on the testing set.
```{r}
forecast_result <- forecast_volume(model_fit, volume_aapl_testing)
# visualization
plots <- generate_plots(forecast_result)
plots$original_and_forecast
```
## Contributing
We welcome all sorts of contributions. Please feel free to open an issue
to report a bug or discuss a feature request.
## Citation
If you make use of this software please consider citing:
- Chen, R., Feng, Y., and Palomar, D. (2016). Forecasting intraday trading volume: A Kalman filter approach. <https://dx.doi.org/10.2139/ssrn.3101695>
## Links
Package: [GitHub](https://github.com/convexfi/intradayModel)
Vignette: [GitHub-vignette](https://htmlpreview.github.io/?https://github.com/convexfi/intradayModel/blob/master/vignettes/intradayModel.html).