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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11f1af1cbae6dfbd31c7ab543801a6b71d6add09dd157f823a380d16d0cc3354
4
- data.tar.gz: f5012e6bffd26cb739260d17efad7a7deff8725d3c02e9ec6994798f0462ebb0
3
+ metadata.gz: e549845d62cd14b399913c4881c8491f1392d9b94df1b3fec8405fd95059bf84
4
+ data.tar.gz: ed52269218da6e88138221e116b8c35e68abc385346cd8376efb230933c71dce
5
5
  SHA512:
6
- metadata.gz: 826229e58f828396cb60fe6af1f86a92b4894f1f34e1d61eef3b65cada0e743679465e1a183a2723f82e480d18e3964608ac8299c9ed492a8f0fe8123df68b81
7
- data.tar.gz: 50e7d157baa972a579cd78ec662544f70ef9af48297fe22f9c45d2fbe338cb512cea6beb363d9020cb518994bd7bfb520968470d5aa4ed2b7224c5aa19f66840
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.11
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(x[a.to_sym], x[b.to_sym]).to_f
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 'Missing parameter, need :length' unless length.is_a? Integer
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
- carrier = Carrier.new(length)
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
@@ -24,7 +24,7 @@ module Cotcube
24
24
  puts "RESULT: #{res}" if debug
25
25
  return reverse ? (1 - res.to_f).round(3).to_f : res.round(3).to_f
26
26
  else
27
- carrier.shift
27
+ carrier << 0
28
28
  return 0
29
29
  end
30
30
  end
@@ -3,8 +3,6 @@
3
3
  module Cotcube
4
4
  module Indicators
5
5
  def rsi(length:, key:, debug: false)
6
- raise 'Missing parameter, need :key and :length options' if length.nil? || key.nil?
7
-
8
6
  carrier = Carrier.new(length: length)
9
7
 
10
8
  lambda do |x|
@@ -11,7 +11,7 @@ module Cotcube
11
11
  current = x[key.to_sym]
12
12
  current = current.abs if abs
13
13
  if current.zero?
14
- carrier.shift
14
+ carrier << 0
15
15
  return 0
16
16
 
17
17
  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 >= upper
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.11
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: 2020-12-05 00:00:00.000000000 Z
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.2
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