Class: Quant::Ticks::Spot
- Includes:
- Quant::TimeMethods
- Defined in:
- lib/quant/ticks/spot.rb
Overview
A Spot
is a single price point in time. It is the most basic form of a Tick and is usually used to represent a continuously streaming tick that just has a single price point at a given point in time.
Constant Summary
Constants included from Quant::TimeMethods
Quant::TimeMethods::EPOCH_DATE, Quant::TimeMethods::EPOCH_TIME
Instance Attribute Summary collapse
-
#base_volume ⇒ Object
(also: #volume)
readonly
Returns the value of attribute base_volume.
-
#close_price ⇒ Object
(also: #price, #high_price, #low_price, #open_price, #oc2, #hl2, #hlc3, #ohlc4, #delta)
readonly
Returns the value of attribute close_price.
-
#close_timestamp ⇒ Object
(also: #timestamp)
readonly
Returns the value of attribute close_timestamp.
-
#open_timestamp ⇒ Object
readonly
Returns the value of attribute open_timestamp.
-
#series ⇒ Object
readonly
Returns the value of attribute series.
-
#target_volume ⇒ Object
readonly
Returns the value of attribute target_volume.
-
#trades ⇒ Object
readonly
Returns the value of attribute trades.
Attributes inherited from Tick
Instance Method Summary collapse
-
#==(other) ⇒ Object
Two ticks are equal if they have the same close price and close timestamp.
-
#corresponding?(other) ⇒ Boolean
The corresponding? method helps determine that the other tick’s timestamp is the same as this tick’s timestamp, which is useful when aligning ticks between two separate series where one starts or ends at a different time, or when there may be gaps in the data between the two series.
-
#initialize(price: nil, timestamp: nil, close_price: nil, close_timestamp: nil, volume: nil, base_volume: nil, target_volume: nil, trades: nil) ⇒ Spot
constructor
A new instance of Spot.
- #inspect ⇒ Object
Methods included from Quant::TimeMethods
epoch_date, epoch_time, #extract_time
Methods inherited from Tick
#assign_series, #assign_series!, #default_serializer_class, default_serializer_class, from, from_json, #interval, #series?, #to_csv, #to_h, #to_json
Constructor Details
#initialize(price: nil, timestamp: nil, close_price: nil, close_timestamp: nil, volume: nil, base_volume: nil, target_volume: nil, trades: nil) ⇒ Spot
Returns a new instance of Spot.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/quant/ticks/spot.rb', line 25 def initialize( price: nil, timestamp: nil, close_price: nil, close_timestamp: nil, volume: nil, base_volume: nil, target_volume: nil, trades: nil ) raise ArgumentError, "Must supply a spot price as either :price or :close_price" unless price || close_price @close_price = (close_price || price).to_f @close_timestamp = extract_time( || || Quant.current_time) @open_timestamp = @close_timestamp @base_volume = (volume || base_volume).to_i @target_volume = (target_volume || @base_volume).to_i @trades = trades.to_i super() end |
Instance Attribute Details
#base_volume ⇒ Object (readonly) Also known as: volume
Returns the value of attribute base_volume.
23 24 25 |
# File 'lib/quant/ticks/spot.rb', line 23 def base_volume @base_volume end |
#close_price ⇒ Object (readonly) Also known as: price, high_price, low_price, open_price, oc2, hl2, hlc3, ohlc4, delta
Returns the value of attribute close_price.
22 23 24 |
# File 'lib/quant/ticks/spot.rb', line 22 def close_price @close_price end |
#close_timestamp ⇒ Object (readonly) Also known as: timestamp
Returns the value of attribute close_timestamp.
21 22 23 |
# File 'lib/quant/ticks/spot.rb', line 21 def @close_timestamp end |
#open_timestamp ⇒ Object (readonly)
Returns the value of attribute open_timestamp.
21 22 23 |
# File 'lib/quant/ticks/spot.rb', line 21 def @open_timestamp end |
#series ⇒ Object (readonly)
Returns the value of attribute series.
20 21 22 |
# File 'lib/quant/ticks/spot.rb', line 20 def series @series end |
#target_volume ⇒ Object (readonly)
Returns the value of attribute target_volume.
23 24 25 |
# File 'lib/quant/ticks/spot.rb', line 23 def target_volume @target_volume end |
#trades ⇒ Object (readonly)
Returns the value of attribute trades.
23 24 25 |
# File 'lib/quant/ticks/spot.rb', line 23 def trades @trades end |
Instance Method Details
#==(other) ⇒ Object
Two ticks are equal if they have the same close price and close timestamp.
62 63 64 |
# File 'lib/quant/ticks/spot.rb', line 62 def ==(other) [close_price, ] == [other.close_price, other.] end |
#corresponding?(other) ⇒ Boolean
The corresponding? method helps determine that the other tick’s timestamp is the same as this tick’s timestamp, which is useful when aligning ticks between two separate series where one starts or ends at a different time, or when there may be gaps in the data between the two series.
69 70 71 |
# File 'lib/quant/ticks/spot.rb', line 69 def corresponding?(other) == other. end |
#inspect ⇒ Object
73 74 75 |
# File 'lib/quant/ticks/spot.rb', line 73 def inspect "#<#{self.class.name} ct=#{} c=#{close_price.to_f} v=#{volume}>" end |