cotcube-bardata 0.1.11 → 0.1.12
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 +4 -0
- data/VERSION +1 -1
- data/lib/cotcube-bardata/daily.rb +1 -0
- data/lib/cotcube-bardata/init.rb +2 -2
- data/lib/cotcube-bardata/range_matrix.rb +19 -7
- 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: 5607a73308b8d9d7aff10caccdd3785189072a7d5b2a0b37ea0b6d2bd1ebf4f9
|
4
|
+
data.tar.gz: 18bf8b90e2aad0d32a6608037de861d5383df1bd6d8c6b11e903724c91f172df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3589e6b49ba104aed0177032cd46299c2c0e1db37330e2b869ab6a97f8b81400917bf29ec631cb37b2f35245ece8dcdb147dd56194487d441773d8c79628d38e
|
7
|
+
data.tar.gz: 3be51d9604d9fb1092939b30fa099801c989babae6ec528479d8af5c8b8750e087dc5965f8b05a3cc5d68281a58de93295cba1b2249030a106220b0eea9594bd
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## 0.1.12 (March 13, 2021)
|
2
|
+
- range_matrix: adapted to accept block for range provision; added params :days_only and :last_n
|
3
|
+
- minor fix on previous patch
|
4
|
+
|
1
5
|
## 0.1.11 (March 07, 2021)
|
2
6
|
- daily.rb: added new technique 'caching in constants' to accelerate computation, also referring to continuous
|
3
7
|
- provide.rb: minor change, so disregarded contracts can be used in swapproximate
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.12
|
data/lib/cotcube-bardata/init.rb
CHANGED
@@ -8,9 +8,9 @@ module Cotcube
|
|
8
8
|
SYMBOL_EXAMPLES
|
9
9
|
else
|
10
10
|
CSV
|
11
|
-
.read(config[:symbols_file], headers: %i[id symbol ticksize power months type bcf reports name])
|
11
|
+
.read(config[:symbols_file], headers: %i[id symbol ticksize power months type bcf reports format name])
|
12
12
|
.map(&:to_h)
|
13
|
-
.map { |row| %i[ticksize power bcf].each { |z| row[z] = row[z].to_f }; row } # rubocop:disable Style/Semicolon
|
13
|
+
.map { |row| %i[ticksize power bcf].each { |z| row[z] = row[z].to_f }; row[:format] = "%#{row[:format]}f"; row } # rubocop:disable Style/Semicolon
|
14
14
|
.reject { |row| row[:id].nil? }
|
15
15
|
.tap { |all| all.select! { |x| x[:type] == type } unless type.nil? }
|
16
16
|
.tap { |all| all.select! { |x| x[:symbol] == symbol } unless symbol.nil? }
|
@@ -5,7 +5,6 @@ module Cotcube
|
|
5
5
|
module Bardata
|
6
6
|
# this is an analysis tool to investigate actual ranges of an underlying symbol
|
7
7
|
# it is in particular no true range or average true range, as a 'true range' can only be applied to
|
8
|
-
# a steady series, what changing contracts definitely aren't
|
9
8
|
#
|
10
9
|
# The result printed / returned is a table, containing a matrix of rows:
|
11
10
|
# 1. size: the amount of values evaluated
|
@@ -22,18 +21,26 @@ module Cotcube
|
|
22
21
|
# 3.a-c) same with days reduced to months (c: 12 months)
|
23
22
|
#
|
24
23
|
# NOTE: there is now a new method Cotcube::Helpers.simple_series_stats, that should be used in favor.
|
25
|
-
def range_matrix(symbol: nil, id: nil, print: false, dim: 0.05)
|
24
|
+
def range_matrix(symbol: nil, id: nil, base: nil, print: false, dim: 0.05, days_only: false, last_n: 60, &block)
|
26
25
|
# rubocop:disable Style/MultilineBlockChain
|
26
|
+
symbol ||= base.last[:contract][0..1] if id.nil?
|
27
27
|
sym = get_id_set(symbol: symbol, id: id)
|
28
28
|
source = {}
|
29
29
|
target = {}
|
30
|
-
|
30
|
+
if base.nil?
|
31
|
+
ml = (Cotcube::Bardata.continuous_actual_ml symbol: symbol)&.last[:contract]
|
32
|
+
source[:days] = Cotcube::Bardata.provide contract: ml
|
33
|
+
else
|
34
|
+
source[:days] = base
|
35
|
+
end
|
31
36
|
source[:weeks] = Cotcube::Helpers.reduce bars: source[:days], to: :weeks
|
32
37
|
source[:months] = Cotcube::Helpers.reduce bars: source[:days], to: :months
|
33
38
|
|
34
39
|
%i[days weeks months].each do |period|
|
40
|
+
next if days_only and %i[weeks months].include? period
|
41
|
+
p yield(source[period].first)
|
35
42
|
source[period].map! do |x|
|
36
|
-
x[:range] = ((x[:high] - x[:low]) / sym[:ticksize]).round
|
43
|
+
x[:range] = block_given? ? yield(x) : (((x[:high] - x[:low]) / sym[:ticksize]).round)
|
37
44
|
x
|
38
45
|
end
|
39
46
|
target[period] = {}
|
@@ -80,14 +87,18 @@ module Cotcube
|
|
80
87
|
|
81
88
|
range = case period
|
82
89
|
when :months
|
83
|
-
-
|
90
|
+
-(last_n/15)..-2
|
84
91
|
when :weeks
|
85
|
-
-
|
92
|
+
-(last_n/4)..-2
|
86
93
|
when :days
|
87
|
-
-
|
94
|
+
-last_n..-1
|
88
95
|
else
|
89
96
|
raise ArgumentError, "Unsupported period: '#{period}'"
|
90
97
|
end
|
98
|
+
if range.begin.abs > source[period].size
|
99
|
+
puts "WARNING: requested last_n = #{last_n} exceeds actual size (#{source[period].size}), adjusting...".light_yellow
|
100
|
+
range = (-source[period].size..range.end)
|
101
|
+
end
|
91
102
|
custom = source[period][range]
|
92
103
|
target[period][:rec_size] = custom.size
|
93
104
|
target[period][:rec_avg] = (custom.map { |x| x[:range] }.reduce(:+) / custom.size).round
|
@@ -110,6 +121,7 @@ module Cotcube
|
|
110
121
|
%w[size avg lower median upper max].each do |a|
|
111
122
|
print "#{'%10s' % a} | " # rubocop:disable Style/FormatString
|
112
123
|
%i[days weeks months].each do |b|
|
124
|
+
next if days_only and %i[weeks months].include? b
|
113
125
|
%w[all dim rec].each do |c|
|
114
126
|
print ('%8d' % target[b]["#{c}_#{a}".to_sym]).to_s # rubocop:disable Style/FormatString
|
115
127
|
end
|
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.
|
4
|
+
version: 0.1.12
|
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-03-
|
11
|
+
date: 2021-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|