cotcube-helpers 0.1.2 → 0.1.3

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: 01aae33281c410de2818d90ab99e2125c5841ad2f6148a71c7950eb84bb07c33
4
- data.tar.gz: 1e4e1fbeaa9d7a3b71bff8fd0325f77ab390620ddd933992b6a138db48fbd77d
3
+ metadata.gz: cec4f9d660486e17a4ff9ef38f53ffd1a5089de00ecbcdadb016b80dbc4231f9
4
+ data.tar.gz: 90943be69de4e059082d49070741b9689cd714a5a88a4b8ead2dea74ab4f3017
5
5
  SHA512:
6
- metadata.gz: 2e15e9005df3ed00b77b90f12d99b67b92838034a2339ff9255b7c4986cbcd7764ed7fc01bf4de5edcd1032bd885d39de4d045529bc34a6826a6e97c9b954cdf
7
- data.tar.gz: edf104056c0a4ea83bf3384a4f5c10ed240f6638e04da12053a84322853d036b1f38bb75ddf96146a195bf2861be9f999bf743a80ff2a14968f5dbdc36b7d2a9
6
+ metadata.gz: bf6306e1baaadfe9fa6f6b4533d2bfb0c31fc464ffa288368d3e47a22f76c1db7a1c48470aa83970e52752b4a911a7b60f759ee75495df43f093661274c13f0c
7
+ data.tar.gz: 6ea7ccc812fd160479f9519532669db81fbf4311fcb6335b841d738bcd81c86e922c994bb005e56c543b4cf0cd3f1d7a4a92db1ad7b52e5ac4d770c6932139cb
@@ -1,3 +1,6 @@
1
+ ## 0.1.3 (December 22, 2020)
2
+ - added .reduce(bars: , to: ,*args, &block) to reduce a series of bars to a higher timeframe (though only 1hour and 1day are supported yet)
3
+
1
4
  ## 0.1.2 (December 21, 2020)
2
5
  - minor changes
3
6
  - minor fix to parallelize and application of positional arguments
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -14,6 +14,7 @@ require_relative 'cotcube-helpers/subpattern.rb'
14
14
  require_relative 'cotcube-helpers/parallelize'
15
15
  require_relative 'cotcube-helpers/simple_output'
16
16
  require_relative 'cotcube-helpers/input'
17
+ require_relative 'cotcube-helpers/reduce'
17
18
 
18
19
 
19
20
  module Cotcube
@@ -21,6 +22,7 @@ module Cotcube
21
22
 
22
23
  module_function :sub,
23
24
  :parallelize,
25
+ :reduce,
24
26
  :keystroke
25
27
 
26
28
 
@@ -0,0 +1,44 @@
1
+ module Cotcube
2
+ module Helpers
3
+ def reduce(bars: , to: nil, datelike: :datetime, &block)
4
+ terminators = case to
5
+ when 1.day
6
+ [:last, :beginning_of_day]
7
+ when 1.hour
8
+ [:first, :beginning_of_hour]
9
+ else
10
+ raise ArgumentError, "Currently supported are reductions to '1.hour' and '1.day'"
11
+ end
12
+ determine_datelike = lambda {|ary| ary.send(terminators.first)[datelike].send(terminators.last) }
13
+ make_new_bar = lambda do |ary, date = nil|
14
+ result = {
15
+ symbol: ary.first[:symbol],
16
+ datetime: determine_datelike.call(ary),
17
+ day: ary.first[:day],
18
+ open: ary.first[:open],
19
+ high: ary.map{|x| x[:high]}.max,
20
+ low: ary.map{|x| x[:low]}.min,
21
+ close: ary.last[:close],
22
+ volume: ary.map{|x| x[:volume]}.reduce(:+)
23
+ }
24
+ result.map{|k,v| result.delete(k) if v.nil?}
25
+ result
26
+ end
27
+ collector = [ ]
28
+ final = [ ]
29
+ bars.each do |bar|
30
+ if collector.empty? or block.call(collector.last, bar)
31
+ collector << bar
32
+ else
33
+ new_bar = make_new_bar.call(collector)
34
+ final << new_bar
35
+ collector = [ bar ]
36
+ end
37
+ end
38
+ new_bar = make_new_bar.call(collector)
39
+ final << new_bar
40
+ final
41
+ end
42
+ end
43
+ end
44
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cotcube-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
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: 2020-12-21 00:00:00.000000000 Z
11
+ date: 2020-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -87,6 +87,7 @@ files:
87
87
  - lib/cotcube-helpers/input.rb
88
88
  - lib/cotcube-helpers/parallelize.rb
89
89
  - lib/cotcube-helpers/range_ext.rb
90
+ - lib/cotcube-helpers/reduce.rb
90
91
  - lib/cotcube-helpers/simple_output.rb
91
92
  - lib/cotcube-helpers/string_ext.rb
92
93
  - lib/cotcube-helpers/subpattern.rb