Module: Quant::Mixins::Functions
- Included in:
- Indicators::Indicator
- Defined in:
- lib/quant/mixins/functions.rb
Instance Method Summary collapse
-
#angle(line1, line2) ⇒ Object
d = dx1*dx2 + dy1*dy2; // dot product of the 2 vectors l2 = (dx1*dx1+dy1*dy1)*(dx2*dx2+dy2*dy2) // product of the squared lengths.
-
#bars_to_alpha(bars) ⇒ Object
3 bars = 0.5 4 bars = 0.4 5 bars = 0.333 6 bars = 0.285 10 bars = 0.182 20 bars = 0.0952 40 bars = 0.0488 50 bars = 0.0392.
- #deg2rad(degrees) ⇒ Object
-
#period_to_alpha(period, k: 1.0) ⇒ Object
α = Cos(K*360/Period)+Sin(K*360/Period)−1 / Cos(K*360/Period) k = 1.0 for single-pole filters k = 0.707 for two-pole high-pass filters k = 1.414 for two-pole low-pass filters.
- #rad2deg(radians) ⇒ Object
Instance Method Details
#angle(line1, line2) ⇒ Object
d = dx1*dx2 + dy1*dy2; // dot product of the 2 vectors l2 = (dx1*dx1+dy1*dy1)*(dx2*dx2+dy2*dy2) // product of the squared lengths
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/quant/mixins/functions.rb', line 44 def angle(line1, line2) dx1 = line2[0][0] - line1[0][0] dy1 = line2[0][1] - line1[0][1] dx2 = line2[1][0] - line1[1][0] dy2 = line2[1][1] - line1[1][1] d = dx1 * dx2 + dy1 * dy2 l2 = ((dx1**2 + dy1**2) * (dx2**2 + dy2**2)) radians = d.to_f / Math.sqrt(l2) value = rad2deg Math.acos(radians) value.nan? ? 0.0 : value end |
#bars_to_alpha(bars) ⇒ Object
3 bars = 0.5 4 bars = 0.4 5 bars = 0.333 6 bars = 0.285 10 bars = 0.182 20 bars = 0.0952 40 bars = 0.0488 50 bars = 0.0392
25 26 27 |
# File 'lib/quant/mixins/functions.rb', line 25 def () 2.0 / ( + 1) end |
#deg2rad(degrees) ⇒ Object
29 30 31 |
# File 'lib/quant/mixins/functions.rb', line 29 def deg2rad(degrees) degrees * Math::PI / 180.0 end |
#period_to_alpha(period, k: 1.0) ⇒ Object
α = Cos(K*360/Period)+Sin(K*360/Period)−1 / Cos(K*360/Period) k = 1.0 for single-pole filters k = 0.707 for two-pole high-pass filters k = 1.414 for two-pole low-pass filters
10 11 12 13 14 15 |
# File 'lib/quant/mixins/functions.rb', line 10 def period_to_alpha(period, k: 1.0) radians = deg2rad(k * 360 / period.to_f) cos = Math.cos(radians) sin = Math.sin(radians) (cos + sin - 1) / cos end |
#rad2deg(radians) ⇒ Object
33 34 35 |
# File 'lib/quant/mixins/functions.rb', line 33 def rad2deg(radians) radians * 180.0 / Math::PI end |