cotcube-bardata 0.1.15.2 → 0.1.15.4
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/CHANGELOG.md +6 -0
- data/VERSION +1 -1
- data/lib/cotcube-bardata/daily.rb +31 -40
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48c3d1d43865ad1b7bba959025aa38ecf0ea574a8a946740f8226aa06741e600
|
4
|
+
data.tar.gz: 4da3026ca588bd848648242c8f21d482e86bb8be72f4a6f0e45b543fca461e05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1235c3ba86c1aa51cd0925912e8f60b07c898498070d86f00d45747aa3041b69039974f04524c4fec187f924bff495596ac0ec32d812d444f8cb5d2b8d223afe
|
7
|
+
data.tar.gz: a9c4753b1cb05598d18c9d0f62d4ecb652b4430ec84ee8ad9900d2cdf0d9bc5330e5b5a8b8b0fa6ff2dda82a72b1087b5f8c28d257b9ce3c6763dd22080c1681
|
data/CHANGELOG.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.15.
|
1
|
+
0.1.15.4
|
@@ -10,8 +10,10 @@ module Cotcube
|
|
10
10
|
timezone: Time.find_zone('America/Chicago'),
|
11
11
|
keep_last: false,
|
12
12
|
add_eods: true,
|
13
|
+
indicators: {},
|
13
14
|
config: init)
|
14
15
|
contract = contract.to_s.upcase
|
16
|
+
rounding = 8
|
15
17
|
unless contract.is_a?(String) && [3, 5].include?(contract.size)
|
16
18
|
raise ArgumentError, "Contract '#{contract}' is bogus, should be like 'M21' or 'ESM21'"
|
17
19
|
end
|
@@ -43,7 +45,10 @@ module Cotcube
|
|
43
45
|
data = CSV.read(data_file, headers: %i[contract date open high low close volume oi]).map do |row|
|
44
46
|
row = row.to_h
|
45
47
|
row.each do |k, _|
|
46
|
-
|
48
|
+
if %i[open high low close].include? k
|
49
|
+
row[k] = row[k].to_f
|
50
|
+
row[k] = (row[k] * sym[:bcf]).round(8) unless sym[:bcf] == 1.0
|
51
|
+
end
|
47
52
|
row[k] = row[k].to_i if %i[volume oi].include? k
|
48
53
|
end
|
49
54
|
row[:datetime] = timezone.parse(row[:date])
|
@@ -57,19 +62,28 @@ module Cotcube
|
|
57
62
|
today = Date.today
|
58
63
|
eods = [ ]
|
59
64
|
while today.strftime('%Y-%m-%d') > data.last[:date]
|
60
|
-
eods << provide_eods(symbol: sym[:symbol], dates: today, contracts_only: false)
|
65
|
+
eods << provide_eods(symbol: sym[:symbol], dates: today, contracts_only: false, quiet: true)
|
61
66
|
today -= 1
|
62
67
|
end
|
63
68
|
eods.flatten!.map!{|x| x.tap {|y| %i[ volume_part oi_part ].map{|z| y.delete(z)} } }
|
64
|
-
eods.select{|x| x[:contract] == contract }
|
69
|
+
eods.select!{|x| x[:contract] == "#{sym[:symbol]}#{contract}" }
|
65
70
|
eods.map!{|x| x.tap{|y|
|
71
|
+
if sym[:bcf] != 1.0
|
72
|
+
%i[open high low close].map{|k|
|
73
|
+
y[k] = (y[k] * sym[:bcf]).round(8)
|
74
|
+
}
|
75
|
+
end
|
66
76
|
y[:datetime] = timezone.parse(y[:date])
|
67
77
|
y[:dist] = ((y[:high] - y[:low]) / sym[:ticksize] ).to_i
|
68
78
|
y[:type] = :eod
|
69
79
|
} }
|
70
80
|
data += eods.reverse
|
71
|
-
|
72
81
|
end
|
82
|
+
data.map do |bar|
|
83
|
+
indicators.each do |k,v|
|
84
|
+
bar[k] = v.call(bar).round(rounding)
|
85
|
+
end
|
86
|
+
end unless indicators.empty?
|
73
87
|
if range.nil?
|
74
88
|
data
|
75
89
|
else
|
@@ -82,7 +96,7 @@ module Cotcube
|
|
82
96
|
|
83
97
|
# reads all files in bardata/daily/<id> and aggregates by date
|
84
98
|
# (what is a pre-stage of a continuous based on daily bars)
|
85
|
-
def continuous(symbol: nil, id: nil, config: init, date: nil, measure: nil, force_rewrite: false, selector: nil, debug: false, add_eods: true)
|
99
|
+
def continuous(symbol: nil, id: nil, config: init, date: nil, measure: nil, force_rewrite: false, selector: nil, debug: false, add_eods: true, indicators: nil)
|
86
100
|
raise ArgumentError, ':measure, if given, must be a Time object (e.g. Time.now)' unless [NilClass, Time].include? measure.class
|
87
101
|
measuring = lambda {|c| puts "[continuous] Time measured until '#{c}': #{(Time.now.to_f - measure.to_f).round(2)}sec" unless measure.nil? }
|
88
102
|
|
@@ -99,7 +113,7 @@ module Cotcube
|
|
99
113
|
|
100
114
|
# instead of using the provide_daily methods above, for this bulk operation a 'continuous.csv' is created
|
101
115
|
# this boosts from 4.5sec to 0.3sec
|
102
|
-
rewriting = force_rewrite or not(File.exist?(c_file)) or (Time.now - File.mtime(c_file) > 8.days)
|
116
|
+
rewriting = (force_rewrite or not(File.exist?(c_file)) or (Time.now - File.mtime(c_file) > 8.days))
|
103
117
|
if rewriting
|
104
118
|
puts "In daily+continuous: Rewriting #{c_file} #{force_rewrite ? "forcibly" : "due to fileage"}.".light_yellow
|
105
119
|
`rm #{c_file}; find #{id_path} | xargs cat 2>/dev/null | grep -v ',0,' | grep -v ',0$'| sort -t, -k2 | cut -d, -f1-8 | grep ',.*,' | uniq > #{c_file}`
|
@@ -113,20 +127,20 @@ module Cotcube
|
|
113
127
|
low: row[4],
|
114
128
|
close: row[5],
|
115
129
|
volume: row[6].to_i,
|
116
|
-
oi: row[7].to_i
|
130
|
+
oi: row[7].to_i,
|
131
|
+
type: :cont
|
117
132
|
}
|
118
133
|
end
|
119
134
|
if add_eods
|
120
135
|
today = Date.today
|
121
136
|
eods = [ ]
|
122
137
|
while today.strftime('%Y-%m-%d') > data.last[:date]
|
123
|
-
eods << provide_eods(symbol: symbol, dates: today, contracts_only: false)
|
138
|
+
eods << provide_eods(symbol: symbol, dates: today, contracts_only: false, quiet: true)
|
124
139
|
today -= 1
|
125
140
|
end
|
126
141
|
eods.flatten!.map!{|x| x.tap {|y| %i[ volume_part oi_part ].map{|z| y.delete(z)} } }
|
127
142
|
eods.delete_if { |elem| elem.flatten.empty? }
|
128
143
|
data += eods.reverse
|
129
|
-
|
130
144
|
end
|
131
145
|
|
132
146
|
measuring.call("Finished retrieving dailies.")
|
@@ -137,34 +151,7 @@ module Cotcube
|
|
137
151
|
sma250_high: Cotcube::Indicators.sma(key: :high, length: 250),
|
138
152
|
sma250_low: Cotcube::Indicators.sma(key: :low, length: 250),
|
139
153
|
sma250_typ: Cotcube::Indicators.sma(key: :typical, length: 250),
|
140
|
-
|
141
|
-
# tr: Cotcube::Indicators.true_range,
|
142
|
-
# atr5: Cotcube::Indicators.sma(key: :tr, length: 5),
|
143
|
-
# dist_abs: Cotcube::Indicators.calc(a: :sma250_high, b: :sma250_low, c: :high, d: :low) do |sma_high, sma_low, high, low|
|
144
|
-
# if high > sma_high
|
145
|
-
# high - sma_high
|
146
|
-
# elsif sma_low > low
|
147
|
-
# low - sma_low
|
148
|
-
# else
|
149
|
-
# 0
|
150
|
-
# end
|
151
|
-
#end,
|
152
|
-
#dist_sma: Cotcube::Indicators.calc(a: :sma250_typ, b: :sma60_typ) do |sma250, sma60|
|
153
|
-
# sma60 - sma250
|
154
|
-
#end,
|
155
|
-
#dist_index: Cotcube::Indicators.index(key: :dist_abs, length: 60, abs: true),
|
156
|
-
#dev250_squared: Cotcube::Indicators.calc(a: :sma250_typ, b: :typical) {|sma, x| (sma - x) ** 2 },
|
157
|
-
#var250: Cotcube::Indicators.sma(key: :dev250_squared, length: long),
|
158
|
-
#sig250: Cotcube::Indicators.calc(a: :var250) {|var| Math.sqrt(var)},
|
159
|
-
#boll250_high: Cotcube::Indicators.calc(a: :sig250, b: :sma250_typ) {|sig, typ| (typ + sig * bollinger_factor) rescue nil},
|
160
|
-
#boll250_low: Cotcube::Indicators.calc(a: :sig250, b: :sma250_typ) {|sig, typ| (typ - sig * bollinger_factor) rescue nil},
|
161
|
-
#dev60_squared: Cotcube::Indicators.calc(a: :sma60_typ, b: :typical) {|sma, x| (sma - x) ** 2 },
|
162
|
-
#var60: Cotcube::Indicators.sma(key: :dev60_squared, length: short),
|
163
|
-
#sig60: Cotcube::Indicators.calc(a: :var60) {|var| Math.sqrt(var)},
|
164
|
-
#boll60_high: Cotcube::Indicators.calc(a: :sig60, b: :sma60_typ) {|sig, typ| (typ + sig * bollinger_factor) rescue nil},
|
165
|
-
#boll60_low: Cotcube::Indicators.calc(a: :sig60, b: :sma60_typ) {|sig, typ| (typ - sig * bollinger_factor) rescue nil}
|
166
|
-
dist: Cotcube::Indicators.calc(a: :high, b: :low, finalize: :to_i) {|high, low| ((high-low) / ticksize) }
|
167
|
-
|
154
|
+
dist: Cotcube::Indicators.calc(a: :high, b: :low, finalize: :to_i) {|high, low| ((high-low) / ticksize) },
|
168
155
|
}
|
169
156
|
|
170
157
|
|
@@ -177,10 +164,13 @@ module Cotcube
|
|
177
164
|
open: nil, high: nil, low: nil, close: nil,
|
178
165
|
volume: v.map { |x| x[:volume] }.reduce(:+),
|
179
166
|
oi: v.map { |x| x[:oi] }.reduce(:+),
|
167
|
+
type: :cont_eod
|
180
168
|
}
|
181
169
|
|
182
170
|
%i[ open high low close ].each do |ohlc|
|
183
171
|
avg_bar[ohlc] = (v.map{|x| x[ohlc].to_f * x[effective_selector] }.reduce(:+) / avg_bar[effective_selector]).round(rounding)
|
172
|
+
avg_bar[ohlc] = (avg_bar[ohlc] * sym[:bcf]).round(8) unless sym[:bcf] == 1.0
|
173
|
+
|
184
174
|
end
|
185
175
|
p avg_bar if debug
|
186
176
|
indicators.each do |k,v|
|
@@ -326,17 +316,18 @@ module Cotcube
|
|
326
316
|
|
327
317
|
ytoday = date.yday
|
328
318
|
data = continuous_overview(id: id, selector: selector, filter: filter, human: false, config: init, measure: measure)
|
329
|
-
.reject { |k, _| k[-2..].to_i
|
319
|
+
.reject { |k, _| k[-2..].to_i >= date.year % 2000 }
|
330
320
|
.group_by { |k, _| k[2] }
|
331
321
|
measuring.call("Retrieved continous_overview")
|
332
322
|
output_sent = []
|
333
323
|
early_year=nil
|
334
324
|
long_output = []
|
335
325
|
data.keys.sort.each do |month|
|
336
|
-
current_long = { month: month }
|
337
326
|
puts "Processing #{sym[:symbol]}#{month}" if debuglevel > 1
|
338
327
|
v0 = data[month]
|
328
|
+
# ldays is the list of 'last days'
|
339
329
|
ldays = v0.map { |_, v1| Date.parse(v1.last[:date]).yday }
|
330
|
+
# fdays is the list of 'first days'
|
340
331
|
fdays = v0.map { |_, v1| Date.parse(v1.first[:date]).yday }.sort
|
341
332
|
# if the last ml day nears the end of the year, we must fix
|
342
333
|
ldays.map! { |x| x > 350 ? x - 366 : x } if ldays.min < 50
|
@@ -374,8 +365,8 @@ module Cotcube
|
|
374
365
|
}: #{dfm.call(ldays.max)}".colorize(color)
|
375
366
|
if debug || (color != :white)
|
376
367
|
puts output unless silent
|
377
|
-
output_sent << "#{sym[:symbol]}#{month}" unless color == :white
|
378
368
|
end
|
369
|
+
output_sent << "#{sym[:symbol]}#{month}" unless color == :white
|
379
370
|
early_year ||= output
|
380
371
|
next if silent or not (debug and debuglevel >= 2)
|
381
372
|
|
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.
|
4
|
+
version: 0.1.15.4
|
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
|
+
date: 2021-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|