cotcube-bardata 0.1.15.5 → 0.1.15.6

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: e1ab9094e7e7e6c04a90f1f1a640b902de5a0c688403a5d79c53a7b3f11c9434
4
- data.tar.gz: 16175de316f036ec9a930b43d700fc241999afaffca728bf2ba436470255c957
3
+ metadata.gz: 5798e21ced6b815404638c1f33948317338d801ea483e9e43edf21b8ad3f73ba
4
+ data.tar.gz: 8bfaf9b663d8de85f8c89b459b3f33e35ce836cad2d0153a02385aaafc4d6781
5
5
  SHA512:
6
- metadata.gz: f549b77c54222c0424d0f96c20a43634ab18af6001efffbc27ef3a4d21ee56e4fe67e727399dbbce47335b82d7e3733350b7b5469a22acee970c682eefef1d0c
7
- data.tar.gz: 5153e8ad6cfae659c0f538e42cf635b53a3e543bb41a0decc8daf9169f62bce92dd0f7cd8b2d7a71a983a953b5be57b1e2fff7e6679f14662d6369524b486ca0
6
+ metadata.gz: f554feb61ac91f542a9e9a24a4f9983cbfd529ace02290b531d07bb67cbe5864da1e154e023b9d00dec77b91b2243efb726d4bd005fee6cdc1af88701de583a8
7
+ data.tar.gz: 32a0446523adb94cc50426c0e03b3bd379746754d5314fe79af8ff02fe169fae95fc3a1ba894a313e5b8b7ac89a2da36d5605e0183b9e0ef8022550e00fc5449
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.1.15.6 (November 19, 2021)
2
+ - daily: added filter_series
3
+
1
4
  ## 0.1.15.5 (November 08, 2021)
2
5
  - decommissioned .get_id_set in favor of Cotcube::Helpers.get_id_set
3
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.15.5
1
+ 0.1.15.6
@@ -198,6 +198,55 @@ module Cotcube
198
198
  date.nil? ? Cotcube::Bardata.const_get(constname).map{|z| z.dup } : Cotcube::Bardata.const_get(constname).find { |x| x[:date] == date }
199
199
  end
200
200
 
201
+ # the filter series is an indicator based on the Cotcube::Bardata.continuous of the asset price.
202
+ # current default filter is the ema50
203
+ def filter_series(ema_length: 50, symbol: , print_range: nil)
204
+ ema_high_n = "ema#{ema_length}_high".to_sym
205
+ ema_low_n = "ema#{ema_length}_low".to_sym
206
+ ema_filter = "ema#{ema_length}_filter".to_sym
207
+ indicators = {
208
+ ema_high_n => Cotcube::Indicators.ema(key: :high, length: ema_length, smoothing: 2),
209
+ ema_low_n => Cotcube::Indicators.ema(key: :low, length: ema_length, smoothing: 2),
210
+ :tr => Cotcube::Indicators.true_range,
211
+ :atr5 => Cotcube::Indicators.ema(key: :tr, length: 5, smoothing: 2),
212
+ ema_filter => Cotcube::Indicators.calc(a: :high, b: :low, c: :close,
213
+ d: ema_high_n, e: ema_low_n, f: :atr5,
214
+ finalize: :to_i) do |high, low, close, ema_high, ema_low, atr5|
215
+
216
+ if close > ema_high and (low - ema_high).abs <= atr5 / 5.0; 3 # :bullish_tipped
217
+ elsif low > ema_high and (low - ema_high).abs >= atr5 * 3.0; 5 # :bullish_away
218
+ elsif low > ema_high and (low - ema_high).abs <= atr5 / 1.5; 2 # :bullish_nearby
219
+ elsif low > ema_high; 4 # :bullish
220
+
221
+ elsif close < ema_low and (high - ema_low).abs <= atr5 / 5.0; -3 # :bearish_tipped
222
+ elsif high < ema_low and (high - ema_low).abs >= atr5 * 3.0; -5 # :bearish_away
223
+ elsif high < ema_low and (high - ema_low).abs <= atr5 / 1.5; -2 # :bearish_nearby
224
+ elsif high < ema_low; -4 # :bearish
225
+
226
+ elsif close >= ema_high and (close - ema_high).abs > atr5 ; 2 # :bullish_closed
227
+ elsif close <= ema_low and (close - ema_low ).abs > atr5 ; -2 # :bearish_closed
228
+ elsif close >= ema_high; 1 # :bullish_weak
229
+ elsif close <= ema_low; -1 # :bearish_weak
230
+ elsif close > ema_low and close < ema_high; 0 # :ambigue
231
+ else
232
+ raise RuntimeError, "Unconsidered Indicator value with #{high}, #{low}, #{close}, #{ema_high}, #{ema_low}, #{atr5}"
233
+
234
+ end
235
+ end
236
+ }
237
+ filter = Cotcube::Bardata.continuous(symbol: symbol, indicators: indicators).
238
+ map{ |z| z[:datetime] = DateTime.parse(z[:date]); z[:datetime] += z[:datetime].wday == 5 ? 3 : 1; z.slice(:datetime, ema_filter) }.
239
+ group_by{ |z| z[:datetime] }.
240
+ map{ |k,v| [ k, v[0][ema_filter] ] }.
241
+ to_h.
242
+ tap{ |z| z.to_a[print_range].each { |v|
243
+ puts "#{v[0].strftime('%Y-%m-%d')
244
+ } : #{format '%2d', v[1]
245
+ }".colorize(v[1] > 3 ? :light_green : v[1] > 1 ? :green : v[1] < -3 ? :light_red : v[1] < -1 ? :red : :white )
246
+ } if print_range.is_a? Range
247
+ }
248
+ end
249
+
201
250
  def continuous_ml(symbol: nil, id: nil, base: nil)
202
251
  (base.nil? ? Cotcube::Bardata.continuous(symbol: symbol, id: id) : base).map do |x|
203
252
  x[:ml] = x[:contracts].max_by { |z| z[:volume] }[:contract]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cotcube-bardata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15.5
4
+ version: 0.1.15.6
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: 2021-11-18 00:00:00.000000000 Z
11
+ date: 2021-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport