cotcube-indicators 0.1.9 → 0.1.10

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: bf34a07745a24a8973103aad577a9a50ff0c51d8024110b1919a1cc8761a2ab2
4
- data.tar.gz: 28e0479f8ee5d3b307b1734b7b1dc2daab0e63fcfaf83b683c2db860b8749bde
3
+ metadata.gz: 63178d5a731cb55b8b5d9c6f63ac5aa9931d909fc30490bceea514d2dff1beb9
4
+ data.tar.gz: 0e0beac7a246973767faabafefd412cb76a08ecdbadb4ce0e390c96027c5ae51
5
5
  SHA512:
6
- metadata.gz: 6e8ac4bfd2c0c3b1c4a148ce8af941b3641ce3d607ceec42f717dcbad154808436fe6f455f52cd54c0d3dc65f1d847522b216969ded24d9edfb990d6ec76001b
7
- data.tar.gz: 75313bd5ad890dc65b6733b4a71e391a1f6ad1e29fd4021fed5f5d990a60c3c47a798a853025d389d692a8ebc69b916f9184a314eca15c7d4235757a54eb451d
6
+ metadata.gz: fcb3bc43b9cb2548e4901d24ad2d422ed37319510add433ba43adbb97308ab39b00ce6ee371acfbcd0372161b212a9117b4b4620cee5bba8a15265592d57214d
7
+ data.tar.gz: 2ebd19d2f1fe549198ecdb9b2ae6e70e27f6d76f80f4b83d57f1c8dafc16387b40e36859b60a0b332afaefb92334ce6d06c7294bf31b85472569dd18347d92a7
data/.gitignore CHANGED
@@ -11,5 +11,6 @@ public/full.raw
11
11
  public/full.raw.html
12
12
  compass/.sass-cache/
13
13
  stash/
14
+ *.gem
14
15
  .rspec_status
15
16
  .yardoc
@@ -1,3 +1,7 @@
1
+ ## 0.1.10 (December 03, 2020)
2
+ - added indicator 'threshold' including spec
3
+ - some minor improvements to .gitignore and .gemspec
4
+
1
5
  ## 0.1.9 (December 02, 2020)
2
6
  - worked through rubocops
3
7
  - wrote according README.md
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.9
1
+ 0.1.10
@@ -9,15 +9,13 @@ Gem::Specification.new do |spec|
9
9
  spec.summary = 'Lambda based indicators, decoupled from legacy cotcube'
10
10
  spec.description = 'Lambda based indicators, decoupled from legacy cotcube'
11
11
 
12
- spec.homepage = 'https://github.com/donkeybridge/cotcube-indicators'
12
+ spec.homepage = 'https://github.com/donkeybridge/'+ spec.name
13
13
  spec.license = 'BSD-4-Clause'
14
14
  spec.required_ruby_version = Gem::Requirement.new('~> 2.7')
15
15
 
16
- # spec.metadata['allowed_push_host'] = 'http://100.100.0.14:5001'
17
-
18
16
  spec.metadata['homepage_uri'] = spec.homepage
19
- spec.metadata['source_code_uri'] = 'https://github.com/donkeybridge/cotcube-indicators'
20
- spec.metadata['changelog_uri'] = 'https://github.com/donkeybridege/cotcube-indicators/CHANGELOG.md'
17
+ spec.metadata['source_code_uri'] = spec.homepage
18
+ spec.metadata['changelog_uri'] = spec.homepage + '/CHANGELOG.md'
21
19
 
22
20
  # Specify which files should be added to the gem when it is released.
23
21
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -10,9 +10,10 @@ require_relative 'cotcube-indicators/ema'
10
10
  require_relative 'cotcube-indicators/sma'
11
11
  require_relative 'cotcube-indicators/rsi'
12
12
  require_relative 'cotcube-indicators/true_range'
13
+ require_relative 'cotcube-indicators/threshold'
13
14
 
14
15
  module Cotcube
15
16
  module Indicators
16
- module_function :calc, :change, :ema, :sma, :rsi, :true_range, :index, :score
17
+ module_function :calc, :change, :ema, :sma, :rsi, :true_range, :index, :score, :threshold
17
18
  end
18
19
  end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cotcube
4
+ module Indicators
5
+ # threshold returns
6
+ def threshold(key:, upper: nil, lower: nil, repeat: false, abs: false, debug: false)
7
+ raise ArgumentError, "Need to set :upper: (set to Float::INFINITY to omit)" if upper.nil?
8
+ raise ArgumentError, "Need to set :lower unless :abs is set" if lower.nil? and not abs
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
11
+ # For this indicator, we just need to remembers -1, 0 or 1. That does not need a helper class.
12
+ carrier = 0
13
+
14
+ lambda do |current|
15
+ current = current[key.to_sym]
16
+ current = current.abs if abs
17
+ puts "UPPER: #{upper}\tLOWER: #{lower}\tCARRIER was: #{carrier}\tCURRENT: #{current}" if debug
18
+ # facing options
19
+ # 1. carrier is zero
20
+ if carrier.zero?
21
+ # 1.a. and threshold
22
+ if current >= upper
23
+ carrier = 1
24
+ return 1
25
+ elsif not abs and current <= lower
26
+ carrier = -1
27
+ return -1
28
+ # 1.b. and no threshold
29
+ else
30
+ return 0
31
+ end
32
+ # 2. carrier is non-zero
33
+ else
34
+ # and threshold
35
+ # if threshold matches carrier, return 0 and keep carrier or return carrier if :repeat
36
+ # if not abs, allow reversing on appropriate threshold
37
+ if carrier.positive? and current >= upper
38
+ return repeat ? 1 : 0
39
+ elsif not abs and carrier.negative? and current <= lower
40
+ return repeat ? -1 : 0
41
+ elsif not abs and carrier.positive? and current <= lower
42
+ carrier = -1
43
+ return -1
44
+ elsif not abs and carrier.negative? and current >= upper
45
+ carrier = 1
46
+ return 1
47
+ # and no threshold
48
+ # silently unset carrier, return 0
49
+ else
50
+ carrier = 0
51
+ return 0
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
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.9
4
+ version: 0.1.10
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-02 00:00:00.000000000 Z
11
+ date: 2020-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -75,6 +75,7 @@ files:
75
75
  - lib/cotcube-indicators/rsi.rb
76
76
  - lib/cotcube-indicators/score.rb
77
77
  - lib/cotcube-indicators/sma.rb
78
+ - lib/cotcube-indicators/threshold.rb
78
79
  - lib/cotcube-indicators/true_range.rb
79
80
  homepage: https://github.com/donkeybridge/cotcube-indicators
80
81
  licenses:
@@ -82,7 +83,7 @@ licenses:
82
83
  metadata:
83
84
  homepage_uri: https://github.com/donkeybridge/cotcube-indicators
84
85
  source_code_uri: https://github.com/donkeybridge/cotcube-indicators
85
- changelog_uri: https://github.com/donkeybridege/cotcube-indicators/CHANGELOG.md
86
+ changelog_uri: https://github.com/donkeybridge/cotcube-indicators/CHANGELOG.md
86
87
  post_install_message:
87
88
  rdoc_options: []
88
89
  require_paths: