Module: StockCruncher::Stats
Overview
this is a module with various statistic calculation methods
Constant Summary collapse
- RANGES =
[5, 10, 20, 30, 50, 100, 200].freeze
Instance Method Summary collapse
-
#list_ema(values) ⇒ Object
Calculate multiple range of exponential moving average.
-
#list_lwma(values) ⇒ Object
Calculate multiple range of linearly weighted moving average.
-
#list_sma(values) ⇒ Object
Calculate multiple range of simple moving average.
-
#list_vwma(values, volumes) ⇒ Object
Calculate multiple range of volume weighted moving average.
Instance Method Details
#list_ema(values) ⇒ Object
Calculate multiple range of exponential moving average
12 13 14 15 16 17 18 19 20 |
# File 'lib/stockcruncher/stats.rb', line 12 def list_ema(values) h = {} RANGES.each do |n| next if values.size < n + 1 h["ema#{n}"] = ema(values[0, n + 1]) end h end |
#list_lwma(values) ⇒ Object
Calculate multiple range of linearly weighted moving average
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/stockcruncher/stats.rb', line 23 def list_lwma(values) h = {} RANGES.each do |n| next if values.size < n weights = (1..n).to_a.reverse h["lwma#{n}"] = sma(values[0, n], weights) end h end |
#list_sma(values) ⇒ Object
Calculate multiple range of simple moving average
35 36 37 38 39 40 41 42 43 |
# File 'lib/stockcruncher/stats.rb', line 35 def list_sma(values) h = {} RANGES.each do |n| next if values.size < n h["sma#{n}"] = sma(values[0, n]) end h end |
#list_vwma(values, volumes) ⇒ Object
Calculate multiple range of volume weighted moving average
46 47 48 49 50 51 52 53 54 |
# File 'lib/stockcruncher/stats.rb', line 46 def list_vwma(values, volumes) h = {} RANGES.each do |n| next if values.size < n h["vwma#{n}"] = sma(values[0, n], volumes[0, n]) end h end |