module SignalTools::Technicals::Stochastic

Attributes

d_period[R]
k_period[R]
stock_data[R]

Public Instance Methods

calculate_d_points(k_points, period) click to toggle source
# File lib/signal_tools/technicals/stochastic.rb, line 8
def calculate_d_points(k_points, period)
  collection_for_array(k_points, period, :average)
end
calculate_fast_stochastic_k_points() click to toggle source
# File lib/signal_tools/technicals/stochastic.rb, line 24
def calculate_fast_stochastic_k_points
  index = 0
  points = []
  while((index + k_period) <= stock_data.close_prices.size)
    today_cp = stock_data.close_prices[index + k_period - 1]
    low_price = get_for_period(stock_data.low_prices, index, index + k_period - 1, :min)
    high_price = get_for_period(stock_data.high_prices, index, index + k_period - 1, :max)
    points << (today_cp - low_price) / (high_price - low_price)
    index += 1
  end
  points
end
fast_stochastic_points() click to toggle source
# File lib/signal_tools/technicals/stochastic.rb, line 18
def fast_stochastic_points
  k_points = calculate_fast_stochastic_k_points
  d_points = calculate_d_points(k_points, d_period)
  k_d_points(k_points, d_points)
end
k_d_points(k_points, d_points) click to toggle source
# File lib/signal_tools/technicals/stochastic.rb, line 12
def k_d_points(k_points, d_points)
  raise unless k_points.size > d_points.size
  SignalTools.truncate_to_shortest!(k_points, d_points)
  {:k => k_points, :d => d_points}
end