A gem for calculating technical analysis indicators.
Current functionality demo of Indicators and Securities gems synergy can be tested at http://strangemuseum.heroku.com. Securities gem: https://rubygems.org/gems/securities
Add this line to your application's Gemfile:
gem 'indicators'
And then execute:
$ bundle
Or install it yourself as:
$ gem install indicators
my_data = Indicators::Data.new([1, 2, 3, 4, 5])
Then it returns data as an array with indicator values in index places:
i.e. my_data.calc(:type => :sma, :params => 2).output => [nil, 1.5, 2.5, 3.5, 4.5]
my_data = Indicators::Data.new(Securities::Stock.new(:symbol => 'AAPL', :start_date => '2012-08-25', :end_date => '2012-08-30').output)
my_data.calc(:type => :sma, :params => 3)
.calc returns an object with such accessor methods
@abbr - indicator abbreviation (usually used when displaying information).
@params - given or defaulted parameters.
@output - indicator calculation result.
i.e. @abbr="SMA", @params=2, @output=[nil, 1.5, 2.5, 3.5, 4.5]
my_data.calc(:type => :sma, :params => 5)
my_data.calc(:type => :ema, :params => 5)
my_data.calc(:type => :bb, :params => [15, 3]) or my_data.calc(:type => :bb, :params => [15, 2.5])
Variables have to be specified as an array [periods, multiplier]. If multiplier isn't specified, it defaults to 2.
It returns output as an array for each data point [middle band, upper band, lower band].
i.e. my_data.calc(:type => :bb, :params => 3) => {"aapl"=>[nil, nil, [674.65, 676.8752190903368, 672.4247809096631]]}
my_data.calc(:type => :macd, :params => [12, 26, 9])
Variables have to be specified as an array [faster periods, slower periods, signal line]. If slower periods isn't specified, it defaults to 26 and signal line to 9.
MACD output is [MACD line, signal line, MACD histogram].
my_data.calc(:type => :rsi, :params => 14)
The more data it has, the more accurate RSI is.
my_data.calc(:type => :sto, :params => [14, 3, 5])
Variables have to be specified as an array [lookback period, the number of periods to slow %K, the number of periods for the %D moving average] => [%K1, %K2, %D].
Stochastic output is [fast %K, slow %K, full %D].
- A strategy backtesting tool.
- More moving averages (CMA, WMA, MMA).
- ROC.
- CCI.
- Williams %R.
- ADX.
- Parabolic SAR.
- StochRSI.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request