cotcube-indicators 0.1.11 → 0.1.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/VERSION +1 -1
- data/lib/cotcube-indicators/calc.rb +10 -2
- data/lib/cotcube-indicators/ema.rb +6 -4
- data/lib/cotcube-indicators/index.rb +1 -1
- data/lib/cotcube-indicators/rsi.rb +0 -2
- data/lib/cotcube-indicators/score.rb +1 -1
- data/lib/cotcube-indicators/sma.rb +1 -2
- data/lib/cotcube-indicators/threshold.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e549845d62cd14b399913c4881c8491f1392d9b94df1b3fec8405fd95059bf84
|
4
|
+
data.tar.gz: ed52269218da6e88138221e116b8c35e68abc385346cd8376efb230933c71dce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9f7f917c7c6e490d9263456f2d2e2887f672a9b85609546bcd17d695840275a0f4de7f2a34e1632ae9d6be359388f843397bb458e707ec9b0c0af097a657efa
|
7
|
+
data.tar.gz: c9650895d30c9e1457b37b56242916a81a2eb70257fbcc16bf45144ec9f55030b10ec82f0f52cf13307c67a12b9b474b93fed262d82961d7fb984ca572b9a035
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## 0.1.15 (November 15, 2021)
|
2
|
+
- fixing ema and sma by applying to_f to divisors
|
3
|
+
|
4
|
+
## 0.1.14 (July 31, 2021)
|
5
|
+
- calc: adding support for more param variables (a .. e)
|
6
|
+
|
7
|
+
## 0.1.13 (December 30, 2020)
|
8
|
+
- small fix to #score and #index to support missing values in series
|
9
|
+
|
10
|
+
## 0.1.12 (December 05, 2020)
|
11
|
+
- added tests for SMA, EMA, RSI
|
12
|
+
|
1
13
|
## 0.1.11 (December 05, 2020)
|
2
14
|
- Fixing 'smoothing' keyword argument in EMA
|
3
15
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.15
|
@@ -2,9 +2,17 @@
|
|
2
2
|
|
3
3
|
module Cotcube
|
4
4
|
module Indicators
|
5
|
-
def calc(a:, b:, &block) # rubocop:disable Naming/MethodParameterName
|
5
|
+
def calc(a:, b:, c:nil, d:nil, e:nil, f:nil, g:nil, h:nil, finalize: :to_f, &block) # rubocop:disable Naming/MethodParameterName
|
6
6
|
lambda do |x|
|
7
|
-
block.call(
|
7
|
+
block.call(
|
8
|
+
x[a.to_sym],
|
9
|
+
(b.nil? ? nil : x[b.to_sym]),
|
10
|
+
(c.nil? ? nil : x[c.to_sym]),
|
11
|
+
(d.nil? ? nil : x[d.to_sym]),
|
12
|
+
(e.nil? ? nil : x[e.to_sym]),
|
13
|
+
(f.nil? ? nil : x[f.to_sym]),
|
14
|
+
(g.nil? ? nil : x[g.to_sym]),
|
15
|
+
).send(finalize.to_sym)
|
8
16
|
end
|
9
17
|
end
|
10
18
|
end
|
@@ -4,16 +4,18 @@ module Cotcube
|
|
4
4
|
module Indicators
|
5
5
|
# the classic exponential moving average
|
6
6
|
def ema(key:, length:, smoothing: nil)
|
7
|
-
raise '
|
7
|
+
raise ArgumentError, 'Improper :length parameter, should be positive Integer' unless length.is_a? Integer and length.positive?
|
8
8
|
|
9
9
|
smoothing ||= (2 / (length - 1).to_f.round(2))
|
10
|
-
|
10
|
+
raise ArgumentError, 'Improper smoothing, should be Numeric' unless smoothing.is_a? Numeric
|
11
|
+
|
12
|
+
carrier = Cotcube::Indicators::Carrier.new(length: length)
|
11
13
|
lambda do |x|
|
12
14
|
current = x[key.to_sym]
|
13
15
|
carrier << if carrier.empty?
|
14
|
-
current * (smoothing / (1 + length))
|
16
|
+
current * (smoothing / (1.0 + length))
|
15
17
|
else
|
16
|
-
current * (smoothing / (1 + length)) + carrier.get[-1] * (1 - (smoothing / (1 + length)))
|
18
|
+
current * (smoothing / (1.0 + length)) + carrier.get[-1] * (1.0 - (smoothing / (1.0 + length)))
|
17
19
|
end
|
18
20
|
carrier.size < length ? -1.0 : carrier.get.last
|
19
21
|
end
|
@@ -3,13 +3,12 @@
|
|
3
3
|
module Cotcube
|
4
4
|
module Indicators
|
5
5
|
def sma(length:, key:)
|
6
|
-
raise 'Missing parameter, need :length and :value options' if opts[:length].nil? || opts[:value].nil?
|
7
6
|
|
8
7
|
carrier = Cotcube::Indicators::Carrier.new(length: length)
|
9
8
|
lambda do |x|
|
10
9
|
current = x[key.to_sym]
|
11
10
|
carrier << current
|
12
|
-
carrier.size < length ? 0.0 : (carrier.get.reduce(:+) / carrier.length).to_f
|
11
|
+
carrier.size < length ? 0.0 : (carrier.get.reduce(:+) / carrier.length.to_f).to_f
|
13
12
|
end
|
14
13
|
end
|
15
14
|
end
|
@@ -7,7 +7,7 @@ module Cotcube
|
|
7
7
|
raise ArgumentError, "Need to set :upper: (set to Float::INFINITY to omit)" if upper.nil?
|
8
8
|
raise ArgumentError, "Need to set :lower unless :abs is set" if lower.nil? and not abs
|
9
9
|
raise ArgumentError, ":lower, upper must be numeric" if not upper.is_a?(Numeric) and ( abs ? true : lower.is_a?(Numeric) )
|
10
|
-
raise ArgumentError, "Found bogus, :lower #{lower} must be lower than :upper #{upper}" if not abs and lower
|
10
|
+
raise ArgumentError, "Found bogus, :lower #{lower} must be lower than :upper #{upper}" if not abs and lower > upper
|
11
11
|
# For this indicator, we just need to remembers -1, 0 or 1. That does not need a helper class.
|
12
12
|
carrier = 0
|
13
13
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cotcube-indicators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin L. Tischendorf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '0'
|
101
101
|
requirements: []
|
102
|
-
rubygems_version: 3.1.
|
102
|
+
rubygems_version: 3.1.6
|
103
103
|
signing_key:
|
104
104
|
specification_version: 4
|
105
105
|
summary: Lambda based indicators, decoupled from legacy cotcube
|