finance_rb 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +21 -0
- data/lib/finance/calculations.rb +30 -0
- data/lib/finance/loan.rb +13 -0
- data/lib/finance/version.rb +5 -0
- data/lib/finance_rb.rb +4 -0
- data/spec/finance/calculations_spec.rb +21 -0
- data/spec/spec_helper.rb +16 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6fa908552e787182999bb782ed6c7f7f624307f0acd77ff969c0171e07dd0179
|
4
|
+
data.tar.gz: e0492ef3dd7baa271a4d7893ff32c5c94de852d2328d1c49321bb1d78147f08e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ccc866a27aecf49b0f869f9ddf590ac58d7682bc35c30a5abfda526251b800960b143fa19b05063411e30061a96f950963c4f8c38d867da763b1654ec77bfb52
|
7
|
+
data.tar.gz: 5ca7d064faf5bb38ad5cd70ddb1595d8983833e4ad9b46290f17b9f5ca8eee2abd4e4c99eedf852bbf79790c28d54e4aa4743beeffbf72921ff0dccc95f1cc94
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Vladislav
|
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,21 @@
|
|
1
|
+
# finance_rb
|
2
|
+
|
3
|
+
This package is a ruby native port of the numpy-financial package with some helpful additional functions.
|
4
|
+
|
5
|
+
The functions in this package are a scalar version of their vectorised counterparts in the [numpy-financial](https://github.com/numpy/numpy-financial) library.
|
6
|
+
|
7
|
+
Currently, only some functions are ported,
|
8
|
+
which are as follows:
|
9
|
+
|
10
|
+
| numpy-financial function | ruby native function ported? | info|
|
11
|
+
|:------------------------: |:------------------: | :------------------|
|
12
|
+
| fv | | Computes the future value|
|
13
|
+
| ipmt | | Computes interest payment for a loan|
|
14
|
+
| pmt | | Computes the fixed periodic payment(principal + interest) made against a loan amount|
|
15
|
+
| ppmt | | Computes principal payment for a loan|
|
16
|
+
| nper | | Computes the number of periodic payments|
|
17
|
+
| pv | | Computes the present value of a payment|
|
18
|
+
| rate | | Computes the rate of interest per period|
|
19
|
+
| irr | | Computes the internal rate of return|
|
20
|
+
| npv | ✅ | Computes the net present value of a series of cash flow|
|
21
|
+
| mirr | | Computes the modified internal rate of return|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Finance
|
4
|
+
class Calculations
|
5
|
+
class << self
|
6
|
+
# Npv computes the Net Present Value of a cash flow series.
|
7
|
+
# @return [Numeric] The NPV of the input cash flow series `values` at the discount `rate`.
|
8
|
+
#
|
9
|
+
# @param [Numeric] :rate A discount rate applied once per period.
|
10
|
+
# @param [Array<Numeric>] :values The values of the time series of cash flows.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# require 'finance_rb'
|
14
|
+
# Finance::Calculations.npv(0.1, [-1000, 100, 100, 100]) #=> -789.3518518518517
|
15
|
+
#
|
16
|
+
# @see http://en.wikipedia.org/wiki/Net_present_value
|
17
|
+
# @see L. J. Gitman, “Principles of Managerial Finance, Brief,” 3rd ed.,
|
18
|
+
# Addison-Wesley, 2003, pg. 346.
|
19
|
+
def npv(rate, values)
|
20
|
+
npv_value = 0.0
|
21
|
+
values.each_with_index do |current_value, pow_index|
|
22
|
+
npv_value += current_value / (1.0 + rate) ** pow_index
|
23
|
+
end
|
24
|
+
npv_value
|
25
|
+
end
|
26
|
+
|
27
|
+
alias net_present_value npv
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/finance/loan.rb
ADDED
data/lib/finance_rb.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Finance::Calculations do
|
4
|
+
describe '#npv' do
|
5
|
+
it 'calculates correct npv value' do
|
6
|
+
expect(Finance::Calculations.npv(0.2, [-1000, 100, 100, 100])).to eq(-789.3518518518517)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'is available through alias name' do
|
10
|
+
expect(
|
11
|
+
Finance::Calculations.net_present_value(0.1, [-100, 6, 6, 6])
|
12
|
+
).to eq(-85.07888805409468)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'returns correct npv for zero rates' do
|
16
|
+
expect(
|
17
|
+
Finance::Calculations.net_present_value(0.0, [-2000, 55, 55, 55])
|
18
|
+
).to eq(-1835.0)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "finance/calculations"
|
4
|
+
require "finance/loan"
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
# Enable flags like --only-failures and --next-failure
|
8
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
9
|
+
|
10
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
11
|
+
config.disable_monkey_patching!
|
12
|
+
|
13
|
+
config.expect_with :rspec do |c|
|
14
|
+
c.syntax = :expect
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: finance_rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vlad Dyachenko
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-03-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A ruby port of numpy-financial functions. This library provides a Ruby
|
14
|
+
interface for working with interest rates, mortgage amortization, and cashflows
|
15
|
+
and other stuff from finance.
|
16
|
+
email:
|
17
|
+
- vla-dy@yandex.ru
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- CHANGELOG.md
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- lib/finance/calculations.rb
|
26
|
+
- lib/finance/loan.rb
|
27
|
+
- lib/finance/version.rb
|
28
|
+
- lib/finance_rb.rb
|
29
|
+
- spec/finance/calculations_spec.rb
|
30
|
+
- spec/spec_helper.rb
|
31
|
+
homepage: https://github.com/wowinter13/finance_rb
|
32
|
+
licenses:
|
33
|
+
- MIT
|
34
|
+
metadata:
|
35
|
+
bug_tracker_uri: https://github.com/wowinter13/finance_rb/issues
|
36
|
+
changelog_uri: https://github.com/wowinter13/finance_rb/blob/v0.0.2/CHANGELOG.md
|
37
|
+
documentation_uri: https://www.rubydoc.info/wowinter13/finance_rb/0.0.2
|
38
|
+
source_code_uri: https://github.com/wowinter13/finance_rb/tree/v0.0.2
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.4.0
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubygems_version: 3.2.15
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: A library for finance manipulations in Ruby.
|
58
|
+
test_files:
|
59
|
+
- spec/finance/calculations_spec.rb
|
60
|
+
- spec/spec_helper.rb
|