signal_tools 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -4,24 +4,24 @@ Signal tools allows you to create technical analysis data for a given stock (lik
4
4
 
5
5
  == Installation
6
6
 
7
- gem install signal_tools
8
- bundle install --without development test
7
+ gem install signal_tools
8
+ bundle install --without development test
9
9
 
10
10
  == Usage
11
11
 
12
- require 'signal_tools'
12
+ require 'signal_tools'
13
13
 
14
- stock = SignalTools::Stock.new('GOOG', '2010-01-01', '2010-05-31')
15
- # Leave the last parameter blank to get from a previous date up until today:
16
- stock = SignalTools::Stock.new('GOOG', '2010-01-01')
17
- # Leave both dates blank to get the past 90 days:
18
- stock = SignalTools::Stock.new('GOOG')
14
+ stock = SignalTools::Stock.new('GOOG', '2010-01-01', '2010-05-31')
15
+ # Leave the last parameter blank to get from a previous date up until today:
16
+ stock = SignalTools::Stock.new('GOOG', '2010-01-01')
17
+ # Leave both dates blank to get the past 90 days:
18
+ stock = SignalTools::Stock.new('GOOG')
19
19
 
20
- # Generate MACD signal with an 8 day short period, 17 day long period, and 9 day EMA signal period:
21
- stock.macd(8, 17, 9)
20
+ # Generate MACD signal with an 8 day short period, 17 day long period, and 9 day EMA signal period:
21
+ stock.macd(8, 17, 9)
22
22
 
23
- # Generate slow stochastic signal with a 14 day K period and a 5 day D period:
24
- stock.slow_stochastic(14, 5)
23
+ # Generate slow stochastic signal with a 14 day K period and a 5 day D period:
24
+ stock.slow_stochastic(14, 5)
25
25
 
26
26
  == Note on Patches/Pull Requests
27
27
 
data/Rakefile CHANGED
@@ -1,5 +1,4 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ require 'bundler/gem_tasks'
3
2
 
4
3
  require 'rake/testtask'
5
4
  Rake::TestTask.new(:test) do |test|
@@ -8,33 +7,4 @@ Rake::TestTask.new(:test) do |test|
8
7
  test.verbose = true
9
8
  end
10
9
 
11
- begin
12
- require 'rcov/rcovtask'
13
- Rcov::RcovTask.new do |test|
14
- test.libs << 'test'
15
- test.pattern = 'test/**/*_test.rb'
16
- test.verbose = true
17
- end
18
- rescue LoadError
19
- task :rcov do
20
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
21
- end
22
- end
23
-
24
- #task :test => :check_dependencies
25
-
26
10
  task :default => :test
27
-
28
- require 'rake/rdoctask'
29
- Rake::RDocTask.new do |rdoc|
30
- if File.exist?('VERSION')
31
- version = File.read('VERSION')
32
- else
33
- version = ""
34
- end
35
-
36
- rdoc.rdoc_dir = 'rdoc'
37
- rdoc.title = "signal_tools #{version}"
38
- rdoc.rdoc_files.include('README*')
39
- rdoc.rdoc_files.include('lib/**/*.rb')
40
- end
@@ -15,33 +15,37 @@ module SignalTools
15
15
  @stock_data = SignalTools::StockData.new(ticker, from_date, to_date)
16
16
  end
17
17
 
18
- def dates
19
- @stock_data.dates
20
- end
21
-
22
18
  # Takes a period of days over which to average closing prices and returns the exponential moving average for each day.
23
19
  def ema(period=10)
24
- trim_data_to_range(ema_points(period, @stock_data.close_prices))
20
+ trim_data_to_range!(ema_points(period, @stock_data.close_prices))
25
21
  end
26
22
 
27
23
  def macd(fast=8, slow=17, signal=9)
28
- trim_data_to_range(macd_points(fast, slow, signal))
24
+ trim_data_to_range!(macd_points(fast, slow, signal))
29
25
  end
30
26
 
31
27
  def fast_stochastic(k=14, d=5)
32
- trim_data_to_range(fast_stochastic_points(k, d))
28
+ trim_data_to_range!(fast_stochastic_points(k, d))
33
29
  end
34
30
 
35
31
  def slow_stochastic(k=14, d=5)
36
- trim_data_to_range(slow_stochastic_points(k, d))
32
+ trim_data_to_range!(slow_stochastic_points(k, d))
37
33
  end
38
34
 
39
35
  def atr(period=14)
40
- trim_data_to_range(average_true_ranges(period))
36
+ trim_data_to_range!(average_true_ranges(period))
41
37
  end
42
38
 
43
39
  def adx(period=14)
44
- trim_data_to_range(average_directional_indexes(period))
40
+ trim_data_to_range!(average_directional_indexes(period))
41
+ end
42
+
43
+ def dates
44
+ @stock_data.dates
45
+ end
46
+
47
+ def close_prices
48
+ @close_prices = trim_data_to_range(@stock_data.close_prices)
45
49
  end
46
50
 
47
51
  private
@@ -263,15 +267,19 @@ module SignalTools
263
267
  #### Misc Utility Methods
264
268
 
265
269
  # Returns only the points specific to the date range given.
266
- def trim_data_to_range(data)
270
+ def trim_data_to_range!(data)
267
271
  if data.is_a? Array
268
- data.slice!(0...(-dates.size))
272
+ data.slice!(0..(-dates.size-1))
269
273
  elsif data.is_a? Hash
270
- data.each { |k,v| v = v.slice!(0...(-dates.size)) }
274
+ data.each { |k,v| v = v.slice!(0..(-dates.size-1)) }
271
275
  end
272
276
  data
273
277
  end
274
278
 
279
+ def trim_data_to_range(data)
280
+ data.slice((-dates.size+1)..-1)
281
+ end
282
+
275
283
  # Gets the first 0...period of numbers from data and returns a simple average.
276
284
  def default_simple_average(data, period)
277
285
  SignalTools.average(data.slice(0...period))
@@ -299,11 +307,5 @@ module SignalTools
299
307
  end
300
308
  collection
301
309
  end
302
-
303
- def matching_dates(array)
304
- dates = @stock_data.dates.dup
305
- SignalTools.truncate_to_shortest!(dates, array)
306
- @dates = dates
307
- end
308
310
  end
309
311
  end
@@ -56,7 +56,7 @@ module SignalTools
56
56
  def trim_dates
57
57
  dates = @raw_data.map { |d| d[Indexes[:date]] }
58
58
  index = binary_search_for_date_index(dates)
59
- dates[index..-1]
59
+ dates[(index+1)..-1]
60
60
  end
61
61
 
62
62
  # Performs a binary search for @from_date on @dates. Returns the index of @from_date.
data/test/test_stock.rb CHANGED
@@ -65,12 +65,12 @@ class TestStock < Test::Unit::TestCase
65
65
  end
66
66
 
67
67
  def test_stock_should_have_correct_number_of_data_elements
68
- assert_equal(@days+1, @stock.dates.size)
69
- assert_equal(@days+1, @stock.ema.size)
70
- assert_equal(@days+1, @stock.macd[:divergences].size)
71
- assert_equal(@days+1, @stock.fast_stochastic[:k].size)
72
- assert_equal(@days+1, @stock.slow_stochastic[:k].size)
73
- assert_equal(@days+1, @stock.atr.size)
74
- assert_equal(@days+1, @stock.adx.size)
68
+ assert_equal(@days, @stock.dates.size)
69
+ assert_equal(@days, @stock.ema.size)
70
+ assert_equal(@days, @stock.macd[:divergences].size)
71
+ assert_equal(@days, @stock.fast_stochastic[:k].size)
72
+ assert_equal(@days, @stock.slow_stochastic[:k].size)
73
+ assert_equal(@days, @stock.atr.size)
74
+ assert_equal(@days, @stock.adx.size)
75
75
  end
76
76
  end
@@ -14,7 +14,7 @@ class TestStockData < Test::Unit::TestCase
14
14
 
15
15
  def test_dates
16
16
  new_dates = []
17
- (0..@days).each { |i| new_dates.unshift((@to_date - i)) }
17
+ (0...@days).each { |i| new_dates.unshift(@to_date - i) }
18
18
  assert_equal new_dates, @stock_data.dates
19
19
  end
20
20
 
metadata CHANGED
@@ -1,57 +1,34 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: signal_tools
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 2
8
- - 0
9
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Matt White
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-11-05 00:00:00 -06:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: rake
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- version: "0"
31
- type: :runtime
32
- version_requirements: *id001
33
- - !ruby/object:Gem::Dependency
12
+ date: 2011-08-29 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
34
15
  name: yahoofinance
35
- prerelease: false
36
- requirement: &id002 !ruby/object:Gem::Requirement
16
+ requirement: &81101670 !ruby/object:Gem::Requirement
37
17
  none: false
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 0
43
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
44
22
  type: :runtime
45
- version_requirements: *id002
46
- description: Gem to create technical analysis data for a given security (like MACD, stochastic, and exponential moving averages).
23
+ prerelease: false
24
+ version_requirements: *81101670
25
+ description: Gem to create technical analysis data for a given stock (like MACD, stochastic,
26
+ and exponential moving averages).
47
27
  email: mattw922@gmail.com
48
28
  executables: []
49
-
50
29
  extensions: []
51
-
52
30
  extra_rdoc_files: []
53
-
54
- files:
31
+ files:
55
32
  - Rakefile
56
33
  - lib/signal_tools/stock.rb
57
34
  - lib/signal_tools/stock_data.rb
@@ -63,37 +40,28 @@ files:
63
40
  - test/test_stock.rb
64
41
  - README.rdoc
65
42
  - LICENSE
66
- has_rdoc: true
67
43
  homepage: http://github.com/whitethunder/signal_tools
68
44
  licenses: []
69
-
70
45
  post_install_message:
71
46
  rdoc_options: []
72
-
73
- require_paths:
47
+ require_paths:
74
48
  - lib
75
- required_ruby_version: !ruby/object:Gem::Requirement
49
+ required_ruby_version: !ruby/object:Gem::Requirement
76
50
  none: false
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- segments:
81
- - 0
82
- version: "0"
83
- required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
56
  none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- segments:
89
- - 0
90
- version: "0"
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
91
61
  requirements: []
92
-
93
62
  rubyforge_project:
94
- rubygems_version: 1.3.7
63
+ rubygems_version: 1.8.6
95
64
  signing_key:
96
65
  specification_version: 3
97
66
  summary: Create technical analysis data for a given stock.
98
67
  test_files: []
99
-