quantitative 0.1.8 → 0.1.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7491465248d383f459899467e14c9bafa16376f8fe7dc2cac657fca8a9170200
4
- data.tar.gz: 956074c17983ee22d6480a176c48b0cc15257aaca2649086eacc71a52688cb12
3
+ metadata.gz: f7ddfcfd200564c3ce9764a7ba635635c56649c6681ac6d76b93390734da4fc9
4
+ data.tar.gz: 04d93778a91c74ee4c3459009f4990644121974b77079d79a3816c5f63a63f6c
5
5
  SHA512:
6
- metadata.gz: 0f932bc68ca6f3e47261aaf2d19b34465b0f242bc13b5935ab55c0eea0ee736b0ea183b4bacc6a99d9beecd9a2457dd07957a639bd2d85e35f0a5584b35c2f2a
7
- data.tar.gz: c0baa0af0133cbdd46439fc0ce8d068a583f05688371025275afe4297d0bd01a7aad90c4f3ebae98afaa1a4b28b56e43fa2aa68aaafc018bd34e22ec037d1b07
6
+ metadata.gz: 8facaa3efaef73c00f98f03b4482b876cf9a6155f46fb56f1c0d3534c996b6c33fefa067ee07ef8f326e76dfbdd41b0fa7d04f349eef49add179444bbe0d9db6
7
+ data.tar.gz: 3fa7bb3d2e34cd3f2ebd718105ab20ffb60e044c45fb5c3909a14cdd1d2876288ae23d4eb7c4211f35890ddd250772068f1c0e0463db71d1c84c490a06edc2d8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- quantitative (0.1.8)
4
+ quantitative (0.1.9)
5
5
  oj (~> 3.10)
6
6
 
7
7
  GEM
data/Rakefile CHANGED
@@ -10,3 +10,32 @@ require "rubocop/rake_task"
10
10
  RuboCop::RakeTask.new
11
11
 
12
12
  task default: %i[spec rubocop]
13
+
14
+ namespace :gem do
15
+ desc "Build the gem"
16
+ task :build do
17
+ sh "gem build quantitative.gemspec"
18
+ end
19
+
20
+ desc "Tag the release in git"
21
+ task :tag do
22
+ version = Quant::VERSION
23
+ sh "git tag -a v#{version} -m 'Release #{version}'"
24
+ sh "git push origin v#{version}"
25
+ end
26
+
27
+ desc "Install local *.gem file"
28
+ task :install do
29
+ sh "gem install quantitative-#{Quant::VERSION}.gem"
30
+ end
31
+
32
+ desc "Remove local *.gem files"
33
+ task :clean do
34
+ sh "rm -f quantitative-#{Quant::VERSION}.gem"
35
+ end
36
+
37
+ desc "Release #{Quant::VERSION} to rubygems.org"
38
+ task release: [:build, :tag] do
39
+ sh "gem push quantitative-#{Quant::VERSION}.gem"
40
+ end
41
+ end
@@ -3,28 +3,24 @@
3
3
  module Quant
4
4
  module Mixins
5
5
  module Stochastic
6
- def stochastic(source, period = max_period)
7
- stoch_period = [points.size, period.to_i].min
8
- return 0.0 if stoch_period < 1
6
+ using Quant
9
7
 
10
- subset = points[-stoch_period, stoch_period].map{ |p| p.send(source) }
11
- ll = subset.min
12
- hh = subset.max
8
+ # The Stochastic Oscillator is a momentum indicator that compares a particular
9
+ # closing price of a security to a range of its prices over a certain
10
+ # period of time. It was developed by George C. Lane in the 1950s.
13
11
 
14
- v0 = points[-1].send(source)
15
- (hh - ll).zero? ? 0.0 : 100.0 * (v0 - ll) / (hh - ll)
16
- end
12
+ # The main idea behind the Stochastic Oscillator is that closing
13
+ # prices should close near the same direction as the current trend.
14
+ # In a market trending up, prices will likely close near their
15
+ # high, and in a market trending down, prices close near their low.
16
+ def stochastic(source, period:)
17
+ subset = values.last(period).map{ |p| p.send(source) }
18
+
19
+ lowest, highest = subset.minimum, subset.maximum
20
+ return 0.0 if (highest - lowest).zero?
17
21
 
18
- # module Fields
19
- # @[JSON::Field(key: "ish")]
20
- # property inst_stoch : Float64 = 0.0
21
- # @[JSON::Field(key: "sh")]
22
- # property stoch : Float64 = 0.0
23
- # @[JSON::Field(key: "su")]
24
- # property stoch_up : Bool = false
25
- # @[JSON::Field(key: "st")]
26
- # property stoch_turned : Bool = false
27
- # end
22
+ 100.0 * (subset[-1] - lowest) / (highest - lowest)
23
+ end
28
24
  end
29
25
  end
30
26
  end
@@ -16,13 +16,21 @@ module Quant
16
16
  def as_start_time(value)
17
17
  return value if value.nil? || value.is_a?(Time)
18
18
 
19
- value.is_a?(Date) ? value.to_time.beginning_of_day : value.to_time
19
+ value.is_a?(Date) ? beginning_of_day(value) : value.to_time
20
20
  end
21
21
 
22
22
  def as_end_time(value)
23
23
  return value if value.nil? || value.is_a?(Time)
24
24
 
25
- value.is_a?(Date) ? value.to_time.end_of_day : value.to_time
25
+ value.is_a?(Date) ? end_of_day(value) : value.to_time
26
+ end
27
+
28
+ def end_of_day(date)
29
+ Time.utc(date.year, date.month, date.day, 23, 59, 59)
30
+ end
31
+
32
+ def beginning_of_day(date)
33
+ Time.utc(date.year, date.month, date.day)
26
34
  end
27
35
 
28
36
  def validate_bounds!
data/lib/quant/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Quant
4
- VERSION = "0.1.8"
4
+ VERSION = "0.1.9"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quantitative
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Lang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-27 00:00:00.000000000 Z
11
+ date: 2024-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj