Sha256: fe4a71c4feed0d70cdbe47bccbc95b331f4966d0c95a12bbc536a40a06bfb898
Contents?: true
Size: 942 Bytes
Versions: 1
Compression:
Stored size: 942 Bytes
Contents
module SignalTools module Technicals module TrueRange # Takes historical data and computes the true ranges. def true_ranges(stock_data) trs = [stock_data.high_prices.first - stock_data.low_prices.first] index = 1 while index < (stock_data.high_prices.size) trs << true_range(stock_data.raw_data[index], stock_data.raw_data[index-1]) index += 1 end trs end # Takes today's data and yesterday's data and computes the true range. def true_range(today, yesterday) [ today[SignalTools::StockData::Indexes[:high]] - today[SignalTools::StockData::Indexes[:low]], (yesterday[SignalTools::StockData::Indexes[:close]] - today[SignalTools::StockData::Indexes[:high]]).abs, (yesterday[SignalTools::StockData::Indexes[:close]] - today[SignalTools::StockData::Indexes[:low]]).abs ].max end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
signal_tools-0.3.1 | lib/signal_tools/technicals/true_range.rb |