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, #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.
-
#high_price ⇒ Object
readonly
Returns the value of attribute high_price.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#low_price ⇒ Object
readonly
Returns the value of attribute low_price.
-
#open_price ⇒ Object
readonly
Returns the value of attribute open_price.
-
#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.
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, interval: 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, #to_csv, #to_h, #to_json
Constructor Details
#initialize(price: nil, timestamp: nil, close_price: nil, close_timestamp: nil, volume: nil, interval: nil, base_volume: nil, target_volume: nil, trades: nil) ⇒ Spot
Returns a new instance of Spot.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/quant/ticks/spot.rb', line 27 def initialize( price: nil, timestamp: nil, close_price: nil, close_timestamp: nil, volume: nil, interval: 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 @interval = Interval[interval] @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.
25 26 27 |
# File 'lib/quant/ticks/spot.rb', line 25 def base_volume @base_volume end |
#close_price ⇒ Object (readonly) Also known as: price, oc2, hl2, hlc3, ohlc4, delta
Returns the value of attribute close_price.
24 25 26 |
# File 'lib/quant/ticks/spot.rb', line 24 def close_price @close_price end |
#close_timestamp ⇒ Object (readonly) Also known as: timestamp
Returns the value of attribute close_timestamp.
23 24 25 |
# File 'lib/quant/ticks/spot.rb', line 23 def @close_timestamp end |
#high_price ⇒ Object (readonly)
Returns the value of attribute high_price.
24 25 26 |
# File 'lib/quant/ticks/spot.rb', line 24 def high_price @high_price end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
22 23 24 |
# File 'lib/quant/ticks/spot.rb', line 22 def interval @interval end |
#low_price ⇒ Object (readonly)
Returns the value of attribute low_price.
24 25 26 |
# File 'lib/quant/ticks/spot.rb', line 24 def low_price @low_price end |
#open_price ⇒ Object (readonly)
Returns the value of attribute open_price.
24 25 26 |
# File 'lib/quant/ticks/spot.rb', line 24 def open_price @open_price end |
#open_timestamp ⇒ Object (readonly)
Returns the value of attribute open_timestamp.
23 24 25 |
# File 'lib/quant/ticks/spot.rb', line 23 def @open_timestamp end |
#series ⇒ Object (readonly)
Returns the value of attribute series.
22 23 24 |
# File 'lib/quant/ticks/spot.rb', line 22 def series @series end |
#target_volume ⇒ Object (readonly)
Returns the value of attribute target_volume.
25 26 27 |
# File 'lib/quant/ticks/spot.rb', line 25 def target_volume @target_volume end |
#trades ⇒ Object (readonly)
Returns the value of attribute trades.
25 26 27 |
# File 'lib/quant/ticks/spot.rb', line 25 def trades @trades end |
Instance Method Details
#==(other) ⇒ Object
Two ticks are equal if they have the same close price and close timestamp.
64 65 66 |
# File 'lib/quant/ticks/spot.rb', line 64 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.
71 72 73 |
# File 'lib/quant/ticks/spot.rb', line 71 def corresponding?(other) == other. end |
#inspect ⇒ Object
75 76 77 |
# File 'lib/quant/ticks/spot.rb', line 75 def inspect "#<#{self.class.name} #{interval} ct=#{} c=#{close_price.to_f} v=#{volume}>" end |