sqa 0.0.18 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/checksums/sqa-0.0.19.gem.sha512 +1 -0
- data/checksums/sqa-0.0.20.gem.sha512 +1 -0
- data/lib/patches/string.rb +58 -0
- data/lib/sqa/data_frame.rb +54 -14
- data/lib/sqa/version.rb +1 -1
- data/lib/sqa.rb +8 -3
- metadata +5 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eaf6c6d975b4bb899fc3f82e79b1fb87b6f4cdad17b19d7e2c5b8300d8cce107
|
4
|
+
data.tar.gz: 2b06b6ffcc711e4d593e18ba7f68508bfb423d60be9d4358ef0953ce2a8983d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ddbd102bb0aa138c39177f4900159e5767739c60943e3ea5d03c07b0cfd1cdfa6cd78db3ea13f502aeee4a31826be64fb36e3d8f9ffa895c30263d5577e6759
|
7
|
+
data.tar.gz: 3b9365d693970575b0d922deccb2c37261ebb4a0ffe5c35109522e85ad861410d2391914b6a3ea7ff4b01d84be721470ee3dc783086517a0e55de84161e2d1c4
|
@@ -0,0 +1 @@
|
|
1
|
+
be42cf0864e1e35a06e177102943577683057e0023751a35421939fc6e096b0e1d16d2e218e33c9c363b45a5a9f57ed22d4361766365154433f5eb371210fb48
|
@@ -0,0 +1 @@
|
|
1
|
+
46d87a1698df7159658dbb5be0d8d3b50209d85cac5085c5d7ee904b1d095c955a25f5f89a79f1af9a0a8c64cda51db58ebb8ae0b23ded2f8d4d680d8ed49606
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# sqa/lib/patches/string.rb
|
2
|
+
|
3
|
+
|
4
|
+
#####################################################################
|
5
|
+
###
|
6
|
+
## File: string.rb
|
7
|
+
## Desc: Monkey to the String class.
|
8
|
+
#
|
9
|
+
|
10
|
+
class String
|
11
|
+
|
12
|
+
##################################
|
13
|
+
## Convert CamelCase to camel_case
|
14
|
+
def to_underscore
|
15
|
+
self.gsub(/::/, '/')
|
16
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
17
|
+
.gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("- ", "_")
|
18
|
+
.downcase
|
19
|
+
end
|
20
|
+
|
21
|
+
alias :to_snakecase :to_underscore
|
22
|
+
alias :snakecase :to_underscore
|
23
|
+
alias :snake_case :to_underscore
|
24
|
+
alias :underscore :to_underscore
|
25
|
+
|
26
|
+
|
27
|
+
##################################
|
28
|
+
## Convert camel_case to CamelCase
|
29
|
+
def to_camelcase
|
30
|
+
self.gsub(/\/(.?)/) { "::" + $1.upcase }
|
31
|
+
.gsub(/(^|_)(.)/) { $2.upcase }
|
32
|
+
end
|
33
|
+
|
34
|
+
alias :camelcase :to_camelcase
|
35
|
+
alias :camelize :to_camelcase
|
36
|
+
|
37
|
+
|
38
|
+
##################################
|
39
|
+
## Convert "CamelCase" into CamelCase
|
40
|
+
def to_constant
|
41
|
+
names = self.split('::')
|
42
|
+
names.shift if names.empty? || names.first.empty?
|
43
|
+
|
44
|
+
constant = Object
|
45
|
+
names.each do |name|
|
46
|
+
if '1.9' == RUBY_VERSION[0,3]
|
47
|
+
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
48
|
+
else
|
49
|
+
constant = constant.const_get(name) || constant.const_missing(name)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
constant
|
53
|
+
end
|
54
|
+
|
55
|
+
alias :constantize :to_constant
|
56
|
+
end
|
57
|
+
|
58
|
+
|
data/lib/sqa/data_frame.rb
CHANGED
@@ -22,11 +22,51 @@ class SQA::DataFrame
|
|
22
22
|
attr_accessor :data
|
23
23
|
|
24
24
|
# Expects a Hash of Arrays (hofa)
|
25
|
-
|
26
|
-
|
25
|
+
# mapping: and transformers: are optional
|
26
|
+
# mapping is a Hash { old_key => new_key }
|
27
|
+
# transformers is also a Hash { key => Proc}
|
28
|
+
def initialize(
|
29
|
+
aofh_or_hofa= {}, # Array of Hashes or hash of array or hash
|
30
|
+
mapping: {}, # { old_key => new_key }
|
31
|
+
transformers: {} # { key => Proc }
|
32
|
+
)
|
33
|
+
|
34
|
+
if aofh_or_hofa.is_a? Hash
|
35
|
+
initialize_hofa(aofh_or_hofa, mapping: mapping)
|
36
|
+
|
37
|
+
elsif aofh_or_hofa.is_a?(Array) &&
|
38
|
+
aofh_or_hofa.first.is_a?(Hash)
|
39
|
+
initialize_aofh(aofh_or_hofa, mapping: mapping)
|
40
|
+
|
41
|
+
else
|
42
|
+
raise BadParameterError, "Expecting Hash or Array of Hashes got: #{aofh_or_hofa.class}"
|
43
|
+
end
|
44
|
+
|
45
|
+
coerce_vectors!(transformers) unless transformers.empty?
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
def initialize_aofh(aofh, mapping:)
|
50
|
+
hofa = self.class.aofh_to_hofa(
|
51
|
+
aofh,
|
52
|
+
mapping: mapping
|
53
|
+
)
|
54
|
+
|
55
|
+
initialize_hofa(hofa, mapping: mapping)
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def initialize_hofa(hofa, mapping:)
|
60
|
+
hofa = self.class.normalize_keys(
|
61
|
+
hofa,
|
62
|
+
adapter_mapping: mapping
|
63
|
+
) unless mapping.empty?
|
64
|
+
|
65
|
+
@data = Data.new(hofa)
|
27
66
|
end
|
28
67
|
|
29
68
|
|
69
|
+
|
30
70
|
def to_csv(path_to_file)
|
31
71
|
CSV.open(path_to_file, 'w') do |csv|
|
32
72
|
csv << keys
|
@@ -74,9 +114,11 @@ class SQA::DataFrame
|
|
74
114
|
def_delegator :@data, :[]=, :[]=
|
75
115
|
|
76
116
|
|
117
|
+
# same as values.transpose
|
118
|
+
# TODO: do benchmark to see if the transpose method if faster
|
77
119
|
def rows
|
78
120
|
result = []
|
79
|
-
|
121
|
+
size.times do |x|
|
80
122
|
entry = row(x)
|
81
123
|
result << entry
|
82
124
|
end
|
@@ -110,14 +152,14 @@ class SQA::DataFrame
|
|
110
152
|
end
|
111
153
|
|
112
154
|
|
113
|
-
def append(new_df)
|
155
|
+
def append!(new_df)
|
114
156
|
raise(BadParameterError, "Key mismatch") if keys != new_df.keys
|
115
157
|
|
116
158
|
keys.each do |key|
|
117
159
|
@data[key] += new_df[key]
|
118
160
|
end
|
119
161
|
end
|
120
|
-
alias_method :concat
|
162
|
+
alias_method :concat!, :append!
|
121
163
|
|
122
164
|
|
123
165
|
# Creates a new instance with new keys
|
@@ -144,7 +186,7 @@ class SQA::DataFrame
|
|
144
186
|
# price: -> (v) {v.to_f.round(3)}
|
145
187
|
# }
|
146
188
|
#
|
147
|
-
def coerce_vectors(transformers)
|
189
|
+
def coerce_vectors!(transformers)
|
148
190
|
transformers.each_pair do |key, transformer|
|
149
191
|
@data[key].map!{|v| transformer.call(v)}
|
150
192
|
end
|
@@ -170,8 +212,8 @@ class SQA::DataFrame
|
|
170
212
|
#################################################
|
171
213
|
class << self
|
172
214
|
|
173
|
-
def
|
174
|
-
base_df.
|
215
|
+
def concat(base_df, other_df)
|
216
|
+
base_df.concat!(other_df)
|
175
217
|
end
|
176
218
|
|
177
219
|
|
@@ -191,7 +233,7 @@ class SQA::DataFrame
|
|
191
233
|
end
|
192
234
|
|
193
235
|
unless transformers.empty?
|
194
|
-
df.coerce_vectors(transformers)
|
236
|
+
df.coerce_vectors!(transformers)
|
195
237
|
end
|
196
238
|
|
197
239
|
df
|
@@ -200,11 +242,9 @@ class SQA::DataFrame
|
|
200
242
|
|
201
243
|
def from_aofh(aofh, mapping: {}, transformers: {})
|
202
244
|
new(
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
transformers: transformers
|
207
|
-
)
|
245
|
+
aofh,
|
246
|
+
mapping: mapping,
|
247
|
+
transformers: transformers
|
208
248
|
)
|
209
249
|
end
|
210
250
|
|
data/lib/sqa/version.rb
CHANGED
data/lib/sqa.rb
CHANGED
@@ -16,8 +16,7 @@ end
|
|
16
16
|
#############################################
|
17
17
|
## Additional Libraries
|
18
18
|
|
19
|
-
require '
|
20
|
-
require 'alphavantage' # TODO: add rate limiter to it; ** PR submitted! **
|
19
|
+
require 'alphavantage'
|
21
20
|
require 'api_key_manager'
|
22
21
|
require 'amazing_print'
|
23
22
|
require 'faraday'
|
@@ -31,6 +30,12 @@ require 'tty-option'
|
|
31
30
|
require 'tty-table'
|
32
31
|
|
33
32
|
|
33
|
+
#############################################
|
34
|
+
## Apply core class monkey patches
|
35
|
+
|
36
|
+
require_relative "patches/string.rb"
|
37
|
+
|
38
|
+
|
34
39
|
#############################################
|
35
40
|
## SQA soecufuc code
|
36
41
|
|
@@ -46,7 +51,7 @@ require_relative 'sqa/init.rb'
|
|
46
51
|
|
47
52
|
require_relative "sqa/config"
|
48
53
|
require_relative "sqa/constants" # SMELL: more app than gem
|
49
|
-
require_relative "sqa/data_frame"
|
54
|
+
require_relative "sqa/data_frame"
|
50
55
|
require_relative "sqa/indicator"
|
51
56
|
require_relative "sqa/portfolio"
|
52
57
|
require_relative "sqa/strategy"
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sqa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dewayne VanHoozer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-10-
|
11
|
+
date: 2023-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: activesupport
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 7.0.6
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - '='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 7.0.6
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: alphavantage
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -243,7 +229,9 @@ files:
|
|
243
229
|
- checksums/sqa-0.0.15.gem.sha512
|
244
230
|
- checksums/sqa-0.0.17.gem.sha512
|
245
231
|
- checksums/sqa-0.0.18.gem.sha512
|
232
|
+
- checksums/sqa-0.0.19.gem.sha512
|
246
233
|
- checksums/sqa-0.0.2.gem.sha512
|
234
|
+
- checksums/sqa-0.0.20.gem.sha512
|
247
235
|
- checksums/sqa-0.0.3.gem.sha512
|
248
236
|
- checksums/sqa-0.0.4.gem.sha512
|
249
237
|
- checksums/sqa-0.0.5.gem.sha512
|
@@ -277,6 +265,7 @@ files:
|
|
277
265
|
- docs/stochastic_oscillator.md
|
278
266
|
- docs/strategy.md
|
279
267
|
- docs/true_range.md
|
268
|
+
- lib/patches/string.rb
|
280
269
|
- lib/sqa.rb
|
281
270
|
- lib/sqa/activity.rb
|
282
271
|
- lib/sqa/analysis.rb
|