sqa 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.irbrc +3 -0
  3. data/checksums/sqa-0.0.2.gem.sha512 +1 -0
  4. data/docs/average_true_range.md +9 -0
  5. data/docs/data_frame.md +164 -0
  6. data/docs/fibonacci_retracement.md +30 -0
  7. data/docs/identify_wave_condition.md +14 -0
  8. data/docs/peaks_and_valleys.md +11 -0
  9. data/docs/requirements.md +22 -0
  10. data/docs/stochastic_oscillator.md +4 -0
  11. data/docs/strategy.md +5 -0
  12. data/lib/sqa/cli.rb +1 -1
  13. data/lib/sqa/data_frame/yahoo_finance.rb +24 -0
  14. data/lib/sqa/data_frame.rb +16 -0
  15. data/lib/sqa/indicator/average_true_range.rb +22 -9
  16. data/lib/sqa/indicator/bollinger_bands.rb +2 -2
  17. data/lib/sqa/indicator/candlestick_pattern_recognizer.rb +1 -1
  18. data/lib/sqa/indicator/donchian_channel.rb +1 -1
  19. data/lib/sqa/indicator/double_top_bottom_pattern.rb +1 -1
  20. data/lib/sqa/indicator/elliott_wave_theory.rb +57 -0
  21. data/lib/sqa/indicator/exponential_moving_average.rb +25 -0
  22. data/lib/sqa/indicator/exponential_moving_average_trend.rb +36 -0
  23. data/lib/sqa/indicator/fibonacci_retracement.rb +5 -7
  24. data/lib/sqa/indicator/head_and_shoulders_pattern.rb +1 -1
  25. data/lib/sqa/indicator/{classify_market_profile.rb → market_profile.rb} +7 -8
  26. data/lib/sqa/indicator/mean_reversion.rb +1 -1
  27. data/lib/sqa/indicator/momentum.rb +9 -7
  28. data/lib/sqa/indicator/moving_average_convergence_divergence.rb +7 -3
  29. data/lib/sqa/indicator/peaks_and_valleys.rb +29 -0
  30. data/lib/sqa/indicator/{relative_strength_index.md.rb → relative_strength_index.rb} +2 -2
  31. data/lib/sqa/indicator/simple_moving_average.rb +6 -3
  32. data/lib/sqa/indicator/simple_moving_average_trend.rb +15 -14
  33. data/lib/sqa/indicator/stochastic_oscillator.rb +32 -3
  34. data/lib/sqa/indicator/true_range.rb +14 -12
  35. data/lib/sqa/indicator.rb +4 -4
  36. data/lib/sqa/stock.rb +6 -13
  37. data/lib/sqa/strategy.rb +65 -0
  38. data/lib/sqa/version.rb +3 -1
  39. data/lib/sqa.rb +44 -6
  40. metadata +34 -29
  41. data/lib/sqa/datastore/active_record.rb +0 -89
  42. data/lib/sqa/datastore/csv/yahoo_finance.rb +0 -51
  43. data/lib/sqa/datastore/csv.rb +0 -93
  44. data/lib/sqa/datastore/sqlite.rb +0 -7
  45. data/lib/sqa/datastore.rb +0 -6
  46. data/lib/sqa/indicator/average_true_range.md +0 -9
  47. data/lib/sqa/indicator/ema_analysis.rb +0 -70
  48. data/lib/sqa/indicator/fibonacci_retracement.md +0 -3
  49. data/lib/sqa/indicator/identify_wave_condition.md +0 -6
  50. data/lib/sqa/indicator/identify_wave_condition.rb +0 -40
  51. data/lib/sqa/indicator/stochastic_oscillator.md +0 -5
  52. /data/{lib/sqa/indicator → docs}/README.md +0 -0
  53. /data/{lib/sqa/indicator → docs}/bollinger_bands.md +0 -0
  54. /data/{lib/sqa/indicator → docs}/candlestick_pattern_recognizer.md +0 -0
  55. /data/{lib/sqa/indicator → docs}/donchian_channel.md +0 -0
  56. /data/{lib/sqa/indicator → docs}/double_top_bottom_pattern.md +0 -0
  57. /data/{lib/sqa/indicator/ema_analysis.md → docs/exponential_moving_average.md} +0 -0
  58. /data/{lib/sqa/indicator → docs}/head_and_shoulders_pattern.md +0 -0
  59. /data/{lib/sqa/indicator/classify_market_profile.md → docs/market_profile.md} +0 -0
  60. /data/{lib/sqa/indicator → docs}/mean_reversion.md +0 -0
  61. /data/{lib/sqa/indicator → docs}/momentum.md +0 -0
  62. /data/{lib/sqa/indicator → docs}/moving_average_convergence_divergence.md +0 -0
  63. /data/{lib/sqa/indicator → docs}/relative_strength_index.md +0 -0
  64. /data/{lib/sqa/indicator → docs}/simple_moving_average.md +0 -0
  65. /data/{lib/sqa/indicator → docs}/true_range.md +0 -0
