-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathREADME.Rmd
More file actions
159 lines (120 loc) · 5.86 KB
/
README.Rmd
File metadata and controls
159 lines (120 loc) · 5.86 KB
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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
# set options
Sys.setenv(OPENSSL_CONF = "/dev/null")
options(talib.chart.modebar = FALSE)
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
fig.dpi = 120,
message = FALSE,
warning = FALSE,
echo = FALSE
)
```
# {talib}: A Technical Analysis and Candlestick Pattern Library in R <img src="man/figures/logo.png" align="right" height="170" alt="" />
<!-- badges: start -->
[](https://github.com/serkor1/ta-lib-R/actions/workflows/R-CMD-check.yaml)
[](https://github.com/serkor1/ta-lib-R/actions/workflows/remote-install.yaml)
[](https://app.codecov.io/gh/serkor1/ta-lib-R)
[](https://CRAN.R-project.org/package=talib)
[](https://r-pkg.org/pkg/talib)
<!-- badges: end -->
[{talib}](https://serkor1.github.io/ta-lib-R/) is an `R`-package for Technical Analysis and algorithmic Candlestick pattern recognition built on the `C` library [TA-Lib](https://github.com/TA-Lib/ta-lib). [{talib}](https://serkor1.github.io/ta-lib-R/) extends [{TTR}](https://github.com/joshuaulrich/TTR) by adding Candlestick pattern recognition to the pool of available indicators, and interactive charts via [{plotly}](https://github.com/plotly/plotly.R).
[TA-Lib](https://github.com/TA-Lib/ta-lib) supports 200+ indicators for Technical Analysis and Candlestick Patterns, all of which are available in [{talib}](https://serkor1.github.io/ta-lib-R/).
## Types of Indicators and Interface
In the core C library functions are named as `TA_INDICATOR()` and `TA_CDLPATTERN()` for indicators and patterns respectively. In the `Python`-wrapper the functions are named `INDICATOR()` and `CDLPATTERN()`---but this `R` package follows the [tidyverse styleguide](https://style.tidyverse.org/) and therefore the naming is inconsistent with the core library and the Python wrapper. See below for an example of the mapping:
<div align="center">
| Function Group | TA-Lib (core) | {talib} |
|:----------------------|:---------------------|:---------------------------|
| Overlap Studies |`TA_BBANDS()` | `bollinger_bands()` |
| Momentum Indicators |`TA_CCI()` | `commodity_channel_index()`|
| Volume Indicators |`TA_OBV()` | `on_balance_volume()` |
| Volatility Indicators | `TA_ATR()` | `average_true_range()` |
| Price Transform | `TA_AVGPRICE()` | `average_price()` |
| Cycle Indicators | `TA_HT_SINE()` | `ht_sine_wave()` |
| Pattern Recognition | `TA_CDLHANGINGMAN()` | `hanging_man()` |
</div>
However, each function in [{talib}](https://serkor1.github.io/ta-lib-R/) is aliased so its consistent with the remaining ecosystem. See below:
```{r, echo = TRUE}
all.equal(
target = talib::bollinger_bands(talib::BTC),
current = talib::BBANDS(talib::BTC)
)
```
The aliases are exported but are not a part of the documentation, but they behave exactly the same as the main functions as demonstrated above.
## Basic Usage
Below are an example on how to use [{talib}](https://serkor1.github.io/ta-lib-R/) to calculate an indicator, identify a candlestick pattern and charting it all together.
### Indicators
```{r pattern, echo = TRUE}
## identify Harami
## patterns
tail(
talib::harami(
talib::BTC
)
)
```
```{r indicator, echo = TRUE}
## calculate bollinger
## bands
tail(
talib::bollinger_bands(
talib::BTC
)
)
```
### Charting
Below is an example on how to use `chart()` and `indicator()`.
```{r charting, fig.align = 'center', echo = TRUE}
{
## construct the chart
## with the default values
## (candlesticks by default)
talib::chart(talib::BTC)
## chart the bollinger bands
talib::indicator(
talib::bollinger_bands
)
## chart RSI
talib::indicator(
talib::RSI
)
## chart volume
talib::indicator(
talib::trading_volume
)
## identify 'Harami'-patterns
## from the last 66 candles and
## chart
talib::indicator(
talib::harami,
data = talib::BTC,
subset = 1:nrow(talib::BTC) %in% 300:nrow(talib::BTC)
)
}
```
## Installation[^1]
[{talib}](https://serkor1.github.io/ta-lib-R/) can be installed using [{pak}](https://github.com/r-lib/pak) from CRAN[^2], or Github.
### Install from source
The latest version of [{talib}](https://serkor1.github.io/ta-lib-R/) can be installed directly from source. The vendoring of [TA-Lib](https://github.com/TA-Lib/ta-lib) is handled by `configure` on Windows, MacOS and Linux.
#### Using [{pak}](https://github.com/r-lib/pak)
```{r devel_install, echo = TRUE, eval = FALSE}
## install remote
pak::pak("serkor1/ta-lib-R")
```
#### Using BASH
```shell
git clone --recursive https://github.com/serkor1/ta-lib-R.git
cd ta-lib-R
make build
```
Use `make` to see package-level build-tools.
## Code of Conduct
Please note that [{talib}](https://serkor1.github.io/ta-lib-R/) is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.
[^1]: [TA-Lib](https://github.com/TA-Lib/ta-lib) is vendored in [{talib}](https://serkor1.github.io/ta-lib-R/) via `CMake`, so it is not necessary to have [TA-Lib](https://github.com/TA-Lib/ta-lib) pre-installed. Some systems (Windows in particular) may require you to explicitly install and link `CMake` for [{talib}](https://serkor1.github.io/ta-lib-R/) to build properly.
[^2]: Not yet available.