Class: Ema

Inherits:
Object
  • Object
show all
Defined in:
lib/rbma/ema.rb

Direct Known Subclasses

NDayEma

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a:) ⇒ Ema

Returns a new instance of Ema.



7
8
9
# File 'lib/rbma/ema.rb', line 7

def initialize(a:)
  @a = a
end

Instance Attribute Details

#aObject (readonly)

S_t = alpha*Y_t+(1-alpha)*S_(t-1)



3
4
5
# File 'lib/rbma/ema.rb', line 3

def a
  @a
end

#lastObject (readonly)

Returns the value of attribute last.



5
6
7
# File 'lib/rbma/ema.rb', line 5

def last
  @last
end

Instance Method Details

#compute(current:, previous: nil) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/rbma/ema.rb', line 11

def compute(current:, previous: nil)
  if previous
    @last = @a*current+(1-@a)*previous
  elsif @last
    @last = @a*current+(1-@a)*@last
  else
    @last = current
  end
end

#to_sObject



21
22
23
# File 'lib/rbma/ema.rb', line 21

def to_s
  "#{@last}"
end