cotcube-bardata 0.1.15.6 → 0.1.16

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5798e21ced6b815404638c1f33948317338d801ea483e9e43edf21b8ad3f73ba
4
- data.tar.gz: 8bfaf9b663d8de85f8c89b459b3f33e35ce836cad2d0153a02385aaafc4d6781
3
+ metadata.gz: aa52a5fd519f8351f712e30495d4dda59bb37a4d4b588c84904d1971d7ad734c
4
+ data.tar.gz: b1eaacc5e75d13d84edf8c095cdaebc7ec588fe0e61ef6dc764d2a5633fedece
5
5
  SHA512:
6
- metadata.gz: f554feb61ac91f542a9e9a24a4f9983cbfd529ace02290b531d07bb67cbe5864da1e154e023b9d00dec77b91b2243efb726d4bd005fee6cdc1af88701de583a8
7
- data.tar.gz: 32a0446523adb94cc50426c0e03b3bd379746754d5314fe79af8ff02fe169fae95fc3a1ba894a313e5b8b7ac89a2da36d5605e0183b9e0ef8022550e00fc5449
6
+ metadata.gz: 1798e058b377f50f2efe78f8f6b0936763ce29686a639f10e893914202ca27f4469665d9520d7adcda4df5f4346e5f9f87e8ce229c389ac78dde666335f1efd3
7
+ data.tar.gz: 8e245ebcea3acdde99f7c5673f97024432648938e530fd9ae11dae4b7f67091a5128536fa70c0e4ba0cb372d85f7c713460249da574278501e60f4bf66ebf1ac
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.1.16 (November 23, 2021)
2
+ - bin/eod.rb: little helper to display eod data in bash resp. in xinetdhttpservice
3
+ - eods.rb: minor change to adapt move of symbols to Helpers
4
+ - daily.rb: in continuous, changed default indicators to %i[ tr atr5 dist ]
5
+
1
6
  ## 0.1.15.6 (November 19, 2021)
2
7
  - daily: added filter_series
3
8
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.15.6
1
+ 0.1.16
data/bin/eod.rb ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/cotcube-bardata.rb'
4
+
5
+ symbol = ARGV[0].nil? ? nil : ARGV[0].upcase
6
+
7
+ s = Cotcube::Bardata.provide_eods(threshold: 0.10, contracts_only: false, symbol: symbol, filter: :oi_part)
8
+ s.each {|x| puts x.values.to_csv}
@@ -146,17 +146,13 @@ module Cotcube
146
146
 
147
147
  measuring.call("Finished retrieving dailies.")
148
148
  result = []
149
- rounding = 8 # sym[:format].split('.').last.to_i rescue 6
149
+ rounding = 8
150
150
  indicators ||= {
151
- typical: Cotcube::Indicators.calc(a: :high, b: :low, c: :close) {|high, low, close| (high + low + close) / 3 },
152
- sma250_high: Cotcube::Indicators.sma(key: :high, length: 250),
153
- sma250_low: Cotcube::Indicators.sma(key: :low, length: 250),
154
- sma250_typ: Cotcube::Indicators.sma(key: :typical, length: 250),
155
- dist: Cotcube::Indicators.calc(a: :high, b: :low, finalize: :to_i) {|high, low| ((high-low) / ticksize) },
151
+ tr: Cotcube::Indicators.true_range,
152
+ atr5: Cotcube::Indicators.ema(key: :tr, length: 5),
153
+ dist: Cotcube::Indicators.calc(a: :high, b: :low, finalize: :to_i) {|high, low| ((high-low) / ticksize) }
156
154
  }
157
155
 
158
-
159
-
160
156
  data.group_by { |x| x[:date] }.map do |k, v|
161
157
  v.map { |x| x.delete(:date) }
