lib/cotcube-bardata/daily.rb
# based on .continuous, this methods sorts the prepared dailies continuous for each date
# on either :volume (default) or :oi
# with this job done, it can provide the period for which a past contract was the most liquid
#
based on .continuous, this methods sorts the prepared dailies continuous for each date
on either :volume (default) or :oi
with this job done, it can provide the period for which a past contract was the most liquid
based on . continuous this methods sorts the prepared dailies continuous for each date on either : volume ( default ) or : oi with this job done it can provide the period for which a past contract was the most liquid
def continuous_overview(symbol: nil, id: nil, 
                            config: init,
                            selector: :volume,
                            human: false,
                            measure: nil,
                            filter: nil)
      raise ArgumentError, ':measure, if given, must be a Time object (e.g. Time.now)' unless [NilClass, Time].include? measure.class
      measuring = lambda {|c| puts "[continuous_overview] Time measured until '#{c}': #{(Time.now.to_f - measure.to_f).round(2)}sec" unless measure.nil? }
      raise ArgumentError, 'Selector must be either :volume or :oi' unless selector.is_a?(Symbol) &&
        %i[volume oi].include?(selector)
      measuring.call("Starting")
      sym = get_id_set(symbol: symbol, id: id)
      id  = sym[:id]
      data = continuous(id: id, config: config, measure: measure).map do |x|
        {
          date: x[:date],
          volume: x[:contracts].sort_by { |z| - z[:volume] }[0..4].compact.reject { |z| z[:volume].zero? },
          oi: x[:contracts].sort_by { |z| - z[:oi] }[0..4].compact.reject { |z| z[:oi].zero? }
        }
      end
      measuring.call("Retrieved continuous for #{sym[:symbol]}")
      data.reject! { |x| x[selector].empty? }
      result = data.group_by { |x| x[selector].first[:contract] }
      result.each_key do |key|
        result[key].map! do |x|
          x[:volume].select! { |z| z[:contract] == key }
          x[:oi].select!     { |z| z[:contract] == key }
          x
        end
      end
      if human
        result.each do |k, v|
          next unless filter.nil? || v.first[selector].first[:contract][2..4] =~ (/#{filter}/)
          puts "#{k
             }\t#{v.first[:date]
             }\t#{v.last[:date]
             }\t#{format('%4d', (Date.parse(v.last[:date]) - Date.parse(v.first[:date])))
             }\t#{result[k].map do |x|
            x[:volume].select do
              x[:contract] == k
            end
          end.size
             }"
        end
      end
      measuring.call("Finished processing")
      result
    end
def continuous_overview ( symbol : nil , id : nil , config : init , selector : :volume , human : false , measure : nil , filter : nil ) raise ArgumentError , ':measure, if given, must be a Time object (e.g. Time.now)' unless [ NilClass , Time ] . include? measure . class measuring = lambda { | c | puts "[continuous_overview] Time measured until '#{c}': #{(Time.now.to_f - measure.to_f).round(2)}sec" unless measure . nil? } raise ArgumentError , 'Selector must be either :volume or :oi' unless selector . is_a? ( Symbol ) && %i[ volume oi ] . include? ( selector ) measuring . call ( "Starting" ) sym = get_id_set ( symbol : symbol , id : id ) id = sym [ :id ] data = continuous ( id : id , config : config , measure : measure ) . map do | x | { date : x [ :date ] , volume : x [ :contracts ] . sort_by { | z | - z [ :volume ] } [ 0 .. 4 ] . compact . reject { | z | z [ :volume ] . zero? } , oi : x [ :contracts ] . sort_by { | z | - z [ :oi ] } [ 0 .. 4 ] . compact . reject { | z | z [ :oi ] . zero? } } end measuring . call ( "Retrieved continuous for #{sym[:symbol]}" ) data . reject! { | x | x [ selector ] . empty? } result = data . group_by { | x | x [ selector ] . first [ :contract ] } result . each_key do | key | result [ key ] . map! do | x | x [ :volume ] . select! { | z | z [ :contract ] == key } x [ :oi ] . select! { | z | z [ :contract ] == key } x end end if human result . each do | k , v | next unless filter . nil? || v . first [ selector ] . first [ :contract ] [ 2 .. 4 ] =~ ( / #{ filter } / ) puts "#{k
             }\t#{v.first[:date]
             }\t#{v.last[:date]
             }\t#{format('%4d', (Date.parse(v.last[:date]) - Date.parse(v.first[:date])))
             }\t#{result[k].map do |x|
            x[:volume].select do
              x[:contract] == k
            end
          end.size
             }" end end measuring . call ( "Finished processing" ) result end
based on .continuous, this methods sorts the prepared dailies continuous for each date
on either :volume (default) or :oi
with this job done, it can provide the period for which a past contract was the most liquid
based on . continuous this methods sorts the prepared dailies continuous for each date on either : volume ( default ) or : oi with this job done it can provide the period for which a past contract was the most liquid
# rubocop:disable Metrics/ParameterLists # noinspection RubyNilAnalysis # rubocop:disable Layout/ClosingParenthesisIndentation # rubocop:enable Layout/ClosingParenthesisIndentation
symbol
<not_specific>
id
<not_specific>
config
<not_specific>
init
<not_specific>
selector
<not_specific>
human
<not_specific>
measure
<not_specific>
filter
<not_specific>