@@ -1,6 +1,6 @@
1
1
  # lib/sqa/indicator/momentum.rb
2
2
 
3
- module SQA::Indicator; class << self
3
+ class SQA::Indicator; class << self
4
4
 
5
5
  # @param prices [Array]
6
6
  # @param period [Integer]
@@ -11,14 +11,16 @@ module SQA::Indicator; class << self
11
11
  prices, # Array of prices
12
12
  period # Integer number of entries to consider
13
13
  )
14
- return 0.0 if prices.length <= period
15
14
 
16
- current_price = prices.last
17
- past_price = prices.last(period).first
18
- change = (current_price - past_price) / past_price.to_f
19
- momentum = change * 100.0
15
+ momentums = []
20
16
 
21
- momentum # Float expressed as a percentage change
17
+ prices.each_cons(period) do |window|
18
+ current_price = window.last.to_f
19
+ past_price = window.first.to_f
20
+ momentums << 10.0 * ( (current_price - past_price) / past_price)
21
+ end
22
+
23
+ momentums # Array
22
24
  end
23
25
  alias_method :m, :momentum
24
26
 
@@ -1,6 +1,6 @@
1
1
  # lib/sqa/indicator/moving_average_convergence_divergence.rb
2
2
 
3
- module SQA::Indicator; class << self
3
+ class SQA::Indicator; class << self
4
4
 
