Class: Iro::Priceitem

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
app/models/iro/priceitem.rb

Overview

Specifically Option or Stock priceitem? Priceitems are intra-day! See Datapoint for daily data

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.my_find(props = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/models/iro/priceitem.rb', line 38

def self.my_find props={}
  lookup = { '$lookup': {
    'from':         'iro_price_items',
    'localField':   'date',
    'foreignField': 'date',
    'pipeline': [
      { '$sort': { 'value': -1 } },
    ],
    'as':           'dates',
  } }
  lookup_merge = { '$replaceRoot': {
    'newRoot': { '$mergeObjects': [
      { '$arrayElemAt': [ "$dates", 0 ] }, "$$ROOT"
    ] }
  } }


  match = { '$match': {
    'date': {
      '$gte': props[:begin_on],
      '$lte': props[:end_on],
    }
  } }

  group = { '$group': {
    '_id': "$date",
    'my_doc': { '$first': "$$ROOT" }
  } }

  outs = Iro::Date.collection.aggregate([
    match,

    lookup,
    lookup_merge,

    group,
    { '$replaceRoot': { 'newRoot': "$my_doc" } },
    # { '$replaceRoot': { 'newRoot': "$my_doc" } },


    { '$project': { '_id': 0, 'date': 1, 'value': 1 } },
    { '$sort': { 'date': 1 } },
  ])

  puts! 'result'
  pp outs.to_a
  # puts! outs.to_a, 'result'
end

Instance Method Details

#putCallObject

PUT, CALL, STOCK



12
# File 'app/models/iro/priceitem.rb', line 12

field :putCall,         type: String