ta_lib_ffi 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +35 -3
- data/README.md +51 -56
- data/Rakefile +13 -0
- data/lib/ta_lib_ffi/doc.rb +138 -0
- data/lib/ta_lib_ffi/version.rb +5 -0
- data/lib/ta_lib_ffi.rb +2396 -248
- data/ta_lib_ffi.gemspec +9 -6
- metadata +52 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c3c72ea70613feff1a82c4043750737ceb8b3addabbc39a5a4c08d030c3f9a32
|
|
4
|
+
data.tar.gz: 4cbd7911b66a29ef0d7d333fbdf57392d75d81bfb5204b71463dc17eb51ee32d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1e10c494d6e06892b1acdc3a281b4ae9d7c36b0ce3afbd5966056ab58f82105d057a34c566acce85dc3f3b8bb7100c715d5cdab89d0a1d884e74e0d5127c83b8
|
|
7
|
+
data.tar.gz: f9bce5cae744b44f6947a73cf9244bb9a7495d937d1b19f093213a411f957d1154a030231bbd385918cde9e9254bfe9d7a812b0609aee55e75c9512526f0e629
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,36 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.4.0] - 2026-11-23
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Support for the TA-Lib 0.8.3 function metadata layout and indicators, including ALMA, alongside 0.6.4. Set `TA_LIB_PATH` to select a particular shared library.
|
|
13
|
+
- Direct C comparisons for the indicators in each installed library and CI coverage for the latest stable Ruby 4.x.
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- Fixed HTML documentation generation on Ruby 4. The local API reference includes the indicators and defaults from the selected TA-Lib C library.
|
|
18
|
+
- Fixed unbounded memory growth during repeated indicator calls. Numeric arrays are packed in bulk, and Ruby owns the input and output buffers for the duration of each call.
|
|
19
|
+
- Invalid input counts, incorrectly grouped price fields, unequal lengths and unknown keywords raise `TALibFFI::TALibError` with details. Previously unknown keywords silently used the default.
|
|
20
|
+
|
|
21
|
+
Indicator defaults and results follow the installed TA-Lib version. This includes the BBANDS default period and how MINMAXINDEX selects among equal extrema.
|
|
22
|
+
|
|
23
|
+
## [0.3.0] - 2025-02-23
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
- Auto-generated YARD documentation
|
|
27
|
+
- GitHub Actions PR Agent workflow
|
|
28
|
+
- Cross-platform test support (Ubuntu, macOS, Windows)
|
|
29
|
+
|
|
30
|
+
### Changed
|
|
31
|
+
- Optimized function documentation generator
|
|
32
|
+
- Improved error handling and validation
|
|
33
|
+
- Updated development dependencies
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
- Fixed prices handling in multiple technical analysis functions
|
|
37
|
+
|
|
8
38
|
## [0.2.0] - 2025-01-21
|
|
9
39
|
|
|
10
40
|
### Added
|
|
@@ -15,7 +45,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
15
45
|
- Renamed main file from `lib/ta_lib.rb` to `lib/ta_lib_ffi.rb`
|
|
16
46
|
- Updated require statements in specs and gemspec
|
|
17
47
|
|
|
18
|
-
## [0.1.0] -
|
|
48
|
+
## [0.1.0] - 2025-01-21
|
|
19
49
|
|
|
20
50
|
### Added
|
|
21
51
|
- Initial release of ta_lib_ffi
|
|
@@ -39,5 +69,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
39
69
|
### Security
|
|
40
70
|
- N/A
|
|
41
71
|
|
|
42
|
-
[0.
|
|
43
|
-
[0.
|
|
72
|
+
[0.4.0]: https://github.com/TA-Lib/ta-lib-ruby/compare/v0.3.0...v0.4.0
|
|
73
|
+
[0.3.0]: https://github.com/TA-Lib/ta-lib-ruby/compare/v0.2.0...v0.3.0
|
|
74
|
+
[0.2.0]: https://github.com/TA-Lib/ta-lib-ruby/compare/v0.1.0...v0.2.0
|
|
75
|
+
[0.1.0]: https://github.com/TA-Lib/ta-lib-ruby/releases/tag/v0.1.0
|
data/README.md
CHANGED
|
@@ -1,90 +1,85 @@
|
|
|
1
1
|
# TALibFFI
|
|
2
2
|
|
|
3
|
-
](https://github.com/TA-Lib/ta-lib-ruby/actions/workflows/main.yml)
|
|
4
|
+
[](https://rubygems.org/gems/ta_lib_ffi)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
`ta_lib_ffi` exposes the technical indicators in your installed TA-Lib C library as Ruby methods. A three-period simple moving average returns its first value at the third price.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## Requirements
|
|
8
|
+
```ruby
|
|
9
|
+
require "ta_lib_ffi"
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
close = [10, 11, 12, 13, 14]
|
|
12
|
+
TALibFFI.sma(close, time_period: 3)
|
|
13
|
+
# => [11.0, 12.0, 13.0]
|
|
14
|
+
```
|
|
13
15
|
|
|
14
16
|
## Installation
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
You need Ruby 3.1 or later and the TA-Lib C shared library 0.6.4 or later. If you already use C library 0.6.4, you can keep it when upgrading the gem to 0.4.0.
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
Download
|
|
20
|
+
- **macOS** — Run `brew install ta-lib`.
|
|
21
|
+
- **Debian or Ubuntu** — Download the `.deb` matching `dpkg --print-architecture`. For example, on `amd64`, install the downloaded file with `sudo dpkg -i ./ta-lib_0.8.3_amd64.deb`. [Debian packages](https://ta-lib.org/install/c/#linux-debian-packages)
|
|
22
|
+
- **Windows x64** — Run the [TA-Lib 0.8.3 x64 installer](https://github.com/TA-Lib/ta-lib/releases/download/v0.8.3/ta-lib-0.8.3-windows-x86_64.msi).
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
brew install ta-lib
|
|
24
|
-
```
|
|
24
|
+
For a custom installation, set `TA_LIB_PATH` to the full path of the shared library (`.so`, `.dylib` or `.dll`) before requiring the gem. [TA-Lib installation guide](https://ta-lib.org/install/c/)
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
# For Intel/AMD 64-bit
|
|
29
|
-
wget https://github.com/ta-lib/ta-lib/releases/download/v0.6.4/ta-lib_0.6.4_amd64.deb
|
|
30
|
-
sudo dpkg -i ta-lib_0.6.4_amd64.deb
|
|
26
|
+
Add the gem to your application with `bundle add ta_lib_ffi`, or install it directly with `gem install ta_lib_ffi`.
|
|
31
27
|
|
|
32
|
-
|
|
33
|
-
wget https://github.com/ta-lib/ta-lib/releases/download/v0.6.4/ta-lib_0.6.4_arm64.deb
|
|
34
|
-
sudo dpkg -i ta-lib_0.6.4_arm64.deb
|
|
28
|
+
## Inputs and results
|
|
35
29
|
|
|
36
|
-
|
|
37
|
-
wget https://github.com/ta-lib/ta-lib/releases/download/v0.6.4/ta-lib_0.6.4_i386.deb
|
|
38
|
-
sudo dpkg -i ta-lib_0.6.4_i386.deb
|
|
39
|
-
```
|
|
30
|
+
Pass price fields together in the order the indicator expects. For Average True Range (ATR), pass high, low and close as one argument. All input series must be nonempty and have the same length.
|
|
40
31
|
|
|
41
|
-
|
|
32
|
+
```ruby
|
|
33
|
+
high = [11, 13, 12, 14, 15]
|
|
34
|
+
low = [9, 10, 9, 11, 12]
|
|
35
|
+
close = [10, 12, 10, 13, 14]
|
|
42
36
|
|
|
43
|
-
|
|
37
|
+
TALibFFI.atr([high, low, close], time_period: 2)
|
|
38
|
+
# => [3.0, 3.5, 3.25]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Single-output indicators return an array. Indicators with several outputs return a hash of arrays keyed by output name. Each array starts at the first input position for which the indicator has enough history.
|
|
44
42
|
|
|
45
43
|
```ruby
|
|
46
|
-
|
|
44
|
+
TALibFFI.minmax([12, 10, 14, 11, 13], time_period: 3)
|
|
45
|
+
# => { min: [10.0, 10.0, 11.0], max: [14.0, 14.0, 14.0] }
|
|
47
46
|
```
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
$ bundle install
|
|
48
|
+
## C library compatibility
|
|
52
49
|
|
|
53
|
-
|
|
50
|
+
The loaded C library determines which methods are available and their default parameters. CI tests Ruby 3.1 through the latest stable Ruby 4.x across Linux, macOS and Windows with TA-Lib C 0.6.4 and 0.8.3.
|
|
54
51
|
|
|
55
|
-
|
|
52
|
+
| TA-Lib C | Indicators | Default BBANDS period | ALMA available |
|
|
53
|
+
| --- | ---: | ---: | --- |
|
|
54
|
+
| 0.6.4 | 161 | 5 | No |
|
|
55
|
+
| 0.7.1 | 161 | 5 | No |
|
|
56
|
+
| 0.8.1 | 201 | 20 | No |
|
|
57
|
+
| 0.8.3 | 237 | 20 | Yes |
|
|
56
58
|
|
|
57
|
-
|
|
59
|
+
Pass `time_period:` explicitly to use the same BBANDS window across versions. Use `respond_to?` when calling an indicator that some installations may lack, such as the Arnaud Legoux Moving Average (ALMA), or inspect `TALibFFI.group_table` and `TALibFFI.function_table(group)` to list loaded indicators.
|
|
58
60
|
|
|
59
61
|
```ruby
|
|
60
|
-
|
|
62
|
+
if TALibFFI.respond_to?(:alma)
|
|
63
|
+
prices = (1..8).map(&:to_f)
|
|
64
|
+
TALibFFI.alma(prices, time_period: 4, sigma: 4.0, offset: 0.75).map { |value| value.round(4) }
|
|
65
|
+
# => [2.8847, 3.8847, 4.8847, 5.8847, 6.8847]
|
|
66
|
+
end
|
|
67
|
+
```
|
|
61
68
|
|
|
62
|
-
|
|
63
|
-
prices = [10.0, 11.0, 12.0, 11.0, 10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0]
|
|
69
|
+
When upgrading to gem 0.4.0, check your keyword arguments. A misspelling such as `timeperiod:` now raises `TALibFFI::TALibError` and the error lists the accepted keywords. [Changelog](CHANGELOG.md)
|
|
64
70
|
|
|
65
|
-
|
|
66
|
-
puts TALibFFI.sma(prices, time_period: 3)
|
|
67
|
-
# => [11.0, 11.333333333333334, 11.0, 10.0, 9.0, 8.0, 7.0, 6.0, 5.0]
|
|
68
|
-
```
|
|
71
|
+
## API documentation
|
|
69
72
|
|
|
70
|
-
|
|
71
|
-
- [ ] Add RDoc documentation for Ruby methods
|
|
72
|
-
- [ ] Create detailed function examples with input/output samples
|
|
73
|
-
- [ ] Add more tests for each function
|
|
74
|
-
- [ ] Support custom TA-Lib installation location
|
|
73
|
+
The gem ships method signatures generated with TA-Lib C 0.8.3. [Online API reference](https://www.rubydoc.info/github/TA-Lib/ta-lib-ruby/main/TALibFFI)
|
|
75
74
|
|
|
76
|
-
|
|
75
|
+
To build the reference for your installed C library, run `bundle install` and `bundle exec rake yard` from a checkout, then open `doc/TALibFFI.html`. The task also updates the generated method comments in `lib/ta_lib_ffi.rb`. Use TA-Lib C 0.8.3 when refreshing the signatures for this release.
|
|
77
76
|
|
|
78
|
-
|
|
79
|
-
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
80
|
-
3. Commit your changes (`git commit -am 'Add some amazing feature'`)
|
|
81
|
-
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
82
|
-
5. Create a Pull Request
|
|
77
|
+
## Development
|
|
83
78
|
|
|
84
|
-
|
|
79
|
+
From a checkout, run `bundle install` followed by `bundle exec rake` to run RSpec and RuboCop. To run just the C comparison tests, use `bundle exec rspec spec/ta_lib_ffi_c_reference_spec.rb`. They call each indicator through Ruby and directly through the installed C library with the same inputs, then compare output values, types, lengths and keys.
|
|
85
80
|
|
|
86
|
-
Bug reports and pull requests are welcome
|
|
81
|
+
Bug reports and pull requests are welcome. [GitHub repository](https://github.com/TA-Lib/ta-lib-ruby)
|
|
87
82
|
|
|
88
83
|
## License
|
|
89
84
|
|
|
90
|
-
|
|
85
|
+
[MIT License](LICENSE.txt)
|
data/Rakefile
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require "bundler/gem_tasks"
|
|
4
4
|
require "rspec/core/rake_task"
|
|
5
|
+
require "yard"
|
|
5
6
|
|
|
6
7
|
RSpec::Core::RakeTask.new(:spec)
|
|
7
8
|
|
|
@@ -10,3 +11,15 @@ require "rubocop/rake_task"
|
|
|
10
11
|
RuboCop::RakeTask.new
|
|
11
12
|
|
|
12
13
|
task default: %i[spec rubocop]
|
|
14
|
+
|
|
15
|
+
YARD::Rake::YardocTask.new do |t|
|
|
16
|
+
t.before = lambda do
|
|
17
|
+
require_relative "lib/ta_lib_ffi"
|
|
18
|
+
require_relative "lib/ta_lib_ffi/doc"
|
|
19
|
+
TALibFFI::Doc.insert
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
t.files = ["lib/**/*.rb"]
|
|
23
|
+
t.options = ["--exclude", "lib/ta_lib_ffi/doc.rb"]
|
|
24
|
+
t.stats_options = ["--list-undoc"]
|
|
25
|
+
end
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module TALibFFI
|
|
4
|
+
# Generates documentation for a TA-Lib function
|
|
5
|
+
#
|
|
6
|
+
# This module provides methods to generate documentation for TA-Lib functions.
|
|
7
|
+
# It includes methods to collect input, optional input, and output information,
|
|
8
|
+
# and to generate documentation for each function.
|
|
9
|
+
module Doc
|
|
10
|
+
module_function
|
|
11
|
+
|
|
12
|
+
def insert
|
|
13
|
+
puts "Inserting documentation"
|
|
14
|
+
file_path = File.expand_path("../ta_lib_ffi.rb", __dir__)
|
|
15
|
+
content = File.read(file_path)
|
|
16
|
+
|
|
17
|
+
new_content = content.sub(
|
|
18
|
+
/### GENERATED DOCUMENTATION START ###.*### GENERATED DOCUMENTATION END ###/m,
|
|
19
|
+
"### GENERATED DOCUMENTATION START ###\n#{generate}\n ### GENERATED DOCUMENTATION END ###"
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
File.write(file_path, new_content)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def remove
|
|
26
|
+
puts "Removing documentation"
|
|
27
|
+
file_path = File.expand_path("../ta_lib_ffi.rb", __dir__)
|
|
28
|
+
content = File.read(file_path)
|
|
29
|
+
|
|
30
|
+
new_content = content.sub(
|
|
31
|
+
/### GENERATED DOCUMENTATION START ###.*### GENERATED DOCUMENTATION END ###/m,
|
|
32
|
+
"### GENERATED DOCUMENTATION START ###\n ### GENERATED DOCUMENTATION END ###"
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
File.write(file_path, new_content)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def generate
|
|
39
|
+
docs = []
|
|
40
|
+
TALibFFI.function_info_map.each_value do |h|
|
|
41
|
+
docs << generate_function_documentation(h[:info], h[:inputs], h[:opt_inputs], h[:outputs])
|
|
42
|
+
end
|
|
43
|
+
docs.join("\n")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def generate_function_documentation(func_info, inputs, opt_inputs, outputs)
|
|
47
|
+
[
|
|
48
|
+
generate_function_description(func_info, inputs, opt_inputs),
|
|
49
|
+
generate_input_documentation(inputs),
|
|
50
|
+
generate_optional_input_documentation(opt_inputs),
|
|
51
|
+
generate_output_documentation(outputs),
|
|
52
|
+
generate_error_documentation
|
|
53
|
+
].flatten.compact.join("\n")
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def generate_function_description(func_info, inputs, opt_inputs) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
|
|
57
|
+
args = []
|
|
58
|
+
inputs.map do |input|
|
|
59
|
+
args << TALibFFI.normalize_parameter_name(input["paramName"].to_s)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
opt_inputs.map do |opt_input|
|
|
63
|
+
param_name = TALibFFI.normalize_parameter_name(opt_input["paramName"].to_s)
|
|
64
|
+
args << "#{param_name}: #{opt_input["defaultValue"]}"
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
[
|
|
68
|
+
" # @!method #{func_info["name"].to_s.downcase}(#{args.join(", ")})",
|
|
69
|
+
" # #{func_info["hint"].to_s.strip}",
|
|
70
|
+
" #"
|
|
71
|
+
]
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def generate_input_documentation(inputs) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
|
|
75
|
+
inputs.map do |input| # rubocop:disable Metrics/BlockLength
|
|
76
|
+
param_name = TALibFFI.normalize_parameter_name(input["paramName"].to_s)
|
|
77
|
+
flags = TALibFFI.extract_flags(input["flags"], :TA_InputFlags)
|
|
78
|
+
|
|
79
|
+
type = case input["type"]
|
|
80
|
+
when TALibFFI::TA_PARAM_TYPE[:TA_Input_Price]
|
|
81
|
+
array_types = Array.new(flags.length, "Array<Float>")
|
|
82
|
+
"Array(#{array_types.join(", ")})"
|
|
83
|
+
when TALibFFI::TA_PARAM_TYPE[:TA_Input_Real]
|
|
84
|
+
"Array<Float>"
|
|
85
|
+
when TALibFFI::TA_PARAM_TYPE[:TA_Input_Integer]
|
|
86
|
+
"Array<Integer>"
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
description = if input["type"] == TALibFFI::TA_PARAM_TYPE[:TA_Input_Price]
|
|
90
|
+
arrays = flags.map do |flag|
|
|
91
|
+
{
|
|
92
|
+
TA_IN_PRICE_OPEN: "open",
|
|
93
|
+
TA_IN_PRICE_HIGH: "high",
|
|
94
|
+
TA_IN_PRICE_LOW: "low",
|
|
95
|
+
TA_IN_PRICE_CLOSE: "close",
|
|
96
|
+
TA_IN_PRICE_VOLUME: "volume",
|
|
97
|
+
TA_IN_PRICE_OPENINTEREST: "open interest",
|
|
98
|
+
TA_IN_PRICE_TIMESTAMP: "timestamp"
|
|
99
|
+
}[flag]
|
|
100
|
+
end
|
|
101
|
+
"Required price arrays: #{arrays.join(", ")}"
|
|
102
|
+
else
|
|
103
|
+
"Input values"
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
" # @param #{param_name} [#{type}] #{description}"
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def generate_optional_input_documentation(opt_inputs)
|
|
111
|
+
opt_inputs.map do |opt_input|
|
|
112
|
+
param_name = TALibFFI.normalize_parameter_name(opt_input["paramName"].to_s)
|
|
113
|
+
type = opt_input["type"] == TALibFFI::TA_PARAM_TYPE[:TA_OptInput_RealRange] ? "Float" : "Integer"
|
|
114
|
+
" # @param #{param_name} [#{type}] #{opt_input["hint"]} (default: #{opt_input["defaultValue"]})"
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def generate_output_documentation(outputs) # rubocop:disable Metrics/MethodLength
|
|
119
|
+
if outputs.length == 1
|
|
120
|
+
type = outputs.first["type"] == TALibFFI::TA_PARAM_TYPE[:TA_Output_Real] ? "Float" : "Integer"
|
|
121
|
+
[" # @return [Array<#{type}>]"]
|
|
122
|
+
else
|
|
123
|
+
[
|
|
124
|
+
" # @return [Hash] Hash containing the following arrays:",
|
|
125
|
+
*outputs.map do |output|
|
|
126
|
+
param_name = TALibFFI.normalize_parameter_name(output["paramName"].to_s)
|
|
127
|
+
type = output["type"] == TALibFFI::TA_PARAM_TYPE[:TA_Output_Real] ? "Float" : "Integer"
|
|
128
|
+
" # @option result [Array<#{type}>] :#{param_name} Output values"
|
|
129
|
+
end
|
|
130
|
+
]
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def generate_error_documentation
|
|
135
|
+
" # @raise [TALibError] If there is an error in function execution\n"
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|