Module: Quant::Mixins::SuperSmoother
- Included in:
- Indicators::Indicator
- Defined in:
- lib/quant/mixins/super_smoother.rb
Overview
Super Smoother Filters provide a way to smooth out the noise in a series without out introducing undesirable lag that you would other get with traditional moving averages.
The EMA only reduces the amplitude at the Nyquist frequency by 13 dB. On the other hand, the SuperSmoother filter theoretically completely eliminates components at the Nyquist Frequency. The added benefit is that the SuperSmoother filter has significantly less lag than the EMA.
Instance Method Summary collapse
- #three_pole_super_smooth(source, period:, previous:) ⇒ Object (also: #ss3p)
- #two_pole_super_smooth(source, period:, previous:) ⇒ Object (also: #super_smoother, #ss2p)
Instance Method Details
#three_pole_super_smooth(source, period:, previous:) ⇒ Object Also known as: ss3p
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/quant/mixins/super_smoother.rb', line 35 def three_pole_super_smooth(source, period:, previous:) raise ArgumentError, "source must be a Symbol" unless source.is_a?(Symbol) radians = Math::PI / period a1 = Math.exp(-radians) b1 = 2 * a1 * Math.cos(Math.sqrt(3) * radians) c1 = a1**2 c4 = c1**2 c3 = -(c1 + b1 * c1) c2 = b1 + c1 c1 = 1 - c2 - c3 - c4 v0 = p0.send(source) v1 = p1.send(previous) v2 = p2.send(previous) v3 = p3.send(previous) (c1 * v0) + (c2 * v1) + (c3 * v2) + (c4 * v3) end |
#two_pole_super_smooth(source, period:, previous:) ⇒ Object Also known as: super_smoother, ss2p
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/quant/mixins/super_smoother.rb', line 15 def two_pole_super_smooth(source, period:, previous:) raise ArgumentError, "source must be a Symbol" unless source.is_a?(Symbol) radians = Math.sqrt(2) * Math::PI / period a1 = Math.exp(-radians) c3 = -a1**2 c2 = 2.0 * a1 * Math.cos(radians) c1 = 1.0 - c2 - c3 v1 = (p0.send(source) + p1.send(source)) * 0.5 v2 = p2.send(previous) v3 = p3.send(previous) (c1 * v1) + (c2 * v2) + (c3 * v3) end |