Class: Quant::Indicators::Frama

Inherits:
Indicator show all
Defined in:
lib/quant/indicators/frama.rb

Overview

FRAMA (FRactal Adaptive Moving Average). A nonlinear moving average is derived using the Hurst exponent. It rapidly follows significant changes in price but becomes very flat in congestion zones so that bad whipsaw trades can be eliminated.

SOURCE: www.mesasoftware.com/papers/FRAMA.pdf

Constant Summary

Constants included from Mixins::UniversalFilters

Mixins::UniversalFilters::K

Instance Attribute Summary

Attributes inherited from Indicator

#p0, #p1, #p2, #p3, #series, #source, #t0, #t1, #t2, #t3

Instance Method Summary collapse

Methods inherited from Indicator

#<<, #[], #dc_period, #dominant_cycle, #dominant_cycle_kind, #each, #indicator_name, #initialize, #input, #inspect, #micro_period, #min_period, #p, #period_points, #pivot_kind, #points_class, #size, #t, #ticks, #values

Methods included from Mixins::FisherTransform

#fisher_transform, #inverse_fisher_transform, #relative_fisher_transform

Methods included from Mixins::Stochastic

#stochastic

Methods included from Mixins::SuperSmoother

#three_pole_super_smooth, #two_pole_super_smooth

Methods included from Mixins::HilbertTransform

#hilbert_transform

Methods included from Mixins::ExponentialMovingAverage

#exponential_moving_average

Methods included from Mixins::SimpleMovingAverage

#simple_moving_average

Methods included from Mixins::WeightedMovingAverage

#extended_weighted_moving_average, #weighted_moving_average

Methods included from Mixins::UniversalFilters

#universal_band_pass, #universal_ema, #universal_filter, #universal_one_pole_high_pass, #universal_one_pole_low_pass, #universal_two_pole_high_pass, #universal_two_pole_low_pass

Methods included from Mixins::ButterworthFilters

#three_pole_butterworth, #two_pole_butterworth

Methods included from Mixins::HighPassFilters

#high_pass_filter, #hpf2, #two_pole_high_pass_filter

Methods included from Mixins::Functions

#angle, #bars_to_alpha, #deg2rad, #period_to_alpha, #rad2deg

Constructor Details

This class inherits a constructor from Quant::Indicators::Indicator

Instance Method Details

#computeObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/quant/indicators/frama.rb', line 35

def compute
  pp = period_points(max_period).map(&:input)
  return if pp.size < max_period

  n3 = (pp.maximum - pp.minimum) / max_period

  ppn2 = pp.first(half_period)
  n2 = (ppn2.maximum - ppn2.minimum) / half_period

  ppn1 = pp.last(half_period)
  n1 = (ppn1.maximum - ppn1.minimum) / half_period

  dimension = (Math.log(n1 + n2) - Math.log(n3)) / Math.log(2)
  alpha = Math.exp(-4.6 * (dimension - 1.0)).clamp(0.01, 1.0)
  p0.frama = (alpha * p0.input) + ((1 - alpha) * p1.frama)
end

#half_periodObject

def max_period

mp = dc_period
mp.even? ? mp : mp + 1

end



31
32
33
# File 'lib/quant/indicators/frama.rb', line 31

def half_period
  max_period / 2
end

#max_periodObject

The max_period is divided into two smaller, equal periods, so must be even



19
20
21
22
23
24
# File 'lib/quant/indicators/frama.rb', line 19

def max_period
  @max_period ||= begin
    mp = super
    mp.even? ? mp : mp + 1
  end
end