5
5
  def moving_average_convergence_divergence(
6
6
  prices,
@@ -11,8 +11,12 @@ module SQA::Indicator; class << self
11
11
 
12
12
  short_ma = simple_moving_average(prices, short_period)
13
13
  long_ma = simple_moving_average(prices, long_period)
14
- macd_line = short_ma.last - long_ma.last
15
- signal_line = simple_moving_average(short_ma, signal_period).last
14
+ signal_line = simple_moving_average(short_ma, signal_period)
15
+ macd_line = []
16
+
17
+ prices.size.times do |x|
18
+ macd_line << short_ma[x] - long_ma[x]
19
+ end
16
20
 
17
21
  {
18
22
  macd: macd_line, # Array
@@ -0,0 +1,29 @@
1
+
2
+ class SQA::Indicator; class << self
3
+
4
+ def peaks_and_valleys(
5
+ prices, # Array of prices
6
+ delta # Integer distance delta (# of higher or lower prices to either side)
7
+ )
8
+ peaks = []
9
+ valleys = []
10
+ period = 2 * delta + 1
11
+
12
+ prices.each_cons(period) do |window|
13
+ price = window[delta]
14
+
15
+ next if window.count(price) == period
16
+
17
+ peaks << price if window.max == price
18
+ valleys << price if window.min == price
19
+ end
20
+
21
+ {
22
+ period: period,
23
+ peaks: peaks,
24
+ valleys: valleys
25
+ }
26
+ end
27
+ alias_method :pav, :peaks_and_valleys
28
+
29
+ end; end
@@ -1,12 +1,12 @@
1
1
  # lib/sqa/indicator/relative_strength_index.rb
2
2
 
3
- module SQA::Indicator; class << self
3
+ class SQA::Indicator; class << self
4
4
 
5
5
  def relative_strength_index(
6
6
  prices, # Array of prices
7
7
  period, # Integer how many to consider at a time
8
8
  over_sold = 30.0, # Float break over point in trend
9
- over_boufht = 70.0 # Float break over point in trend
9
+ over_bought = 70.0 # Float break over point in trend
10
10
  )
11
11
  gains = []
12
12
  losses = []
@@ -1,6 +1,6 @@
1
1
  # lib/sqa/indicator/simple_moving_average.rb
2
2
 
3
- module SQA::Indicator; class << self
3
+ class SQA::Indicator; class << self
4
4
 
5
5
  def simple_moving_average(
6
6
  prices, # Array of prices
@@ -8,9 +8,12 @@ module SQA::Indicator; class << self
8
8
  )
9
9
  moving_averages = []
10
10
 
11
+ (0..period-2).to_a.each do |x|
12
+ moving_averages << prices[0..x].mean
13
+ end
14
+
11
15
  prices.each_cons(period) do |window|
12
- moving_average = window.sum / period.to_f
13
- moving_averages << moving_average
16
+ moving_averages << window.mean
14
17
  end
15
18
 
16
19
  moving_averages # Array
@@ -1,28 +1,29 @@
1
1
  # lib/sqa/indicator/simple_moving_average_trend.rb
2
2
 
3
- module SQA::Indicator; class << self
3
+ class SQA::Indicator; class << self
4
4
 
5
5
  def simple_moving_average_trend(
6
- closing_prices, # Array of closing prices
6
+ prices, # Array of prices
7
7
  period, # Integer number of entries to consider
8
- delta = 0.0005 # Float defines a :nutria trend range.
8
+ delta = 1.0 # Float defines the angle range(+/-) for :neutral trend
9
9
  )
10
- sma = simple_moving_average(closing_prices, period)
10
+ sma = simple_moving_average(prices, period)
11
11
  last_sma = sma.last
12
- prev_sma = sma[-2]
12
+ prev_sma = sma.last(period).first
13
13
  angle = Math.atan((last_sma - prev_sma) / period) * (180 / Math::PI)
14
14
 
15
- if angle > 0.0
16
- trend = :up
17
- elsif angle < 0.0
18
- trend = :down
19
- else
20
- trend = :neutral
21
- end
15
+ trend = if angle > delta
16
+ :up
17
+ elsif angle < -delta
18
+ :down
19
+ else
20
+ :neutral
21
+ end
22
22
 
23
23
  {
24
- trend: trend, # Symbol :up, :down, :neutral
25
- angle: angle # Float how step the trend
24
+ sma: sma, # Array
25
+ trend: trend, # Symbol :up, :down, :neutral
26
+ angle: angle # Float how step the trend
26
27
  }
27
28
  end
28
29
  alias_method :sma_trend, :simple_moving_average_trend
@@ -1,6 +1,6 @@
1
1
  # lib/sqa/indicator/stochastic_oscillator.rb
2
2
 
3
- module SQA::Indicator; class << self
3
+ class SQA::Indicator; class << self
4
4
 
5
5
  # @param high_prices [Array]
6
6
  # @param low_prices [Array]
@@ -20,10 +20,10 @@ module SQA::Indicator; class << self
20
20
  k_values = []
21
21
  d_values = []
22
22
 
23
- closing_prices.each_cons(period) do |closing_prices_subset|
23
+ closing_prices.each_cons(period) do |window|
24
24
  highest_high = high_prices.max(period)
25
25
  lowest_low = low_prices.min(period)
26
- current_close = closing_prices_subset.last
26
+ current_close = window.last
27
27
  k_values << (current_close - lowest_low) / (highest_high - lowest_low) * 100 # Calculate the k_value
28
28
  end
29
29
 
@@ -35,5 +35,34 @@ module SQA::Indicator; class << self
35
35
  end
36
36
  alias_method :so, :stochastic_oscillator
37
37
 
38
+
39
+ def stochastic_oscillator2(
40
+ prices, # Array of prices
41
+ period # Integer number of events to consider
42
+ )
43
+ k_values = []
44
+ d_values = []
45
+
46
+ prices.each_cons(period) do |window|
47
+ low = window.min # Lowest price in the period
48
+ high = window.max # Highest price in the period
49
+ current_price = window.last # Current closing price
50
+
51
+ k_values << (current_price - low) * 100 / (high - low)
52
+ end
53
+
54
+ k_values.each_cons(period) do |window|
55
+ d_values << window.mean
56
+ end
57
+
58
+ {
59
+ k: k_values,
60
+ d: d_values
61
+ }
62
+ end
63
+ alias_method :so2, :stochastic_oscillator2
64
+
65
+
66
+
38
67
  end; end
39
68
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  # See Also: average_true_range
4
4
 
5
- module SQA::Indicator; class << self
5
+ class SQA::Indicator; class << self
6
6
 
7
7
  # @param high_prices [Array]
8
8
  # @param low_prices [Array]
@@ -13,21 +13,23 @@ module SQA::Indicator; class << self
13
13
  def true_range(
14
14
  high_prices, # Array of high prices
15
15
  low_prices, # Array of low prices
16
- previous_closes # Array of previous closing prices
16
+ closing_prices # Array of closing prices
17
17
  )
18
18
  true_ranges = []
19
19
 
20
20
  high_prices.each_with_index do |high, index|
21
- low = low_prices[index]
22
- previous_close = previous_closes[index]
23
-
24
- true_range = [
25
- high - low,
26
- (high - previous_close).abs,
27
- (low - previous_close).abs
28
- ].max
29
-
30
- true_ranges << true_range
21
+ if index > 0
22
+ low = low_prices[index]
23
+ previous_close = closing_prices[index - 1]
24
+
25
+ true_range = [
26
+ high - low,
27
+ (high - previous_close).abs,
28
+ (low - previous_close).abs
29
+ ].max
30
+
31
+ true_ranges << true_range
32
+ end
31
33
  end
32
34
 
33
35
  true_ranges # Array of True Range values
data/lib/sqa/indicator.rb CHANGED
@@ -1,11 +1,11 @@
1
- # lib/sqa/indicators.rb
1
+ # lib/sqa/indicator.rb
2
2
 
3
- module SQA::Indicator
3
+ class SQA::Indicator
4
4
  end
5
5
 
6
6
  # setup a shortcut for the namespace
7
7
  SQAI = SQA::Indicator
8
8
 
9
- Dir["indicator/*.rb"].each do |file|
10
- require_relative file
9
+ Dir[__dir__ + "/indicator/*.rb"].each do |file|
10
+ load file
11
11
  end
data/lib/sqa/stock.rb CHANGED
@@ -1,26 +1,19 @@
1
1
  # lib/sqa/stock.rb
2
2
 
3
- require_relative 'indicators'
4
- require_relative 'datastore'
5
-
6
- class SQA::Stock < ActiveRecord::Base
7
- include SQA::Indicators
8
-
9
- # has_many :activities using ticker as the foreign key
10
- # primary id is ticker it is unique
11
-
3
+ class SQA::Stock
12
4
  attr_accessor :company_name
13
- attr_accessor :data
5
+ attr_accessor :df # The DataFrane
14
6
  attr_accessor :ticker
15
7
 
16
- def initialize(ticker, datastore = SQA::Datastore::CSV)
8
+ def initialize(ticker:, source: :yahoo_finance, type: :csv)
17
9
  @ticker = ticker
18
10
  @company_name = "Company Name"
19
- @data = datastore.new(ticker)
11
+ klass = "SQA::DataFrame::#{source.to_s.camelize}".constantize
12
+ @df = klass.send("from_#{type.downcase}", ticker)
20
13
  end
21
14
 
22
15
  def to_s
23
- "#{ticker} with #{@data.size} data points."
16
+ "#{ticker} with #{@df.size} data points from #{@df.timestamp.first} to #{@df.timestamp.last}"
24
17
  end
25
18
  end
26
19
 
@@ -0,0 +1,65 @@
1
+ # lib/sqa/strategy.rb
2
+
3
+ class SQA::Strategy
4
+ attr_accessor :strategies
5
+
6
+ def initialize
7
+ @strategies = []
8
+ end
9
+
10
+ def add(a_proc=nil, &block)
11
+ @strategies << a_proc unless a_proc.nil?
12
+ @strategies << block if a_proc.nil? && block_given?
13
+ end
14
+
15
+ def execute(v)
16
+ result = []
17
+ # TODO: Can do this in parallel ...
18
+ @strategies.each { |signal| result << signal.call(v) }
19
+ result
20
+ end
21
+ end
22
+
23
+ __END__
24
+
25
+ Example Usage
26
+ =============
27
+
28
+ ss = SQA::Strategy.new
29
+
30
+ ss.add do |vector|
31
+ case rand(10)
32
+ when (8..)
33
+ :buy
34
+ when (..3)
35
+ :sell
36
+ else
37
+ :hold
38
+ end
39
+ end
40
+
41
+
42
+ ss.add do |vector|
43
+ case rand(10)
44
+ when (8..)
45
+ :sell
46
+ when (..3)
47
+ :buy
48
+ else
49
+ :keep
50
+ end
51
+ end
52
+
53
+ def magic(vector)
54
+ 0 == rand(2) ? :spend : :save
55
+ end
56
+
57
+ ss.add method(:magic)
58
+
59
+ class MyClass
60
+ def self.my_method(vector)
61
+ vector.rsi[:rsi]
62
+ end
63
+ end
64
+
65
+ ss.add MyClass.method(:my_method)
data/lib/sqa/version.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SQA
4
- VERSION = "0.0.1"
4
+ module Version
5
+ VERSION = "0.0.3"
6
+ end
5
7
  end
data/lib/sqa.rb CHANGED
@@ -1,12 +1,50 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module SQA
4
- end
5
-
6
- require 'csv'
3
+ require 'active_support'
4
+ require 'active_support/core_ext/string'
5
+ require 'daru'
7
6
  require 'date'
8
- require 'json'
7
+
8
+ require 'debug_me'
9
+ include DebugMe
10
+
11
+ require 'descriptive_statistics'
12
+ require 'mixlib/config'
13
+ require 'nenv'
9
14
  require 'pathname'
15
+ require "version_gem"
10
16
 
11
- require_relative "sqa/version"
17
+ unless defined?(HOME)
18
+ HOME = Pathname.new(Nenv.home)
19
+ end
20
+
21
+
22
+ module SQA
23
+ module Config
24
+ extend Mixlib::Config
25
+ config_strict_mode true
26
+
27
+ default :data_dir, HOME + "sqa_data"
28
+ default :plotting_library, :gruff
29
+ default :lazy_update, false
30
+ end
31
+
32
+ def self.init
33
+ Daru.lazy_update = Config.lazy_update
34
+ Daru.plotting_library = Config.plotting_library
35
+
36
+ nil
37
+ end
38
+ end
39
+
40
+ require_relative "sqa/data_frame"
12
41
  require_relative "sqa/errors"
42
+ require_relative "sqa/indicator"
43
+ require_relative "sqa/strategy"
44
+ require_relative "sqa/stock"
45
+ require_relative "sqa/version"
46
+
47
+
48
+ SQA::Version.class_eval do
49
+ extend VersionGem::Basic
50
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sqa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dewayne VanHoozer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-12 00:00:00.000000000 Z
11
+ date: 2023-08-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Simplistic playpen (e.g. not for serious use) for doing technical analysis
14
14
  of stock prices.
@@ -20,61 +20,66 @@ extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
22
  - ".envrc"
23
+ - ".irbrc"
23
24
  - CHANGELOG.md
24
25
  - LICENSE
25
26
  - README.md
26
27
  - Rakefile
27
28
  - bin/sqa
28
29
  - checksums/sqa-0.0.1.gem.sha512
30
+ - checksums/sqa-0.0.2.gem.sha512
31
+ - docs/README.md
32
+ - docs/average_true_range.md
33
+ - docs/bollinger_bands.md
34
+ - docs/candlestick_pattern_recognizer.md
35
+ - docs/data_frame.md
36
+ - docs/donchian_channel.md
37
+ - docs/double_top_bottom_pattern.md
38
+ - docs/exponential_moving_average.md
39
+ - docs/fibonacci_retracement.md
40
+ - docs/head_and_shoulders_pattern.md
41
+ - docs/identify_wave_condition.md
42
+ - docs/market_profile.md
43
+ - docs/mean_reversion.md
44
+ - docs/momentum.md
45
+ - docs/moving_average_convergence_divergence.md
46
+ - docs/peaks_and_valleys.md
47
+ - docs/relative_strength_index.md
29
48
  - docs/requirements.md
49
+ - docs/simple_moving_average.md
50
+ - docs/stochastic_oscillator.md
51
+ - docs/strategy.md
52
+ - docs/true_range.md
30
53
  - lib/sqa.rb
31
54
  - lib/sqa/activity.rb
32
55
  - lib/sqa/cli.rb
33
- - lib/sqa/datastore.rb
34
- - lib/sqa/datastore/active_record.rb
35
- - lib/sqa/datastore/csv.rb
36
- - lib/sqa/datastore/csv/yahoo_finance.rb
37
- - lib/sqa/datastore/sqlite.rb
56
+ - lib/sqa/data_frame.rb
57
+ - lib/sqa/data_frame/yahoo_finance.rb
38
58
  - lib/sqa/errors.rb
39
59
  - lib/sqa/indicator.rb
40
- - lib/sqa/indicator/README.md
41
- - lib/sqa/indicator/average_true_range.md
42
60
  - lib/sqa/indicator/average_true_range.rb
43
- - lib/sqa/indicator/bollinger_bands.md
44
61
  - lib/sqa/indicator/bollinger_bands.rb
45
- - lib/sqa/indicator/candlestick_pattern_recognizer.md
46
62
  - lib/sqa/indicator/candlestick_pattern_recognizer.rb
47
- - lib/sqa/indicator/classify_market_profile.md
48
- - lib/sqa/indicator/classify_market_profile.rb
49
- - lib/sqa/indicator/donchian_channel.md
50
63
  - lib/sqa/indicator/donchian_channel.rb
51
- - lib/sqa/indicator/double_top_bottom_pattern.md
52
64
  - lib/sqa/indicator/double_top_bottom_pattern.rb
53
- - lib/sqa/indicator/ema_analysis.md
54
- - lib/sqa/indicator/ema_analysis.rb
55
- - lib/sqa/indicator/fibonacci_retracement.md
65
+ - lib/sqa/indicator/elliott_wave_theory.rb
66
+ - lib/sqa/indicator/exponential_moving_average.rb
67
+ - lib/sqa/indicator/exponential_moving_average_trend.rb
56
68
  - lib/sqa/indicator/fibonacci_retracement.rb
57
- - lib/sqa/indicator/head_and_shoulders_pattern.md
58
69
  - lib/sqa/indicator/head_and_shoulders_pattern.rb
59
- - lib/sqa/indicator/identify_wave_condition.md
60
- - lib/sqa/indicator/identify_wave_condition.rb
61
- - lib/sqa/indicator/mean_reversion.md
70
+ - lib/sqa/indicator/market_profile.rb
62
71
  - lib/sqa/indicator/mean_reversion.rb
63
- - lib/sqa/indicator/momentum.md
64
72
  - lib/sqa/indicator/momentum.rb
65
- - lib/sqa/indicator/moving_average_convergence_divergence.md
66
73
  - lib/sqa/indicator/moving_average_convergence_divergence.rb
67
- - lib/sqa/indicator/relative_strength_index.md
68
- - lib/sqa/indicator/relative_strength_index.md.rb
69
- - lib/sqa/indicator/simple_moving_average.md
74
+ - lib/sqa/indicator/peaks_and_valleys.rb
75
+ - lib/sqa/indicator/relative_strength_index.rb
70
76
  - lib/sqa/indicator/simple_moving_average.rb
71
77
  - lib/sqa/indicator/simple_moving_average_trend.rb
72
- - lib/sqa/indicator/stochastic_oscillator.md
73
78
  - lib/sqa/indicator/stochastic_oscillator.rb
74
- - lib/sqa/indicator/true_range.md
75
79
  - lib/sqa/indicator/true_range.rb
76
80
  - lib/sqa/protfolio.rb
77
81
  - lib/sqa/stock.rb
82
+ - lib/sqa/strategy.rb
78
83
  - lib/sqa/version.rb
79
84
  homepage: https://github.com/MadBomber/sqa
80
85
  licenses:
@@ -1,89 +0,0 @@
1
- # lib/sqa/datastore/active_record.rb
2
-
3
-
4
- require 'active_record'
5
- require 'sqlite3'
6
-
7
-
8
- module SQA::Datastore
9
- class ActiveRecord
10
- def initialize(ticker); end
11
- end
12
- end
13
-
14
-
15
- __END__
16
-
17
- # An example of how to use active record with sqlite3 ...
18
-
19
- #!/usr/bin/env ruby
20
- # See: https://gist.github.com/unnitallman/944011
21
-
22
- require 'active_record'
23
- require 'sqlite3'
24
-
25
- ActiveRecord::Base.logger = Logger.new(STDERR)
26
- # TDV ActiveRecord::Base.colorize_logging = false
27
-
28
- ActiveRecord::Base.establish_connection(
29
- adapter: "sqlite3",
30
- database: './database.db'
31
- )
32
-
33
- ActiveRecord::Schema.define do
34
- create_table :albums do |table|
35
- table.column :title, :string
36
- table.column :performer, :string
37
- end
38
-
39
- create_table :tracks do |table|
40
- table.column :album_id, :integer
41
- table.column :track_number, :integer
42
- table.column :title, :string
43
- end
44
- end
45
-
46
- class Album < ActiveRecord::Base
47
- has_many :tracks
48
- end
49
-
50
- class Track < ActiveRecord::Base
51
- belongs_to :album
52
- end
53
-
54
- album = Album.create(:title => 'Black and Blue',
55
- :performer => 'The Rolling Stones')
56
- album.tracks.create(:track_number => 1, :title => 'Hot Stuff')
57
- album.tracks.create(:track_number => 2, :title => 'Hand Of Fate')
58
- album.tracks.create(:track_number => 3, :title => 'Cherry Oh Baby ')
59
- album.tracks.create(:track_number => 4, :title => 'Memory Motel ')
60
- album.tracks.create(:track_number => 5, :title => 'Hey Negrita')
61
- album.tracks.create(:track_number => 6, :title => 'Fool To Cry')
62
- album.tracks.create(:track_number => 7, :title => 'Crazy Mama')
63
- album.tracks.create(:track_number => 8,
64
- :title => 'Melody (Inspiration By Billy Preston)')
65
-
66
- album = Album.create(:title => 'Sticky Fingers',
67
- :performer => 'The Rolling Stones')
68
- album.tracks.create(:track_number => 1, :title => 'Brown Sugar')
69
- album.tracks.create(:track_number => 2, :title => 'Sway')
70
- album.tracks.create(:track_number => 3, :title => 'Wild Horses')
71
- album.tracks.create(:track_number => 4,
72
- :title => 'Can\'t You Hear Me Knocking')
73
- album.tracks.create(:track_number => 5, :title => 'You Gotta Move')
74
- album.tracks.create(:track_number => 6, :title => 'Bitch')
75
- album.tracks.create(:track_number => 7, :title => 'I Got The Blues')
76
- album.tracks.create(:track_number => 8, :title => 'Sister Morphine')
77
- album.tracks.create(:track_number => 9, :title => 'Dead Flowers')
78
- album.tracks.create(:track_number => 10, :title => 'Moonlight Mile')
79
-
80
- puts Album.find(1).tracks.length
81
- puts Album.find(2).tracks.length
82
-
83
- puts Album.find_by_title('Sticky Fingers').title
84
- puts Track.find_by_title('Fool To Cry').album_id
85
-
86
-
87
-
88
-
89
-