Class: Quant::Indicators::Frama
- 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.
Constant Summary
Constants inherited from Indicator
Constants included from Mixins::UniversalFilters
Instance Attribute Summary
Attributes inherited from Indicator
#p0, #p1, #p2, #p3, #series, #source, #t0, #t1, #t2, #t3
Instance Method Summary collapse
- #compute ⇒ Object
- #half_period ⇒ Object
-
#max_period ⇒ Object
The max_period is divided into two smaller, equal periods, so must be even.
Methods inherited from Indicator
#<<, #[], #adaptive_half_period, #adaptive_period, dependent_indicator_classes, depends_on, #dominant_cycle, #dominant_cycle_indicator_class, #dominant_cycle_kind, #each, #indicator_name, #initialize, #input, #inspect, #micro_period, #min_period, #p, #period_points, #pivot_kind, #points_class, #priority, register, #size, #t, #ticks, #values, #warmed_up?
Methods included from Mixins::FisherTransform
#fisher_transform, #inverse_fisher_transform, #relative_fisher_transform
Methods included from Mixins::Stochastic
Methods included from Mixins::SuperSmoother
#three_pole_super_smooth, #two_pole_super_smooth
Methods included from Mixins::HilbertTransform
Methods included from Mixins::ExponentialMovingAverage
Methods included from Mixins::SimpleMovingAverage
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
#compute ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/quant/indicators/frama.rb', line 33 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 p0.dimension = (Math.log(n1 + n2) - Math.log(n3)) / Math.log(2) p0.alpha = Math.exp(-4.6 * (p0.dimension - 1.0)).clamp(0.01, 1.0) p0.frama = (p0.alpha * p0.input) + ((1 - p0.alpha) * p1.frama) end |
#half_period ⇒ Object
29 30 31 |
# File 'lib/quant/indicators/frama.rb', line 29 def half_period max_period / 2 end |
#max_period ⇒ Object
The max_period is divided into two smaller, equal periods, so must be even
22 23 24 25 26 27 |
# File 'lib/quant/indicators/frama.rb', line 22 def max_period @max_period ||= begin mp = super mp.even? ? mp : mp + 1 end end |