Class: Quant::Ticks::Value
- Inherits:
-
Object
- Object
- Quant::Ticks::Value
- Includes:
- Quant::TimeMethods
- Defined in:
- lib/quant/ticks/value.rb
Overview
Value ticks are the most basic ticks and are used to represent a single price point (no open, high, low, close, etc.) and a single timestamp. Usually, these are best used in streaming data where ticks are flowing in every second or whatever interval that’s appropriate for the data source. Often indicators and charts still want a universal public interface (i.e. open_price, high_price, volume, etc.), so we add those methods here and inherit and redefine upstream as appropriate.
For Value ticks:
-
The
pricegiven is set for all *_price fields. -
The
volumeis set for both base and target volume. -
The
timestampis set for both open and close timestamps.
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: #oc2, #hl2, #hlc3, #ohlc4, #delta)
readonly
Returns the value of attribute close_price.
-
#close_timestamp ⇒ Object
readonly
Returns the value of attribute close_timestamp.
-
#doji ⇒ Object
readonly
Returns the value of attribute doji.
-
#green ⇒ Object
readonly
Returns the value of attribute green.
-
#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
-
#assign_series(new_series) ⇒ Object
ticks are immutable across series so we can easily initialize sub-sets or new series with the same ticks while allowing each series to have its own state and full control over the ticks within its series.
- #assign_series!(new_series) ⇒ Object
- #corresponding?(other) ⇒ Boolean
-
#initialize(price:, timestamp: Quant.current_time, interval: nil, volume: 0, trades: 0) ⇒ Value
constructor
A new instance of Value.
- #inspect ⇒ Object
- #to_h ⇒ Object
- #to_json(*_args) ⇒ Object
Methods included from Quant::TimeMethods
epoch_date, epoch_time, #extract_time
Constructor Details
#initialize(price:, timestamp: Quant.current_time, interval: nil, volume: 0, trades: 0) ⇒ Value
Returns a new instance of Value.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/quant/ticks/value.rb', line 24 def initialize(price:, timestamp: Quant.current_time, interval: nil, volume: 0, trades: 0) @interval = Interval[interval] @close_timestamp = extract_time() @open_timestamp = @close_timestamp @close_price = price.to_f @open_price = close_price @high_price = close_price @low_price = close_price @base_volume = volume.to_i @target_volume = volume.to_i @trades = trades.to_i # Set the series by appending to the series @series = nil end |
Instance Attribute Details
#base_volume ⇒ Object (readonly) Also known as: volume
Returns the value of attribute base_volume.
21 22 23 |
# File 'lib/quant/ticks/value.rb', line 21 def base_volume @base_volume end |
#close_price ⇒ Object (readonly) Also known as: oc2, hl2, hlc3, ohlc4, delta
Returns the value of attribute close_price.
20 21 22 |
# File 'lib/quant/ticks/value.rb', line 20 def close_price @close_price end |
#close_timestamp ⇒ Object (readonly)
Returns the value of attribute close_timestamp.
19 20 21 |
# File 'lib/quant/ticks/value.rb', line 19 def @close_timestamp end |
#doji ⇒ Object (readonly)
Returns the value of attribute doji.
22 23 24 |
# File 'lib/quant/ticks/value.rb', line 22 def doji @doji end |
#green ⇒ Object (readonly)
Returns the value of attribute green.
22 23 24 |
# File 'lib/quant/ticks/value.rb', line 22 def green @green end |
#high_price ⇒ Object (readonly)
Returns the value of attribute high_price.
20 21 22 |
# File 'lib/quant/ticks/value.rb', line 20 def high_price @high_price end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
18 19 20 |
# File 'lib/quant/ticks/value.rb', line 18 def interval @interval end |
#low_price ⇒ Object (readonly)
Returns the value of attribute low_price.
20 21 22 |
# File 'lib/quant/ticks/value.rb', line 20 def low_price @low_price end |
#open_price ⇒ Object (readonly)
Returns the value of attribute open_price.
20 21 22 |
# File 'lib/quant/ticks/value.rb', line 20 def open_price @open_price end |
#open_timestamp ⇒ Object (readonly)
Returns the value of attribute open_timestamp.
19 20 21 |
# File 'lib/quant/ticks/value.rb', line 19 def @open_timestamp end |
#series ⇒ Object (readonly)
Returns the value of attribute series.
18 19 20 |
# File 'lib/quant/ticks/value.rb', line 18 def series @series end |
#target_volume ⇒ Object (readonly)
Returns the value of attribute target_volume.
21 22 23 |
# File 'lib/quant/ticks/value.rb', line 21 def target_volume @target_volume end |
#trades ⇒ Object (readonly)
Returns the value of attribute trades.
21 22 23 |
# File 'lib/quant/ticks/value.rb', line 21 def trades @trades end |
Instance Method Details
#==(other) ⇒ Object
54 55 56 |
# File 'lib/quant/ticks/value.rb', line 54 def ==(other) to_h == other.to_h end |
#assign_series(new_series) ⇒ Object
ticks are immutable across series so we can easily initialize sub-sets or new series with the same ticks while allowing each series to have its own state and full control over the ticks within its series
61 62 63 64 65 66 67 68 |
# File 'lib/quant/ticks/value.rb', line 61 def assign_series(new_series) assign_series!(new_series) if @series.nil? # dup.tap do |new_tick| # # new_tick.instance_variable_set(:@series, new_series) # new_tick.instance_variable_set(:@indicators, indicators) # end end |
#assign_series!(new_series) ⇒ Object
70 71 72 73 |
# File 'lib/quant/ticks/value.rb', line 70 def assign_series!(new_series) @series = new_series self end |
#corresponding?(other) ⇒ Boolean
50 51 52 |
# File 'lib/quant/ticks/value.rb', line 50 def corresponding?(other) == other. end |
#inspect ⇒ Object
75 76 77 |
# File 'lib/quant/ticks/value.rb', line 75 def inspect "#<#{self.class.name} iv=#{interval} ct=#{.strftime("%Y-%m-%d")} o=#{open_price} c=#{close_price} v=#{volume}>" end |
#to_h ⇒ Object
79 80 81 |
# File 'lib/quant/ticks/value.rb', line 79 def to_h Quant::Ticks::Serializers::Value.to_h(self) end |
#to_json(*_args) ⇒ Object
83 84 85 |
# File 'lib/quant/ticks/value.rb', line 83 def to_json(*_args) Quant::Ticks::Serializers::Value.to_json(self) end |