exonio 0.1.1 → 0.2.0
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/README.md +14 -1
- data/lib/exonio/financial.rb +22 -0
- data/lib/exonio/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9595c1bffef30730dadb4b4274742bc3113ef5e
|
4
|
+
data.tar.gz: 335f53e02bb83504bfcaaa8186d0debfeb7f09cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e656084a10f77e0d48f7a32be71625863a6427bc34532229daf3692fef734784b9d0ded1ed556f67304ef9cbefb890d659fba7dcb3c6b94fa216cc752d67af02
|
7
|
+
data.tar.gz: 53bf0c5c0f905d0d86d1f7deb15b3e3c9cbffa4c7134ca6dbd92129ca62c797359688ef74e19943e6b4a7b662e6939935291357107741b481836f446e4816d28
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -67,6 +67,20 @@ In order to pay-off (i.e., have a future-value of 0) the $200,000 obtained
|
|
67
67
|
today, a monthly payment of $1,854.02 would be required. Note that this
|
68
68
|
example illustrates usage of `fv` (future value) having a default value of 0.
|
69
69
|
|
70
|
+
### PV
|
71
|
+
|
72
|
+
What is the present value (e.g., the initial investment) of an investment
|
73
|
+
that needs to total $20,000.00 after 10 years of saving $100 every month?
|
74
|
+
Assume the interest rate is 5% (annually) compounded monthly.
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
Exonio.pv(0.05 / 12, 12 * 10, -100, 20_000) # ==> -2715.0857731569663
|
78
|
+
```
|
79
|
+
|
80
|
+
By convention, the negative sign represents cash flow out (i.e., money not available today).
|
81
|
+
Thus, to end up with $20,000.00 in 10 years saving $100 a month at 5% annual
|
82
|
+
interest, an initial deposit of $2715,09 should be made.
|
83
|
+
|
70
84
|
## TODO
|
71
85
|
|
72
86
|
There's a lot of formulas to be implemented, including:
|
@@ -82,7 +96,6 @@ There's a lot of formulas to be implemented, including:
|
|
82
96
|
* MIRR
|
83
97
|
* NPV
|
84
98
|
* PPMT
|
85
|
-
* PV
|
86
99
|
* RATE
|
87
100
|
* SLN
|
88
101
|
* SYD
|
data/lib/exonio/financial.rb
CHANGED
@@ -66,5 +66,27 @@ module Exonio
|
|
66
66
|
|
67
67
|
-(fv + pv * temp) / fact
|
68
68
|
end
|
69
|
+
|
70
|
+
# Calculates the present value of an annuity investment based on
|
71
|
+
# constant-amount periodic payments and a constant interest rate.
|
72
|
+
#
|
73
|
+
# @param rate [Float] The interest rate as decimal (not per cent) per period
|
74
|
+
# @param nper [Integer] The number of payments to be made (number of periods)
|
75
|
+
# @param pmt [Float] The amount per period to be paid
|
76
|
+
# @param fv [Float] The future value remaining after the final payment has been made
|
77
|
+
# @param end_or_begining [Integer] Whether payments are due at the end (0) or
|
78
|
+
# beggining (1) of each period
|
79
|
+
#
|
80
|
+
# @return [Float]
|
81
|
+
#
|
82
|
+
# @example
|
83
|
+
# Exonio.pv(0.05/12, 12*10, -100, 20_000) # ==> -2715.0857731569663
|
84
|
+
#
|
85
|
+
def pv(rate, nper, pmt, fv = 0, end_or_beginning = 0)
|
86
|
+
temp = (1 + rate) ** nper
|
87
|
+
fact = (1 + rate * end_or_beginning) * (temp - 1) / rate
|
88
|
+
|
89
|
+
-(fv + pmt * fact) / temp
|
90
|
+
end
|
69
91
|
end
|
70
92
|
end
|
data/lib/exonio/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exonio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafael Izidoro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|