162
158
  avg_bar = {
@@ -180,9 +176,9 @@ module Cotcube
180
176
  avg_bar[k] = tmp.respond_to?(:round) ? tmp.round(rounding) : tmp
181
177
  puts avg_bar[k] if debug
182
178
  end
183
- %i[tr atr5].each { |ind|
184
- avg_bar[ind] = (avg_bar[ind] / sym[:ticksize]).round.to_i unless avg_bar[ind].nil?
185
- }
179
+ #%i[tr atr5].each { |ind|
180
+ # avg_bar[ind] = (avg_bar[ind] / sym[:ticksize]).round.to_i unless avg_bar[ind].nil?
181
+ #}
186
182
  result << avg_bar
187
183
  result.last[:contracts] = v
188
184
  end
@@ -207,44 +203,46 @@ module Cotcube
207
203
  indicators = {
208
204
  ema_high_n => Cotcube::Indicators.ema(key: :high, length: ema_length, smoothing: 2),
209
205
  ema_low_n => Cotcube::Indicators.ema(key: :low, length: ema_length, smoothing: 2),
206
+ # NOTE: TR / ATR5 are in default set of continuous
210
207
  :tr => Cotcube::Indicators.true_range,
211
208
  :atr5 => Cotcube::Indicators.ema(key: :tr, length: 5, smoothing: 2),
212
209
  ema_filter => Cotcube::Indicators.calc(a: :high, b: :low, c: :close,
213
210
  d: ema_high_n, e: ema_low_n, f: :atr5,
214
211
  finalize: :to_i) do |high, low, close, ema_high, ema_low, atr5|
215
212
 
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
213
+ if close > ema_high and (low - ema_high).abs <= atr5 / 5.0; 3 # :bullish_tipped
214
+ elsif low > ema_high and (low - ema_high).abs >= atr5 * 3.0; 5 # :bullish_away
215
+ elsif low > ema_high and (low - ema_high).abs <= atr5 / 1.5; 2 # :bullish_nearby
216
+ elsif low > ema_high; 4 # :bullish
217
+
218
+ elsif close < ema_low and (high - ema_low).abs <= atr5 / 5.0; -3 # :bearish_tipped
219
+ elsif high < ema_low and (high - ema_low).abs >= atr5 * 3.0; -5 # :bearish_away
220
+ elsif high < ema_low and (high - ema_low).abs <= atr5 / 1.5; -2 # :bearish_nearby
221
+ elsif high < ema_low; -4 # :bearish
222
+
223
+ elsif close >= ema_high and (close - ema_high).abs > atr5 ; 2 # :bullish_closed
224
+ elsif close <= ema_low and (close - ema_low ).abs > atr5 ; -2 # :bearish_closed
225
+ elsif close >= ema_high; 1 # :bullish_weak
226
+ elsif close <= ema_low; -1 # :bearish_weak
227
+ elsif close > ema_low and close < ema_high; 0 # :ambigue
228
+ else
229
+ raise RuntimeError, "Unconsidered Indicator value with #{high}, #{low}, #{close}, #{ema_high}, #{ema_low}, #{atr5}"
230
+
231
+ end
232
+ end
236
233
  }
237
234
  filter = Cotcube::Bardata.continuous(symbol: symbol, indicators: indicators).
238
235
  map{ |z| z[:datetime] = DateTime.parse(z[:date]); z[:datetime] += z[:datetime].wday == 5 ? 3 : 1; z.slice(:datetime, ema_filter) }.
239
236
  group_by{ |z| z[:datetime] }.
240
237
  map{ |k,v| [ k, v[0][ema_filter] ] }.
241
238
  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
- }
239
+ tap{ |z|
240
+ z.to_a[print_range].each { |v|
241
+ puts "#{symbol} #{v[0].strftime('%Y-%m-%d')
242
+ } #{format '%2d', v[1]
243
+ }".colorize(v[1] > 3 ? :light_green : v[1] > 1 ? :green : v[1] < -3 ? :light_red : v[1] < -1 ? :red : :white )
244
+ } if print_range.is_a? Range
245
+ }
248
246
  end
249
247
 
250
248
  def continuous_ml(symbol: nil, id: nil, base: nil)
@@ -370,12 +368,14 @@ module Cotcube
370
368
  .reject { |k, _| k[-2..].to_i >= date.year % 2000 }
371
369
  .group_by { |k, _| k[2] }
372
370
  measuring.call("Retrieved continous_overview")
373
- output_sent = []
374
- early_year=nil
375
371
  long_output = []
372
+
373
+ toydate = -> (z,y=2021) { str = "#{z>365 ? y+1 : y} #{z>365 ? z-365 : z}"; DateTime.strptime(str, '%Y %j').strftime('%Y-%m-%d') }
374
+
376
375
  data.keys.sort.each do |month|
377
376
  puts "Processing #{sym[:symbol]}#{month}" if debuglevel > 1
378
377
  v0 = data[month]
378
+
379
379
  # ldays is the list of 'last days'
380
380
  ldays = v0.map { |_, v1| Date.parse(v1.last[:date]).yday }
381
381
  # fdays is the list of 'first days'
@@ -384,6 +384,23 @@ module Cotcube
384
384
  ldays.map! { |x| x > 350 ? x - 366 : x } if ldays.min < 50
385
385
  fday = fdays[fdays.size / 2]
386
386
  lavg = ldays.reduce(:+) / ldays.size
387
+
388
+ # rubocop:disable Layout/ClosingParenthesisIndentation
389
+ current = {
390
+ month: month,
391
+ contract: "#{sym[:symbol]}#{month}",
392
+ first_ml: fday,
393
+ last_min: ldays.min,
394
+ last_avg: lavg,
395
+ last_max: ldays.max,
396
+ until_start: fday - ytoday,
397
+ until_end: ldays.min - ytoday
398
+ }
399
+ current[:until_end] += 365 if current[:until_end] - current[:until_start] < 0
400
+ current[:until_end] -= 365 if current[:until_end] > 365
401
+
402
+ long_output << current
403
+
387
404
  # a contract is proposed to use after fday - 1, but before ldays.min (green)
388
405
  # it is warned to user after fday - 1 but before lavg - 1 (red)
389
406
  # it is warned red >= lavg - 1 and <= lavg + 1
@@ -396,55 +413,42 @@ module Cotcube
396
413
  else
397
414
  :white
398
415
  end
