financial_math 0.3.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c921d52e51e5f58cc4f57b35fb3be689be412fe951b7c47c827841cfae32c69e
4
+ data.tar.gz: 36d24ce900c09e7c004e944928bb02b94d0bc02ecbaaee195ff1a0255dac2231
5
+ SHA512:
6
+ metadata.gz: 1034b3bad2c684ffb511babb43a232bf76e74bc6f8805c6f6d54e4b392ca2d7668673c40fff3e7c37f0d43bd28d986f85ae966e709d2b49e43e9fa7e71196d98
7
+ data.tar.gz: 94660004e27d53b1bf246d4f3e42e75ea16069f65abd8362f53eeb3a3456e2113be17cf60856f0d819728685b6c0fc515eea1318eb1380ad54f3bce0eb1bca8a
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at daniel.omar.vergara@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in financial_math.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ financial_math (0.3.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.8.0)
12
+ rspec-core (~> 3.8.0)
13
+ rspec-expectations (~> 3.8.0)
14
+ rspec-mocks (~> 3.8.0)
15
+ rspec-core (3.8.0)
16
+ rspec-support (~> 3.8.0)
17
+ rspec-expectations (3.8.1)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.8.0)
20
+ rspec-mocks (3.8.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-support (3.8.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.16)
30
+ financial_math!
31
+ rake (~> 10.0)
32
+ rspec (~> 3.0)
33
+
34
+ BUNDLED WITH
35
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Daniel Omar Vergara Pérez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # FinancialMath
2
+ > A set of financial equations.
3
+
4
+ This library provides a set of financial equations.
5
+ This library is based on the book titled:
6
+
7
+ ## Matemáticasfi nancieras
8
+ El valor del dinero en el tiempo
9
+
10
+ by *Zbigniew Kozikowski Zarska*
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'financial_math'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install financial_math
26
+
27
+ ## Usage
28
+
29
+ To calculate the last item of a geometric progression:
30
+
31
+ ```ruby
32
+ args = { initial_value: 1100, ratio: 1.1, times: 5 }
33
+ geometric_progression = FinancialMath::GeometricProgression.new(args)
34
+ expect(geometric_progression.last_item).to eql(1610.51)
35
+ ```
36
+
37
+ To calculate the future value:
38
+
39
+ ```ruby
40
+ args = { present_value: 100_000.0, interest_rate: 0.05, periods: 3 }
41
+ simple_interest = FinancialMath::SimpleInterest.new(args)
42
+ simple_interest.future_value
43
+ ```
44
+ ## Development
45
+
46
+ If want test this gem without clone this repo, type:
47
+
48
+ ```shell
49
+ $ gem install financial_math --dev
50
+ ```
51
+
52
+ This command will get the development dependencies installed too.
53
+
54
+ ## Release History
55
+
56
+ * 0.3.1
57
+ * CHANGE: Update docs (module code remains unchanged)
58
+ * 0.3.0
59
+ * ADD: Add `SimpleInterest` class
60
+ * 0.3.0
61
+ * ADD: Add `GEometricProgression` class
62
+ * 0.2.0
63
+ * ADD: Add `ArithemeticProgression` class
64
+ * 0.1.0
65
+ * The first proper release
66
+ * ADD: The basic file with basic equations
67
+ * 0.0.1
68
+ * Work in progress
69
+
70
+ ## Meta
71
+
72
+ Daniel Omar Vergara Pérez – [@dan1_net](https://twitter.com/dan1_net) – daniel.omar.vergara@gmail.com
73
+
74
+ [https://github.com/dany2691/](https://github.com/dany2691/)
75
+
76
+ ## Contributing
77
+
78
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dany2691/financial_math. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
79
+
80
+ ## Contributing
81
+
82
+ 1. Fork it (<https://github.com/dany2691/financial_math/fork>)
83
+ 2. Create your feature branch (`git checkout -b feature/fooBar`)
84
+ 3. Commit your changes (`git commit -am 'Add some fooBar'`)
85
+ 4. Push to the branch (`git push origin feature/fooBar`)
86
+ 5. Create a new Pull Request
87
+
88
+ ## License
89
+
90
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
91
+
92
+ ## Code of Conduct
93
+
94
+ Everyone interacting in the FinancialMath project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/financial_math/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "financial_math"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "financial_math/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "financial_math"
8
+ spec.version = FinancialMath::VERSION
9
+ spec.authors = ["Daniel Omar Vergara Pérez"]
10
+ spec.email = ["daniel.omar.vergara@gmail.com"]
11
+
12
+ spec.summary = %q{Financial equations}
13
+ spec.description = %q{Set of financial functions}
14
+ spec.homepage = "https://github.com/dany2691/financial_math"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.16"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+ end
@@ -0,0 +1,19 @@
1
+ module FinancialMath
2
+ class ArithmeticProgression
3
+ attr_reader :distance, :times, :initial_value
4
+
5
+ def initialize(args)
6
+ @distance = args.fetch(:distance, 1)
7
+ @times = args.fetch(:times, 1)
8
+ @initial_value = args.fetch(:initial_value, 0)
9
+ end
10
+
11
+ def last_item
12
+ (initial_value + (times - 1.0) * distance).round(2)
13
+ end
14
+
15
+ def sum
16
+ (times / 2.0 * (initial_value + last_item)).round(2)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal :true
2
+
3
+ # Basic financial functions
4
+ module FinancialMath
5
+ # A class that contains basic functions in finance
6
+ def self.geometric_mean(growth_rates)
7
+ raw_geometric_mean(growth_rates).round(4)
8
+ end
9
+
10
+ def self.continuous_capitalization(initial_value, rate, time)
11
+ (initial_value * Math.exp(rate * time)).round(2)
12
+ end
13
+
14
+ def self.raw_geometric_mean(growth_rates)
15
+ growth_rates.map { |i| i + 1 }.inject(:*)**(1.0 / growth_rates.size) - 1
16
+ end
17
+ end
18
+
19
+ # module FinancialMath
20
+ # # A class that contains basic functions in finance
21
+ # class Basics
22
+ # def self.geometric_mean(growth_rates)
23
+ # raw_geometric_mean(growth_rates).round(4)
24
+ # end
25
+ #
26
+ # def self.continuous_capitalization(initial_value, rate, time)
27
+ # (initial_value * Math.exp(rate * time)).round(2)
28
+ # end
29
+ #
30
+ # def self.raw_geometric_mean(growth_rates)
31
+ # growth_rates.map { |i| i + 1 }.inject(:*)**(1.0 / growth_rates.size) - 1
32
+ # end
33
+ #
34
+ # private_class_method :raw_geometric_mean
35
+ # end
36
+ # end
@@ -0,0 +1,39 @@
1
+ module FinancialMath
2
+ class GeometricProgression
3
+ attr_reader :initial_value, :ratio, :times
4
+
5
+ def initialize(args)
6
+ @initial_value = args.fetch(:initial_value, 1)
7
+ @ratio = args.fetch(:ratio, 0)
8
+ @times = args.fetch(:times, 1)
9
+ end
10
+
11
+ def last_item
12
+ (initial_value * ratio**(times - 1)).round(2)
13
+ end
14
+
15
+ def sum
16
+ if ratio > 1
17
+ growing_progression
18
+ elsif ratio < 1
19
+ decreasing_progression
20
+ elsif ratio == 1
21
+ raise ZeroDivisionError, "ratio can't be equal to one"
22
+ end
23
+ end
24
+
25
+ def infinite_decreasing_sum
26
+ initial_value / (1 - ratio)
27
+ end
28
+
29
+ private
30
+
31
+ def growing_progression
32
+ (initial_value * (ratio**times - 1.0) / (ratio - 1.0)).round(2)
33
+ end
34
+
35
+ def decreasing_progression
36
+ (initial_value * (1.0 - ratio**times) / (1.0 - ratio)).round(2)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,63 @@
1
+ module FinancialMath
2
+ class SimpleInterest
3
+ attr_reader :periods
4
+
5
+ def initialize(args)
6
+ @present_value = args.fetch(:present_value, 0)
7
+ @periods = args.fetch(:periods, 0)
8
+ @interest_rate = args.fetch(:interest_rate, 0)
9
+ @future_value = args.fetch(:future_value, 0)
10
+ @bank_discount_rate = args.fetch(:bank_discount_rate, 0)
11
+ end
12
+
13
+ def bank_discount_rate
14
+ @bank_discount_rate = (discount / future_value).round(2)
15
+ end
16
+
17
+ def discount
18
+ (@future_value - @present_value).round(2)
19
+ end
20
+
21
+ def future_value
22
+ @future_value = (@present_value * (1 + periods * @interest_rate)).round(2)
23
+ end
24
+
25
+ def future_value_in_days
26
+ @future_value = @present_value * (1 + @interest_rate * periods_in_days)
27
+ @future_value.round(2)
28
+ end
29
+
30
+ def present_value
31
+ @present_value = (@future_value / (1 + periods * @interest_rate)).round(2)
32
+ end
33
+
34
+ def present_value_in_days
35
+ @present_value = @future_value / (1 + @interest_rate * periods_in_days)
36
+ @present_value.round(2)
37
+ end
38
+
39
+ def rational_discount_in_days
40
+ (@present_value * @interest_rate * @periods_in_days).round(2)
41
+ end
42
+
43
+ def bank_discount_in_days
44
+ (@future_value * @bank_discount_rate * @periods_in_days).round(2)
45
+ end
46
+
47
+ def interest_rate_given_discount_rate
48
+ divisor = 1 - @bank_discount_rate * periods_in_days
49
+ @interest_rate = (@bank_discount_rate / divisor).round(2)
50
+ end
51
+
52
+ def discount_rate_given_interest_rate
53
+ divisor = 1 + @interest_rate * periods_in_days
54
+ @bank_discount_rate = (@interest_rate / divisor).round(2)
55
+ end
56
+
57
+ private
58
+
59
+ def periods_in_days
60
+ periods / 360.0
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,3 @@
1
+ module FinancialMath
2
+ VERSION = '0.3.1'
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'financial_math/version'
2
+ require 'financial_math/basics'
3
+ require 'financial_math/geometric_progression'
4
+ require 'financial_math/arithmetic_progression'
5
+ require 'financial_math/simple_interest'
6
+
7
+ module FinancialMath
8
+ # Your code goes here...
9
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: financial_math
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Omar Vergara Pérez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Set of financial functions
56
+ email:
57
+ - daniel.omar.vergara@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - financial_math.gemspec
74
+ - lib/financial_math.rb
75
+ - lib/financial_math/arithmetic_progression.rb
76
+ - lib/financial_math/basics.rb
77
+ - lib/financial_math/geometric_progression.rb
78
+ - lib/financial_math/simple_interest.rb
79
+ - lib/financial_math/version.rb
80
+ homepage: https://github.com/dany2691/financial_math
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.7.7
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Financial equations
104
+ test_files: []