ta-indicator 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/README.rdoc +200 -196
  2. data/examples/mapping.rb +15 -0
  3. data/lib/indicator/auto_gen.rb +158 -158
  4. data/lib/indicator/auto_gen/ad.rb +2 -2
  5. data/lib/indicator/auto_gen/ad_osc.rb +2 -2
  6. data/lib/indicator/auto_gen/adx.rb +2 -2
  7. data/lib/indicator/auto_gen/adxr.rb +2 -2
  8. data/lib/indicator/auto_gen/aroon.rb +2 -2
  9. data/lib/indicator/auto_gen/aroon_osc.rb +2 -2
  10. data/lib/indicator/auto_gen/atr.rb +2 -2
  11. data/lib/indicator/auto_gen/avg_price.rb +1 -1
  12. data/lib/indicator/auto_gen/bop.rb +1 -1
  13. data/lib/indicator/auto_gen/cci.rb +2 -2
  14. data/lib/indicator/auto_gen/cdl2_crows.rb +1 -1
  15. data/lib/indicator/auto_gen/cdl3_black_crows.rb +1 -1
  16. data/lib/indicator/auto_gen/cdl3_inside.rb +1 -1
  17. data/lib/indicator/auto_gen/cdl3_line_strike.rb +1 -1
  18. data/lib/indicator/auto_gen/cdl3_outside.rb +1 -1
  19. data/lib/indicator/auto_gen/cdl3_stars_in_south.rb +1 -1
  20. data/lib/indicator/auto_gen/cdl3_white_soldiers.rb +1 -1
  21. data/lib/indicator/auto_gen/cdl_abandoned_baby.rb +1 -1
  22. data/lib/indicator/auto_gen/cdl_advance_block.rb +1 -1
  23. data/lib/indicator/auto_gen/cdl_belt_hold.rb +1 -1
  24. data/lib/indicator/auto_gen/cdl_breakaway.rb +1 -1
  25. data/lib/indicator/auto_gen/cdl_closing_marubozu.rb +1 -1
  26. data/lib/indicator/auto_gen/cdl_conceal_babys_wall.rb +1 -1
  27. data/lib/indicator/auto_gen/cdl_counter_attack.rb +1 -1
  28. data/lib/indicator/auto_gen/cdl_dark_cloud_cover.rb +1 -1
  29. data/lib/indicator/auto_gen/cdl_doji.rb +1 -1
  30. data/lib/indicator/auto_gen/cdl_doji_star.rb +1 -1
  31. data/lib/indicator/auto_gen/cdl_dragonfly_doji.rb +1 -1
  32. data/lib/indicator/auto_gen/cdl_engulfing.rb +1 -1
  33. data/lib/indicator/auto_gen/cdl_evening_doji_star.rb +1 -1
  34. data/lib/indicator/auto_gen/cdl_evening_star.rb +1 -1
  35. data/lib/indicator/auto_gen/cdl_gap_side_side_white.rb +1 -1
  36. data/lib/indicator/auto_gen/cdl_gravestone_doji.rb +1 -1
  37. data/lib/indicator/auto_gen/cdl_hammer.rb +1 -1
  38. data/lib/indicator/auto_gen/cdl_hanging_man.rb +1 -1
  39. data/lib/indicator/auto_gen/cdl_harami.rb +1 -1
  40. data/lib/indicator/auto_gen/cdl_harami_cross.rb +1 -1
  41. data/lib/indicator/auto_gen/cdl_hign_wave.rb +1 -1
  42. data/lib/indicator/auto_gen/cdl_hikkake.rb +1 -1
  43. data/lib/indicator/auto_gen/cdl_hikkake_mod.rb +1 -1
  44. data/lib/indicator/auto_gen/cdl_homing_pigeon.rb +1 -1
  45. data/lib/indicator/auto_gen/cdl_identical3_crows.rb +1 -1
  46. data/lib/indicator/auto_gen/cdl_in_neck.rb +1 -1
  47. data/lib/indicator/auto_gen/cdl_inverted_hammer.rb +1 -1
  48. data/lib/indicator/auto_gen/cdl_kicking.rb +1 -1
  49. data/lib/indicator/auto_gen/cdl_kicking_by_length.rb +1 -1
  50. data/lib/indicator/auto_gen/cdl_ladder_bottom.rb +1 -1
  51. data/lib/indicator/auto_gen/cdl_long_legged_doji.rb +1 -1
  52. data/lib/indicator/auto_gen/cdl_long_line.rb +1 -1
  53. data/lib/indicator/auto_gen/cdl_marubozu.rb +1 -1
  54. data/lib/indicator/auto_gen/cdl_mat_hold.rb +1 -1
  55. data/lib/indicator/auto_gen/cdl_matching_low.rb +1 -1
  56. data/lib/indicator/auto_gen/cdl_morning_doji_star.rb +1 -1
  57. data/lib/indicator/auto_gen/cdl_morning_star.rb +1 -1
  58. data/lib/indicator/auto_gen/cdl_on_neck.rb +1 -1
  59. data/lib/indicator/auto_gen/cdl_piercing.rb +1 -1
  60. data/lib/indicator/auto_gen/cdl_rickshaw_man.rb +1 -1
  61. data/lib/indicator/auto_gen/cdl_rise_fall3_methods.rb +1 -1
  62. data/lib/indicator/auto_gen/cdl_seperating_lines.rb +1 -1
  63. data/lib/indicator/auto_gen/cdl_shooting_star.rb +1 -1
  64. data/lib/indicator/auto_gen/cdl_short_line.rb +1 -1
  65. data/lib/indicator/auto_gen/cdl_spinning_top.rb +1 -1
  66. data/lib/indicator/auto_gen/cdl_stalled_pattern.rb +1 -1
  67. data/lib/indicator/auto_gen/cdl_stick_sandwhich.rb +1 -1
  68. data/lib/indicator/auto_gen/cdl_takuri.rb +1 -1
  69. data/lib/indicator/auto_gen/cdl_tasuki_gap.rb +1 -1
  70. data/lib/indicator/auto_gen/cdl_thrusting.rb +1 -1
  71. data/lib/indicator/auto_gen/cdl_tristar.rb +1 -1
  72. data/lib/indicator/auto_gen/cdl_unique3_river.rb +1 -1
  73. data/lib/indicator/auto_gen/cdl_upside_gap2_crows.rb +1 -1
  74. data/lib/indicator/auto_gen/cdl_x_side_gap3_methods.rb +1 -1
  75. data/lib/indicator/auto_gen/dx.rb +2 -2
  76. data/lib/indicator/auto_gen/med_price.rb +2 -2
  77. data/lib/indicator/auto_gen/mfi.rb +2 -2
  78. data/lib/indicator/auto_gen/mid_price.rb +2 -2
  79. data/lib/indicator/auto_gen/minus_di.rb +2 -2
  80. data/lib/indicator/auto_gen/minus_dm.rb +2 -2
  81. data/lib/indicator/auto_gen/natr.rb +2 -2
  82. data/lib/indicator/auto_gen/obv.rb +6 -5
  83. data/lib/indicator/auto_gen/plus_di.rb +2 -2
  84. data/lib/indicator/auto_gen/plus_dm.rb +2 -2
  85. data/lib/indicator/auto_gen/sar.rb +2 -2
  86. data/lib/indicator/auto_gen/sar_ext.rb +2 -2
  87. data/lib/indicator/auto_gen/stoch.rb +2 -2
  88. data/lib/indicator/auto_gen/stoch_f.rb +2 -2
  89. data/lib/indicator/auto_gen/true_range.rb +2 -2
  90. data/lib/indicator/auto_gen/typ_price.rb +2 -2
  91. data/lib/indicator/auto_gen/ult_osc.rb +2 -2
  92. data/lib/indicator/auto_gen/wcl_price.rb +2 -2
  93. data/lib/indicator/auto_gen/will_r.rb +2 -2
  94. data/lib/indicator/base.rb +18 -0
  95. data/lib/indicator/data_mapper.rb +0 -20
  96. data/lib/indicator/version.rb +1 -1
  97. metadata +4 -4
