cotcube-indicators 0.1.9 → 0.1.10
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/.gitignore +1 -0
- data/CHANGELOG.md +4 -0
- data/VERSION +1 -1
- data/cotcube-indicators.gemspec +3 -5
- data/lib/cotcube-indicators.rb +2 -1
- data/lib/cotcube-indicators/threshold.rb +57 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63178d5a731cb55b8b5d9c6f63ac5aa9931d909fc30490bceea514d2dff1beb9
|
4
|
+
data.tar.gz: 0e0beac7a246973767faabafefd412cb76a08ecdbadb4ce0e390c96027c5ae51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcb3bc43b9cb2548e4901d24ad2d422ed37319510add433ba43adbb97308ab39b00ce6ee371acfbcd0372161b212a9117b4b4620cee5bba8a15265592d57214d
|
7
|
+
data.tar.gz: 2ebd19d2f1fe549198ecdb9b2ae6e70e27f6d76f80f4b83d57f1c8dafc16387b40e36859b60a0b332afaefb92334ce6d06c7294bf31b85472569dd18347d92a7
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.10
|
data/cotcube-indicators.gemspec
CHANGED
@@ -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/
|
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'] =
|
20
|
-
spec.metadata['changelog_uri'] = '
|
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.
|
data/lib/cotcube-indicators.rb
CHANGED
@@ -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.
|
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-
|
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/
|
86
|
+
changelog_uri: https://github.com/donkeybridge/cotcube-indicators/CHANGELOG.md
|
86
87
|
post_install_message:
|
87
88
|
rdoc_options: []
|
88
89
|
require_paths:
|