fintools 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/fintools.rb +53 -0
  3. metadata +72 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cceabbe4a44637ad58978d1d3460c6884aefb7fc
4
+ data.tar.gz: 00a526dc2d175520c28b09078bbbc1f2f8533471
5
+ SHA512:
6
+ metadata.gz: 2596c0e42c4dab0337ac43764432787fc9c3d95f0988b29553827d6b8314627c3dbdc9988cbc12209ad904fcb0e94639878302fba8dd6cb63e1bd621fb192cf8
7
+ data.tar.gz: 23ac128946e13ab08322a97745945221dda02b983e9f8ea6561bdb33714723b7fcec7189fdd9f99a39b6598b4bc7e8ae4701454b1c5a19e0f15527b4e3dd9096
@@ -0,0 +1,53 @@
1
+ require 'indicators'
2
+
3
+ class FinTools
4
+
5
+ def sum(arr)
6
+ arr.inject(0) { | accum, i | accum + i
7
+ }
8
+ end
9
+
10
+ def mean(arr)
11
+ arr.sum / arr.length.to_f
12
+ end
13
+
14
+ def sample_variance(arr)
15
+ m = mean(arr)
16
+ sum = arr.inject(0) { | accum, i |
17
+ accum + (i - m) ** 2
18
+ }
19
+ sum / (arr.length - 1).to_f
20
+ end
21
+
22
+ def standard_deviation(arr)
23
+ return Math.sqrt(sample_variance(arr))
24
+ end
25
+
26
+ def histvola(values)
27
+ stddev = standard_deviation(values)
28
+ return stddev * Math.sqrt(254)
29
+ end
30
+
31
+ # returns is an array of returns(percent)
32
+ def sharpe_ratio(rets)
33
+ return mean(rets) / standard_deviation(rets)
34
+ end
35
+
36
+ ####
37
+ def calc_ema(arr, period)
38
+ my_data = Indicators::Data.new(arr)
39
+ return my_data.calc(:type => :ema, :params => period).output
40
+ end
41
+
42
+ ####
43
+ def calcMACD(price_arr, ema_long, ema_short, ema_diff)
44
+ closing_prices = price_arr.map { | r |
45
+ r[:cls]
46
+ }
47
+ ema26 = calc_ema(closing_prices, ema_long)
48
+ ema12 = calc_ema(closing_prices, ema_short)
49
+
50
+ return calc_ema(closing_prices, ema_diff)
51
+ end
52
+
53
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fintools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Peter Andersson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: indicators
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: indicators
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A Collection of financial tools in Ruby. Things like SMA, EMA, MACD etc
42
+ email: fshsweden@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/fintools.rb
48
+ homepage: http://rubygems.org/gems/fintools
49
+ licenses:
50
+ - MIT
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.6.8
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Financial Tools in Ruby
72
+ test_files: []