@@ -1,196 +1,200 @@
1
- = Technical Analysis Indicator Library
2
-
3
- == Overview
4
-
5
- Provides a wrapper around the talib-ruby[https://github.com/rivella50/talib-ruby] library which is a ruby wrapper for the ta-lib[http://ta-lib.org/] library.
6
-
7
- This library has been designed to make interfacing with the ta-lib functions easy by wrapping each function in a ruby class.
8
-
9
- The wrappers are autogenerated from the xml function description provided with the ta-lib project.
10
-
11
- == Usage
12
-
13
- Requires the talib-ruby gem. The examples require the yahoofinance gem.
14
-
15
- === Simple Example
16
- The easiest way to use the indicator library is to include the indicator mixin module. This module extends the Array class with the Indicator::Mixin module allowing quick calculations to be performed:
17
-
18
- require 'indicator/mixin'
19
-
20
- data = [1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3]
21
- results = data.indicator(:sma, :time_period => 5)
22
- results = data.indicator(:sma, 5)
23
- results = data.indicator(:sma_5)
24
-
25
- All perform a simple moving average with time period of 5 and produce the same results:
26
-
27
- => [nil, nil, nil, nil, 2.2, 2.4, 2.6, 2.4, 2.6, 2.4, 2.6]
28
-
29
- More complex indicators can also be used
30
-
31
- result = data.indicator(:macd_12_26_9)
32
-
33
- This performs a macd calculation using a slow period of 12, fast period of 26 and signal period of 9.
34
-
35
- The list of available indicators can be retrieved via
36
-
37
- Indicator.list
38
-
39
- Information about each indicator including a list of arguments can be retrieved via:
40
-
41
- Indicator.info :sma
42
- Inficator.info :macd
43
- ...
44
-
45
- == Details
46
- The base Indicator functions are located in the Indicator module and the auto generated classed are located in the Indicator::AutoGen module. All of the following examples assume these modules have been included:
47
-
48
- require 'indicator'
49
- include Indicator
50
- include Indicator::AutoGen
51
-
52
- === Class Construction
53
-
54
- All ta-lib functions are wrapped in a class named using the camel class name of the function: SMA is Sma, AVGPRICE is AvgPrice, etc. The constructor takes the optional arguments either as a hash or argument list. For example the Macd class takes three arguments, fast_period, slow_period and signal_period. They can be initialised in any of the following ways:
55
-
56
- sma = Sma.new 5
57
- macd = Macd.new 12,26,9
58
- or
59
- sma = Sma.new :time_period => 5
60
- macd = Macd.new :fast_period => 12, :slow_period => 26, :signal_period => 9
61
-
62
- If a parameter is not passed in then it will be initialised to the default value as specified by the ta-lib interface.
63
-
64
- The Indicator module also supports factory style functions to simplify class creation.
65
-
66
- sma = Indicator.create :sma
67
- sma = Indicator.create :sma, 5
68
- sma = Indicator.create :sma, time_period => 5
69
-
70
- macd = Indicator.create :macd
71
- macd = Indicator.create :macd, 12,26,9
72
- macd = Indicator.create :macd, :fast_period => 12, :slow_period => 26, :signal_period => 9
73
-
74
- If a indicator is to be constructed using only integer parameters then an indicator can be constructed using the create_named factory function. The create_named function expects the indicator name optionally followed by it's arguments joined by an underscore.
75
-
76
- sma = Indicator.create_named :sma_5
77
- macd = Indicator.create_named :sma_12_26_9
78
-
79
- === Argument attributes
80
-
81
- All arguments can be updated through attributes:
82
- macd.fast_period
83
- => 12
84
- macd.slow_period = 30
85
- => 30
86
-
87
- A list of all the arguments that a particular class takes can be be retrieved using the class method 'arguments'.
88
- Macd.arguments
89
- => [:fast_period, :slow_period, :signal_period]
90
- Sma.arguments
91
- => [:time_period]
92
-
93
- === Running The Indicators
94
- Each indicator defines a run method that takes in each input array to be processed as a List. An example of an indicator that takes one input:
95
- sma = Indicator.create_named :sma_5
96
- sma.run [1,2,3,4,3,2,3,2,3,2,3,2]
97
- => [nil, nil, nil, nil, 2.6, 2.8, 3.0, 2.8, 2.6, 2.4, 2.6, 2.4]
98
-
99
- An example of an indicator that takes two inputs:
100
- add = Indicator.create_named :add
101
- add.run [1,2,3,4,5], [5,4,3,2,1]
102
- => [6.0, 6.0, 6.0, 6.0, 6.0]
103
-
104
- Some indicators require OHLC (and optionally V) price inputs. An example of an indicator that takes price inputs:
105
- avg = AvgPrice.new
106
- # AvgPrice run function takes open, high, low, close
107
- avg.run [1,2,1,2], [2,1,2,1], [3,1,3,1], [1,3,1,3]
108
- => [1.75, 1.75, 1.75, 1.75]
109
-
110
- A list of inputs that a indicator run function requires can be retrieved using the class method 'inputs'.
111
- Sma.inputs
112
- => [:in_real]
113
- Add.inputs
114
- => [:in_real0, in_real1]
115
- AvgPrice.inputs
116
- => [:open, :high, :low, :close]
117
- AdOsc.inputs
118
- => [:open, :high, :low, :close, :volume]
119
-
120
- === Outputs
121
- The run function returns an array containing the results if there is only one List to return otherwise it returns a hash that maps each output List to it's name. For eample:
122
- sma = Sma.new(5)
123
- sma.run [1,2,3,4,3,2,3,2,3,2,3,2]
124
- => [nil, nil, nil, nil, 2.6, 2.8, 3.0, 2.8, 2.6, 2.4, 2.6, 2.4]
125
- macd = Macd.new 3,4,1
126
- result = macd.run [1,2,3,4,4,3]
127
- puts results[:out_macd]
128
- => [nil, nil, -3.785768566076978e-270, 0.5, nil, nil]
129
- puts result[:out_macd_signal]
130
- => [nil, nil, 0.399999999999999, 0.189999999999999, nil, nil],
131
- puts result[:out_macd_hist]
132
- => [nil, nil, -0.3999999999999999, 0.31000000000000005, nil, nil]
133
-
134
- A list of outputs that an indicator run function returns can be retrieved using the class method 'outputs'.
135
- Sma.outputs
136
- => [:out_real]
137
- Macd.outputs
138
- => [:out_macd, :out_macd_signal, :out_macd_hist]
139
-
140
- === Data Mapping
141
- The run function also accepts a DataMapping::Map structure which can be used to extract data from an enumerable collection.
142
-
143
- # Assume historical_data is a list of hashes with the following keys
144
- # :open, :high, :low, :close, :volume
145
- sma = Sma.new 5
146
- sma_results = sma.run(DataMapper::Map.new(historical_data, :open))
147
-
148
- When the above example is run the DataMapper will attempt to extract data from the historical_data collection by either calling a function called open or retrieving a hash value using the key :open. You can also directly pass in a lambda function if a more complex mapping function is required.
149
- To reduce the amount of code required a helper function called new_map is available:
150
-
151
- sma = Sma.new 5
152
- sma_results = sma.run new_map(historical_data, :open)
153
- sma_results = sma.run new_map(historical_data, lambda => |b| { b[:open] / 2 })
154
-
155
- By default the run function will attempt to use a default getter of :open, so the following is also valid:
156
-
157
- sma = Sma.new 5
158
- sma_results = sma.run historical_data
159
- # Calculates the sma by accessing [:open] on each element of historical_data
160
-
161
- The default getter can be changed:
162
- sma = Sma.new 5
163
- sma.default_getter :high
164
- sma_results = sma.run historical_data
165
- # Calculates the sma by accessing [:high] on each element of historical_data
166
-
167
- The same mapping system works for functions requiring price data as an input. The AvgPrice function can be called using either of the following syntax:
168
-
169
- ap = AvgPrice.new
170
- ap.run(
171
- new_map(historical_data, :open),
172
- new_map(historical_data, :high),
173
- new_map(historical_data, :low),
174
- new_map(historical_data, :close))
175
-
176
- or
177
-
178
- ap = AvgPrice.new
179
- ap.run historical_data
180
-
181
- The run function will again attempt to use sensible default mappings of :open, :high, :low, :close and :volume (if required).
182
-
183
- == Regenerating the wrappers
184
-
185
- The wrappers can be regenerated using the gen_wrapper.rb file in the tools directory:
186
-
187
- ruby gen_wrapper.rb
188
-
189
- This script must be run from the tools directory as it uses realtive paths.
190
- The gen_wrapper.rb script uses the erb library to generate code from the defined templates.
191
-
192
- == Copyright
193
-
194
- Copyright (c) 2012 Michael Lamb. See LICENSE for details.
195
-
196
- The files ta_func_api.xml and ta_func_api.xsd are from the talib library. The license details are contained within LICENSE-ta-lib.
1
+ = Technical Analysis Indicator Library
2
+
3
+ == Overview
4
+
5
+ Provides a wrapper around the talib-ruby[https://github.com/rivella50/talib-ruby] library which is a ruby wrapper for the ta-lib[http://ta-lib.org/] library.
6
+
7
+ This library has been designed to make interfacing with the ta-lib functions easy by wrapping each function in a ruby class.
8
+
9
+ The wrappers are autogenerated from the xml function description provided with the ta-lib project.
10
+
11
+ == Usage
12
+
13
+ Requires the talib-ruby gem. The examples require the yahoofinance gem.
14
+
15
+ Install via gem using:
16
+
17
+ gem install ta-indicator
18
+
19
+ === Simple Example
20
+ The easiest way to use the indicator library is to include the indicator mixin module. This module extends the Array class with the Indicator::Mixin module allowing quick calculations to be performed:
21
+
22
+ require 'indicator/mixin'
23
+
24
+ data = [1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3]
25
+ results = data.indicator(:sma, :time_period => 5)
26
+ results = data.indicator(:sma, 5)
27
+ results = data.indicator(:sma_5)
28
+
29
+ All perform a simple moving average with time period of 5 and produce the same results:
30
+
31
+ => [nil, nil, nil, nil, 2.2, 2.4, 2.6, 2.4, 2.6, 2.4, 2.6]
32
+
33
+ More complex indicators can also be used
34
+
35
+ result = data.indicator(:macd_12_26_9)
36
+
37
+ This performs a macd calculation using a slow period of 12, fast period of 26 and signal period of 9.
38
+
39
+ The list of available indicators can be retrieved via
40
+
41
+ Indicator.list
42
+
43
+ Information about each indicator including a list of arguments can be retrieved via:
44
+
45
+ Indicator.info :sma
46
+ Inficator.info :macd
47
+ ...
48
+
49
+ == Details
50
+ The base Indicator functions are located in the Indicator module and the auto generated classed are located in the Indicator::AutoGen module. All of the following examples assume these modules have been included:
51
+
52
+ require 'indicator'
53
+ include Indicator
54
+ include Indicator::AutoGen
55
+
56
+ === Class Construction
57
+
58
+ All ta-lib functions are wrapped in a class named using the camel class name of the function: SMA is Sma, AVGPRICE is AvgPrice, etc. The constructor takes the optional arguments either as a hash or argument list. For example the Macd class takes three arguments, fast_period, slow_period and signal_period. They can be initialised in any of the following ways:
59
+
60
+ sma = Sma.new 5
61
+ macd = Macd.new 12,26,9
62
+ or
63
+ sma = Sma.new :time_period => 5
64
+ macd = Macd.new :fast_period => 12, :slow_period => 26, :signal_period => 9
65
+
66
+ If a parameter is not passed in then it will be initialised to the default value as specified by the ta-lib interface.
67
+
68
+ The Indicator module also supports factory style functions to simplify class creation.
69
+
70
+ sma = Indicator.create :sma
71
+ sma = Indicator.create :sma, 5
72
+ sma = Indicator.create :sma, time_period => 5
73
+
74
+ macd = Indicator.create :macd
75
+ macd = Indicator.create :macd, 12,26,9
76
+ macd = Indicator.create :macd, :fast_period => 12, :slow_period => 26, :signal_period => 9
77
+
78
+ If a indicator is to be constructed using only integer parameters then an indicator can be constructed using the create_named factory function. The create_named function expects the indicator name optionally followed by it's arguments joined by an underscore.
79
+
80
+ sma = Indicator.create_named :sma_5
81
+ macd = Indicator.create_named :macd_12_26_9
82
+
83
+ === Argument attributes
84
+
85
+ All arguments can be updated through attributes:
86
+ macd.fast_period
87
+ => 12
88
+ macd.slow_period = 30
89
+ => 30
90
+
91
+ A list of all the arguments that a particular class takes can be be retrieved using the class method 'arguments'.
92
+ Macd.arguments
93
+ => [:fast_period, :slow_period, :signal_period]
94
+ Sma.arguments
95
+ => [:time_period]
96
+
97
+ === Running The Indicators
98
+ Each indicator defines a run method that takes in each input array to be processed as a List. An example of an indicator that takes one input:
99
+ sma = Indicator.create_named :sma_5
100
+ sma.run [1,2,3,4,3,2,3,2,3,2,3,2]
101
+ => [nil, nil, nil, nil, 2.6, 2.8, 3.0, 2.8, 2.6, 2.4, 2.6, 2.4]
102
+
103
+ An example of an indicator that takes two inputs:
104
+ add = Indicator.create_named :add
105
+ add.run [1,2,3,4,5], [5,4,3,2,1]
106
+ => [6.0, 6.0, 6.0, 6.0, 6.0]
107
+
108
+ Some indicators require OHLC (and optionally V) price inputs. An example of an indicator that takes price inputs:
109
+ avg = AvgPrice.new
110
+ # AvgPrice run function takes open, high, low, close
111
+ avg.run [1,2,1,2], [2,1,2,1], [3,1,3,1], [1,3,1,3]
112
+ => [1.75, 1.75, 1.75, 1.75]
113
+
114
+ A list of inputs that a indicator run function requires can be retrieved using the class method 'inputs'.
115
+ Sma.inputs
116
+ => [:in_real]
117
+ Add.inputs
118
+ => [:in_real0, in_real1]
119
+ AvgPrice.inputs
120
+ => [:open, :high, :low, :close]
121
+ AdOsc.inputs
122
+ => [:open, :high, :low, :close, :volume]
123
+
124
+ === Outputs
125
+ The run function returns an array containing the results if there is only one List to return otherwise it returns a hash that maps each output List to it's name. For eample:
126
+ sma = Sma.new(5)
127
+ sma.run [1,2,3,4,3,2,3,2,3,2,3,2]
128
+ => [nil, nil, nil, nil, 2.6, 2.8, 3.0, 2.8, 2.6, 2.4, 2.6, 2.4]
129
+ macd = Macd.new 3,4,1
130
+ result = macd.run [1,2,3,4,4,3]
131
+ puts results[:out_macd]
132
+ => [nil, nil, -3.785768566076978e-270, 0.5, nil, nil]
133
+ puts result[:out_macd_signal]
134
+ => [nil, nil, 0.399999999999999, 0.189999999999999, nil, nil],
135
+ puts result[:out_macd_hist]
136
+ => [nil, nil, -0.3999999999999999, 0.31000000000000005, nil, nil]
137
+
138
+ A list of outputs that an indicator run function returns can be retrieved using the class method 'outputs'.
139
+ Sma.outputs
140
+ => [:out_real]
141
+ Macd.outputs
142
+ => [:out_macd, :out_macd_signal, :out_macd_hist]
143
+
144
+ === Data Mapping
145
+ The run function also accepts a DataMapping::Map structure which can be used to extract data from an enumerable collection.
146
+
147
+ # Assume historical_data is a list of hashes with the following keys
148
+ # :open, :high, :low, :close, :volume
149
+ sma = Sma.new 5
150
+ sma_results = sma.run(DataMapper::Map.new(historical_data, :open))
151
+
152
+ When the above example is run the DataMapper will attempt to extract data from the historical_data collection by either calling a function called open or retrieving a hash value using the key :open. You can also directly pass in a lambda function if a more complex mapping function is required.
153
+ To reduce the amount of code required a helper function called new_map is available:
154
+
155
+ sma = Sma.new 5
156
+ sma_results = sma.run new_map(historical_data, :open)
157
+ sma_results = sma.run new_map(historical_data, lambda => |b| { b[:open] / 2 })
158
+
159
+ By default the run function will attempt to use a default getter of :open, so the following is also valid:
160
+
161
+ sma = Sma.new 5
162
+ sma_results = sma.run historical_data
163
+ # Calculates the sma by accessing [:open] on each element of historical_data
164
+
165
+ The default getter can be changed:
166
+ sma = Sma.new 5
167
+ sma.default_getter :high
168
+ sma_results = sma.run historical_data
169
+ # Calculates the sma by accessing [:high] on each element of historical_data
170
+
171
+ The same mapping system works for functions requiring price data as an input. The AvgPrice function can be called using either of the following syntax:
172
+
173
+ ap = AvgPrice.new
174
+ ap.run(
175
+ new_map(historical_data, :open),
176
+ new_map(historical_data, :high),
177
+ new_map(historical_data, :low),
178
+ new_map(historical_data, :close))
179
+
180
+ or
181
+
182
+ ap = AvgPrice.new
183
+ ap.run historical_data
184
+
185
+ The run function will again attempt to use sensible default mappings of :open, :high, :low, :close and :volume (if required).
186
+
187
+ == Regenerating the wrappers
188
+
189
+ The wrappers can be regenerated using the gen_wrapper.rb file in the tools directory:
190
+
191
+ ruby gen_wrapper.rb
192
+
193
+ This script must be run from the tools directory as it uses realtive paths.
194
+ The gen_wrapper.rb script uses the erb library to generate code from the defined templates.
195
+
196
+ == Copyright
197
+
198
+ Copyright (c) 2012 Michael Lamb. See LICENSE for details.
199
+
200
+ The files ta_func_api.xml and ta_func_api.xsd are from the talib library. The license details are contained within LICENSE-ta-lib.
@@ -13,6 +13,16 @@ def bar_to_hash r
13
13
  h
14
14
  end
15
15
 
16
+ def short_hash r
17
+ h = {}
18
+ h[:date] = r[:date]
19
+ h[:high] = r[:high]
20
+ h[:low] = r[:low]
21
+ h[:close] = r[:close]
22
+ h[:volume] = r[:volume]
23
+ h
24
+ end
25
+
16
26
  def get_data_100 ticker
17
27
  YahooFinance::get_historical_quotes_days(ticker, 100)
18
28
  end
@@ -20,6 +30,7 @@ end
20
30
  puts 'Retrieving historical data'
21
31
  cba = get_data_100("CBA.AX").inject([]) { |lst, q| lst << bar_to_hash(q) }
22
32
  nab = get_data_100("NAB.AX").inject([]) { |lst, q| lst << bar_to_hash(q) }
33
+ nab_no_open = nab.inject([]) { |lst, q| lst << short_hash(q) }
23
34
 
24
35
  sma = Indicator.create_named :sma_13
25
36
  sma_results = sma.run(Indicator::DataMapper::Map.new(cba, :open))
@@ -32,6 +43,10 @@ sub = Indicator.create :sub
32
43
  sub.default_getter = :low
33
44
  sub_results = sub.run cba, nab
34
45
 
46
+ stoch = Indicator.create :stoch
47
+ stoch_results = stoch.run nab
48
+ stoch_results = stoch.run nab_no_open
49
+
35
50
  adx = Indicator.create :adx
36
51
  adx_results = adx.run(
37
52
  new_map(nab, :open),
@@ -3,161 +3,161 @@ module Indicator
3
3
  end
4
4
  end
5
5
 
6
- require 'indicator/auto_gen/acos'
7
- require 'indicator/auto_gen/ad'
8
- require 'indicator/auto_gen/add'
9
- require 'indicator/auto_gen/ad_osc'
10
- require 'indicator/auto_gen/adx'
11
- require 'indicator/auto_gen/adxr'
12
- require 'indicator/auto_gen/apo'
13
- require 'indicator/auto_gen/aroon'
14
- require 'indicator/auto_gen/aroon_osc'
15
- require 'indicator/auto_gen/asin'
16
- require 'indicator/auto_gen/atan'
17
- require 'indicator/auto_gen/atr'
18
- require 'indicator/auto_gen/avg_price'
19
- require 'indicator/auto_gen/bbands'
20
- require 'indicator/auto_gen/beta'
21
- require 'indicator/auto_gen/bop'
22
- require 'indicator/auto_gen/cci'
23
- require 'indicator/auto_gen/cdl2_crows'
24
- require 'indicator/auto_gen/cdl3_black_crows'
25
- require 'indicator/auto_gen/cdl3_inside'
26
- require 'indicator/auto_gen/cdl3_line_strike'
27
- require 'indicator/auto_gen/cdl3_outside'
28
- require 'indicator/auto_gen/cdl3_stars_in_south'
29
- require 'indicator/auto_gen/cdl3_white_soldiers'
30
- require 'indicator/auto_gen/cdl_abandoned_baby'
31
- require 'indicator/auto_gen/cdl_advance_block'
32
- require 'indicator/auto_gen/cdl_belt_hold'
33
- require 'indicator/auto_gen/cdl_breakaway'
34
- require 'indicator/auto_gen/cdl_closing_marubozu'
35
- require 'indicator/auto_gen/cdl_conceal_babys_wall'
36
- require 'indicator/auto_gen/cdl_counter_attack'
37
- require 'indicator/auto_gen/cdl_dark_cloud_cover'
38
- require 'indicator/auto_gen/cdl_doji'
39
- require 'indicator/auto_gen/cdl_doji_star'
40
- require 'indicator/auto_gen/cdl_dragonfly_doji'
41
- require 'indicator/auto_gen/cdl_engulfing'
42
- require 'indicator/auto_gen/cdl_evening_doji_star'
43
- require 'indicator/auto_gen/cdl_evening_star'
44
- require 'indicator/auto_gen/cdl_gap_side_side_white'
45
- require 'indicator/auto_gen/cdl_gravestone_doji'
46
- require 'indicator/auto_gen/cdl_hammer'
47
- require 'indicator/auto_gen/cdl_hanging_man'
48
- require 'indicator/auto_gen/cdl_harami'
49
- require 'indicator/auto_gen/cdl_harami_cross'
50
- require 'indicator/auto_gen/cdl_hign_wave'
51
- require 'indicator/auto_gen/cdl_hikkake'
52
- require 'indicator/auto_gen/cdl_hikkake_mod'
53
- require 'indicator/auto_gen/cdl_homing_pigeon'
54
- require 'indicator/auto_gen/cdl_identical3_crows'
55
- require 'indicator/auto_gen/cdl_in_neck'
56
- require 'indicator/auto_gen/cdl_inverted_hammer'
57
- require 'indicator/auto_gen/cdl_kicking'
58
- require 'indicator/auto_gen/cdl_kicking_by_length'
59
- require 'indicator/auto_gen/cdl_ladder_bottom'
60
- require 'indicator/auto_gen/cdl_long_legged_doji'
61
- require 'indicator/auto_gen/cdl_long_line'
62
- require 'indicator/auto_gen/cdl_marubozu'
63
- require 'indicator/auto_gen/cdl_matching_low'
64
- require 'indicator/auto_gen/cdl_mat_hold'
65
- require 'indicator/auto_gen/cdl_morning_doji_star'
66
- require 'indicator/auto_gen/cdl_morning_star'
67
- require 'indicator/auto_gen/cdl_on_neck'
68
- require 'indicator/auto_gen/cdl_piercing'
69
- require 'indicator/auto_gen/cdl_rickshaw_man'
70
- require 'indicator/auto_gen/cdl_rise_fall3_methods'
71
- require 'indicator/auto_gen/cdl_seperating_lines'
72
- require 'indicator/auto_gen/cdl_shooting_star'
73
- require 'indicator/auto_gen/cdl_short_line'
74
- require 'indicator/auto_gen/cdl_spinning_top'
75
- require 'indicator/auto_gen/cdl_stalled_pattern'
76
- require 'indicator/auto_gen/cdl_stick_sandwhich'
77
- require 'indicator/auto_gen/cdl_takuri'
78
- require 'indicator/auto_gen/cdl_tasuki_gap'
79
- require 'indicator/auto_gen/cdl_thrusting'
80
- require 'indicator/auto_gen/cdl_tristar'
81
- require 'indicator/auto_gen/cdl_unique3_river'
82
- require 'indicator/auto_gen/cdl_upside_gap2_crows'
83
- require 'indicator/auto_gen/cdl_x_side_gap3_methods'
84
- require 'indicator/auto_gen/ceil'
85
- require 'indicator/auto_gen/cmo'
86
- require 'indicator/auto_gen/correl'
87
- require 'indicator/auto_gen/cos'
88
- require 'indicator/auto_gen/cosh'
89
- require 'indicator/auto_gen/dema'
90
- require 'indicator/auto_gen/div'
91
- require 'indicator/auto_gen/dx'
92
- require 'indicator/auto_gen/ema'
93
- require 'indicator/auto_gen/exp'
94
- require 'indicator/auto_gen/floor'
95
- require 'indicator/auto_gen/ht_dc_period'
96
- require 'indicator/auto_gen/ht_dc_phase'
97
- require 'indicator/auto_gen/ht_phasor'
98
- require 'indicator/auto_gen/ht_sine'
99
- require 'indicator/auto_gen/ht_trendline'
100
- require 'indicator/auto_gen/ht_trend_mode'
101
- require 'indicator/auto_gen/kama'
102
- require 'indicator/auto_gen/linear_reg'
103
- require 'indicator/auto_gen/linear_reg_angle'
104
- require 'indicator/auto_gen/linear_reg_intercept'
105
- require 'indicator/auto_gen/linear_reg_slope'
106
- require 'indicator/auto_gen/ln'
107
- require 'indicator/auto_gen/log10'
108
- require 'indicator/auto_gen/moving_average'
109
- require 'indicator/auto_gen/macd'
110
- require 'indicator/auto_gen/macd_ext'
111
- require 'indicator/auto_gen/macd_fix'
112
- require 'indicator/auto_gen/mama'
113
- require 'indicator/auto_gen/moving_average_variable_period'
114
- require 'indicator/auto_gen/max'
115
- require 'indicator/auto_gen/max_index'
116
- require 'indicator/auto_gen/med_price'
117
- require 'indicator/auto_gen/mfi'
118
- require 'indicator/auto_gen/mid_point'
119
- require 'indicator/auto_gen/mid_price'
120
- require 'indicator/auto_gen/min'
121
- require 'indicator/auto_gen/min_index'
122
- require 'indicator/auto_gen/min_max'
123
- require 'indicator/auto_gen/min_max_index'
124
- require 'indicator/auto_gen/minus_di'
125
- require 'indicator/auto_gen/minus_dm'
126
- require 'indicator/auto_gen/mom'
127
- require 'indicator/auto_gen/mult'
128
- require 'indicator/auto_gen/natr'
129
- require 'indicator/auto_gen/obv'
130
- require 'indicator/auto_gen/plus_di'
131
- require 'indicator/auto_gen/plus_dm'
132
- require 'indicator/auto_gen/ppo'
133
- require 'indicator/auto_gen/roc'
134
- require 'indicator/auto_gen/roc_p'
135
- require 'indicator/auto_gen/roc_r'
136
- require 'indicator/auto_gen/roc_r100'
137
- require 'indicator/auto_gen/rsi'
138
- require 'indicator/auto_gen/sar'
139
- require 'indicator/auto_gen/sar_ext'
140
- require 'indicator/auto_gen/sin'
141
- require 'indicator/auto_gen/sinh'
142
- require 'indicator/auto_gen/sma'
143
- require 'indicator/auto_gen/sqrt'
144
- require 'indicator/auto_gen/std_dev'
145
- require 'indicator/auto_gen/stoch'
146
- require 'indicator/auto_gen/stoch_f'
147
- require 'indicator/auto_gen/stoch_rsi'
148
- require 'indicator/auto_gen/sub'
149
- require 'indicator/auto_gen/sum'
150
- require 'indicator/auto_gen/t3'
151
- require 'indicator/auto_gen/tan'
152
- require 'indicator/auto_gen/tanh'
153
- require 'indicator/auto_gen/tema'
154
- require 'indicator/auto_gen/true_range'
155
- require 'indicator/auto_gen/trima'
156
- require 'indicator/auto_gen/trix'
157
- require 'indicator/auto_gen/tsf'
158
- require 'indicator/auto_gen/typ_price'
159
- require 'indicator/auto_gen/ult_osc'
160
- require 'indicator/auto_gen/variance'
161
- require 'indicator/auto_gen/wcl_price'
162
- require 'indicator/auto_gen/will_r'
163
- require 'indicator/auto_gen/wma'
6
+ require 'indicator\auto_gen\acos'
7
+ require 'indicator\auto_gen\ad'
8
+ require 'indicator\auto_gen\add'
9
+ require 'indicator\auto_gen\ad_osc'
10
+ require 'indicator\auto_gen\adx'
11
+ require 'indicator\auto_gen\adxr'
12
+ require 'indicator\auto_gen\apo'
13
+ require 'indicator\auto_gen\aroon'
14
+ require 'indicator\auto_gen\aroon_osc'
15
+ require 'indicator\auto_gen\asin'
16
+ require 'indicator\auto_gen\atan'
17
+ require 'indicator\auto_gen\atr'
18
+ require 'indicator\auto_gen\avg_price'
19
+ require 'indicator\auto_gen\bbands'
20
+ require 'indicator\auto_gen\beta'
21
+ require 'indicator\auto_gen\bop'
22
+ require 'indicator\auto_gen\cci'
23
+ require 'indicator\auto_gen\cdl2_crows'
24
+ require 'indicator\auto_gen\cdl3_black_crows'
25
+ require 'indicator\auto_gen\cdl3_inside'
26
+ require 'indicator\auto_gen\cdl3_line_strike'
27
+ require 'indicator\auto_gen\cdl3_outside'
28
+ require 'indicator\auto_gen\cdl3_stars_in_south'
29
+ require 'indicator\auto_gen\cdl3_white_soldiers'
30
+ require 'indicator\auto_gen\cdl_abandoned_baby'
31
+ require 'indicator\auto_gen\cdl_advance_block'
32
+ require 'indicator\auto_gen\cdl_belt_hold'
33
+ require 'indicator\auto_gen\cdl_breakaway'
34
+ require 'indicator\auto_gen\cdl_closing_marubozu'
35
+ require 'indicator\auto_gen\cdl_conceal_babys_wall'
36
+ require 'indicator\auto_gen\cdl_counter_attack'
37
+ require 'indicator\auto_gen\cdl_dark_cloud_cover'
38
+ require 'indicator\auto_gen\cdl_doji'
39
+ require 'indicator\auto_gen\cdl_doji_star'
40
+ require 'indicator\auto_gen\cdl_dragonfly_doji'
41
+ require 'indicator\auto_gen\cdl_engulfing'
42
+ require 'indicator\auto_gen\cdl_evening_doji_star'
43
+ require 'indicator\auto_gen\cdl_evening_star'
44
+ require 'indicator\auto_gen\cdl_gap_side_side_white'
45
+ require 'indicator\auto_gen\cdl_gravestone_doji'
46
+ require 'indicator\auto_gen\cdl_hammer'
47
+ require 'indicator\auto_gen\cdl_hanging_man'
48
+ require 'indicator\auto_gen\cdl_harami'
49
+ require 'indicator\auto_gen\cdl_harami_cross'
50
+ require 'indicator\auto_gen\cdl_hign_wave'
51
+ require 'indicator\auto_gen\cdl_hikkake'
52
+ require 'indicator\auto_gen\cdl_hikkake_mod'
53
+ require 'indicator\auto_gen\cdl_homing_pigeon'
54
+ require 'indicator\auto_gen\cdl_identical3_crows'
55
+ require 'indicator\auto_gen\cdl_in_neck'
56
+ require 'indicator\auto_gen\cdl_inverted_hammer'
57
+ require 'indicator\auto_gen\cdl_kicking'
58
+ require 'indicator\auto_gen\cdl_kicking_by_length'
59
+ require 'indicator\auto_gen\cdl_ladder_bottom'
60
+ require 'indicator\auto_gen\cdl_long_legged_doji'
61
+ require 'indicator\auto_gen\cdl_long_line'
62
+ require 'indicator\auto_gen\cdl_marubozu'
63
+ require 'indicator\auto_gen\cdl_matching_low'
64
+ require 'indicator\auto_gen\cdl_mat_hold'
65
+ require 'indicator\auto_gen\cdl_morning_doji_star'
66
+ require 'indicator\auto_gen\cdl_morning_star'
67
+ require 'indicator\auto_gen\cdl_on_neck'
68
+ require 'indicator\auto_gen\cdl_piercing'
69
+ require 'indicator\auto_gen\cdl_rickshaw_man'
70
+ require 'indicator\auto_gen\cdl_rise_fall3_methods'
71
+ require 'indicator\auto_gen\cdl_seperating_lines'
72
+ require 'indicator\auto_gen\cdl_shooting_star'
73
+ require 'indicator\auto_gen\cdl_short_line'
74
+ require 'indicator\auto_gen\cdl_spinning_top'
75
+ require 'indicator\auto_gen\cdl_stalled_pattern'
76
+ require 'indicator\auto_gen\cdl_stick_sandwhich'
77
+ require 'indicator\auto_gen\cdl_takuri'
78
+ require 'indicator\auto_gen\cdl_tasuki_gap'
79
+ require 'indicator\auto_gen\cdl_thrusting'
80
+ require 'indicator\auto_gen\cdl_tristar'
81
+ require 'indicator\auto_gen\cdl_unique3_river'
82
+ require 'indicator\auto_gen\cdl_upside_gap2_crows'
83
+ require 'indicator\auto_gen\cdl_x_side_gap3_methods'
84
+ require 'indicator\auto_gen\ceil'
85
+ require 'indicator\auto_gen\cmo'
86
+ require 'indicator\auto_gen\correl'
87
+ require 'indicator\auto_gen\cos'
88
+ require 'indicator\auto_gen\cosh'
89
+ require 'indicator\auto_gen\dema'
90
+ require 'indicator\auto_gen\div'
91
+ require 'indicator\auto_gen\dx'
92
+ require 'indicator\auto_gen\ema'
93
+ require 'indicator\auto_gen\exp'
94
+ require 'indicator\auto_gen\floor'
95
+ require 'indicator\auto_gen\ht_dc_period'
96
+ require 'indicator\auto_gen\ht_dc_phase'
97
+ require 'indicator\auto_gen\ht_phasor'
98
+ require 'indicator\auto_gen\ht_sine'
99
+ require 'indicator\auto_gen\ht_trendline'
100
+ require 'indicator\auto_gen\ht_trend_mode'
101
+ require 'indicator\auto_gen\kama'
102
+ require 'indicator\auto_gen\linear_reg'
103
+ require 'indicator\auto_gen\linear_reg_angle'
104
+ require 'indicator\auto_gen\linear_reg_intercept'
105
+ require 'indicator\auto_gen\linear_reg_slope'
106
+ require 'indicator\auto_gen\ln'
107
+ require 'indicator\auto_gen\log10'
108
+ require 'indicator\auto_gen\moving_average'
109
+ require 'indicator\auto_gen\macd'
110
+ require 'indicator\auto_gen\macd_ext'
111
+ require 'indicator\auto_gen\macd_fix'
112
+ require 'indicator\auto_gen\mama'
113
+ require 'indicator\auto_gen\moving_average_variable_period'
114
+ require 'indicator\auto_gen\max'
115
+ require 'indicator\auto_gen\max_index'
116
+ require 'indicator\auto_gen\med_price'
117
+ require 'indicator\auto_gen\mfi'
118
+ require 'indicator\auto_gen\mid_point'
119
+ require 'indicator\auto_gen\mid_price'
120
+ require 'indicator\auto_gen\min'
121
+ require 'indicator\auto_gen\min_index'
122
+ require 'indicator\auto_gen\min_max'
123
+ require 'indicator\auto_gen\min_max_index'
124
+ require 'indicator\auto_gen\minus_di'
125
+ require 'indicator\auto_gen\minus_dm'
126
+ require 'indicator\auto_gen\mom'
127
+ require 'indicator\auto_gen\mult'
128
+ require 'indicator\auto_gen\natr'
129
+ require 'indicator\auto_gen\obv'
130
+ require 'indicator\auto_gen\plus_di'
131
+ require 'indicator\auto_gen\plus_dm'
132
+ require 'indicator\auto_gen\ppo'
133
+ require 'indicator\auto_gen\roc'
134
+ require 'indicator\auto_gen\roc_p'
135
+ require 'indicator\auto_gen\roc_r'
136
+ require 'indicator\auto_gen\roc_r100'
137
+ require 'indicator\auto_gen\rsi'
138
+ require 'indicator\auto_gen\sar'
139
+ require 'indicator\auto_gen\sar_ext'
140
+ require 'indicator\auto_gen\sin'
141
+ require 'indicator\auto_gen\sinh'
142
+ require 'indicator\auto_gen\sma'
143
+ require 'indicator\auto_gen\sqrt'
144
+ require 'indicator\auto_gen\std_dev'
145
+ require 'indicator\auto_gen\stoch'
146
+ require 'indicator\auto_gen\stoch_f'
147
+ require 'indicator\auto_gen\stoch_rsi'
148
+ require 'indicator\auto_gen\sub'
149
+ require 'indicator\auto_gen\sum'
150
+ require 'indicator\auto_gen\t3'
151
+ require 'indicator\auto_gen\tan'
152
+ require 'indicator\auto_gen\tanh'
153
+ require 'indicator\auto_gen\tema'
154
+ require 'indicator\auto_gen\true_range'
155
+ require 'indicator\auto_gen\trima'
156
+ require 'indicator\auto_gen\trix'
157
+ require 'indicator\auto_gen\tsf'
158
+ require 'indicator\auto_gen\typ_price'
159
+ require 'indicator\auto_gen\ult_osc'
160
+ require 'indicator\auto_gen\variance'
161
+ require 'indicator\auto_gen\wcl_price'
162
+ require 'indicator\auto_gen\will_r'
163
+ require 'indicator\auto_gen\wma'