quantitative 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/Rakefile +29 -0
- data/lib/quant/mixins/stochastic.rb +15 -19
- data/lib/quant/time_period.rb +10 -2
- data/lib/quant/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7ddfcfd200564c3ce9764a7ba635635c56649c6681ac6d76b93390734da4fc9
|
4
|
+
data.tar.gz: 04d93778a91c74ee4c3459009f4990644121974b77079d79a3816c5f63a63f6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8facaa3efaef73c00f98f03b4482b876cf9a6155f46fb56f1c0d3534c996b6c33fefa067ee07ef8f326e76dfbdd41b0fa7d04f349eef49add179444bbe0d9db6
|
7
|
+
data.tar.gz: 3fa7bb3d2e34cd3f2ebd718105ab20ffb60e044c45fb5c3909a14cdd1d2876288ae23d4eb7c4211f35890ddd250772068f1c0e0463db71d1c84c490a06edc2d8
|
data/Gemfile.lock
CHANGED
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
|
-
|
7
|
-
stoch_period = [points.size, period.to_i].min
|
8
|
-
return 0.0 if stoch_period < 1
|
6
|
+
using Quant
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
19
|
-
|
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
|
data/lib/quant/time_period.rb
CHANGED
@@ -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
|
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
|
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
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.
|
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-
|
11
|
+
date: 2024-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|