399
- # rubocop:disable Layout/ClosingParenthesisIndentation
400
- long_output << {
401
- month: month,
402
- first_ml: fday,
403
- last_min: ldays.min,
404
- last_avg: lavg,
405
- last_max: ldays.max }
416
+
406
417
  output = "#{sym[:symbol]
407
- }#{month
408
- }\t#{format '%12s', sym[:type]
409
- }\ttoday is #{ytoday
410
- } -- median of first is #{fday
411
- }\tlast ranges from #{format '%5d', ldays.min
412
- }: #{dfm.call(ldays.min)
413
- }\t#{format '%5d', lavg
414
- }: #{dfm.call(lavg)
415
- }\tto #{format '%5d', ldays.max
416
- }: #{dfm.call(ldays.max)}".colorize(color)
417
- if debug || (color != :white)
418
- puts output unless silent
419
- end
420
- output_sent << "#{sym[:symbol]}#{month}" unless color == :white
421
- early_year ||= output
422
- next if silent or not (debug and debuglevel >= 2)
423
-
424
- v0.each do |contract, v1|
425
- puts "\t#{contract
426
- }\t#{v1.first[:date]
427
- } (#{format '%3d', Date.parse(v1.first[:date]).yday
428
- })\t#{Date.parse(v1.last[:date]).strftime('%a, %Y-%m-%d')
429
- } (#{Date.parse(v1.last[:date]).yday})" unless silent
430
- # rubocop:enable Layout/ClosingParenthesisIndentation
431
- end
418
+ }#{month
419
+ }\t#{format '%12s', sym[:type]
420
+ }\ttoday is #{ytoday
421
+ } -- median of first is #{fday
422
+ }\tlast ranges from #{format '%5d', ldays.min
423
+ }: #{dfm.call(ldays.min)
424
+ }\t#{format '%5d', lavg
425
+ }: #{dfm.call(lavg)
426
+ }\tto #{format '%5d', ldays.max
427
+ }: #{dfm.call(ldays.max)}".colorize(color)
428
+
429
+ if debug || (color != :white)
430
+ puts output unless silent
431
+ end
432
+ next if silent or not (debug and debuglevel >= 2)
433
+
434
+ v0.each do |contract, v1|
435
+ puts "\t#{contract
436
+ }\t#{v1.first[:date]
437
+ } (#{format '%3d', Date.parse(v1.first[:date]).yday
438
+ })\t#{Date.parse(v1.last[:date]).strftime('%a, %Y-%m-%d')
439
+ } (#{Date.parse(v1.last[:date]).yday})" unless silent
440
+ # rubocop:enable Layout/ClosingParenthesisIndentation
441
+ end
442
+
432
443
  end
433
- case output_sent.size
434
- when 0
435
- unless silent
436
- puts "WARNING: No output was sent for symbol '#{sym[:symbol]}'.".colorize(:light_yellow)
437
- puts " Assuming late-year-processing.".light_yellow
438
- puts early_year.light_green
439
- end
440
- when 1
441
- # all ok
442
- true
443
- else
444
- puts "Continuous table show #{output_sent.size} active contracts ( #{output_sent} ) for #{sym[:symbol]} ---------------" unless silent
444
+ long_output.sort_by!{|z| z[:until_end] + (z[:until_end].negative? ? 365 : 0)}
445
+
446
+ if short
447
+ return ([long_output.first] + long_output.select{|z| z[:until_start].positive? and z[:until_start] < 10 }).map{|z| z[:contract] }.uniq
445
448
  end
449
+
446
450
  measuring.call("Finished processing")
447
- short ? output_sent : long_output
451
+ return long_output
448
452
  end
449
453
  end
450
454
  end
@@ -68,7 +68,7 @@ module Cotcube
68
68
  raise ArgumentError, ':filter must be in [:volume_part, :oi_part]' unless %i[volume_part oi_part].include? filter
69
69
 
70
70
  # noinspection RubyScope
71
- ids = sym.nil? ? symbols.map { |x| x[:id] } : [sym[:id]]
71
+ ids = sym.nil? ? Cotcube::Helpers.symbols.map { |x| x[:id] } : [sym[:id]]
72
72
  dates = [dates] unless dates.is_a?(Array) || dates.nil?
73
73
 
74
74
  id_path_get = ->(local_id) { "#{config[:data_path]}/eods/#{local_id}" }
@@ -56,6 +56,8 @@ module Cotcube
56
56
  :continuous_overview,
57
57
  # provider estimation of current ML usability
58
58
  :continuous_table,
59
+ # provide a simple filter series
60
+ :filter_series,
59
61
  # provide the list of quarters, possibly as hours or days.
60
62
  :provide_quarters,
61
63
  # some statistics to estimate daily volatility of specific 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.6
4
+ version: 0.1.16
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-19 00:00:00.000000000 Z
11
+ date: 2021-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -164,6 +164,7 @@ files:
164
164
  - README.md
165
165
  - Rakefile
166
166
  - VERSION
167
+ - bin/eod.rb
167
168
  - cotcube-bardata.gemspec
168
169
  - lib/cotcube-bardata.rb
169
170
  - lib/cotcube-bardata/cached.rb