Module: Quant::Mixins::Stochastic
- Defined in:
- lib/quant/mixins/stochastic.rb
Instance Method Summary collapse
Instance Method Details
#stochastic(source, period = max_period) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/quant/mixins/stochastic.rb', line 6 def stochastic(source, period = max_period) stoch_period = [points.size, period.to_i].min return 0.0 if stoch_period < 1 subset = points[-stoch_period, stoch_period].map{ |p| p.send(source) } ll = subset.min hh = subset.max v0 = points[-1].send(source) (hh - ll).zero? ? 0.0 : 100.0 * (v0 - ll) / (hh - ll) end |