Class: IEma
- Inherits:
-
Object
- Object
- IEma
- Defined in:
- lib/rbma/i_ema.rb
Instance Attribute Summary collapse
-
#g ⇒ Object
readonly
Returns the value of attribute g.
-
#prev ⇒ Object
readonly
where G is the smoothing coeficient, a the rate decay Y_t, an event value at time t Y_n, an event value at the time of event n S_t, the EMA value at time t S_n, the EMA value at the time of the event n t(n), the time of the event n.
-
#tprev ⇒ Object
readonly
Returns the value of attribute tprev.
Instance Method Summary collapse
- #compute(current:, t:, prev: nil, tprev: nil) ⇒ Object
-
#initialize(g:) ⇒ IEma
constructor
A new instance of IEma.
- #value(t:, tprev: nil, prev: nil) ⇒ Object
Constructor Details
#initialize(g:) ⇒ IEma
Returns a new instance of IEma.
19 20 21 |
# File 'lib/rbma/i_ema.rb', line 19 def initialize(g:) @g = g.to_f end |
Instance Attribute Details
#g ⇒ Object (readonly)
Returns the value of attribute g.
16 17 18 |
# File 'lib/rbma/i_ema.rb', line 16 def g @g end |
#prev ⇒ Object (readonly)
where G is the smoothing coeficient, a the rate decay Y_t, an event value at time t Y_n, an event value at the time of event n S_t, the EMA value at time t S_n, the EMA value at the time of the event n t(n), the time of the event n
15 16 17 |
# File 'lib/rbma/i_ema.rb', line 15 def prev @prev end |
#tprev ⇒ Object (readonly)
Returns the value of attribute tprev.
17 18 19 |
# File 'lib/rbma/i_ema.rb', line 17 def tprev @tprev end |
Instance Method Details
#compute(current:, t:, prev: nil, tprev: nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rbma/i_ema.rb', line 23 def compute(current:, t:, prev: nil, tprev: nil) if tprev && prev alpha = a(t - tprev) elsif @tprev && @prev alpha = a(t - @tprev) prev = @prev else alpha = 0 prev = 0 end @tprev = t @prev = (1-alpha)*current + alpha*prev end |
#value(t:, tprev: nil, prev: nil) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rbma/i_ema.rb', line 37 def value(t:, tprev: nil, prev: nil) # 3) S_t = S_t(n)*exp((t-t(n))/G) if tprev && prev elsif @tprev && @prev tprev = @tprev prev = @prev else raise ArgumentError.new("There is no previous data and you did not provide any") end prev*a(t - tprev) end |