au_loan_calculations 0.1.6
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 +7 -0
- data/README.md +69 -0
- data/assets/csvs/payg_tax_rates/2018.csv +6 -0
- data/lib/au_loan_calculations.rb +10 -0
- data/lib/au_loan_calculations/exception/asset_not_found_error.rb +9 -0
- data/lib/au_loan_calculations/income.rb +44 -0
- data/lib/au_loan_calculations/loan.rb +31 -0
- data/lib/au_loan_calculations/parse.rb +62 -0
- data/lib/au_loan_calculations/version.rb +3 -0
- metadata +99 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 92c63ef9ede64da1ff83e5f31c5c43381904d6c1b826c497a9208b4326f8becb
|
|
4
|
+
data.tar.gz: 75dc94b341e28b6ed20cd39a174055de6dbf2044a210c6d9ad98ab23e2afb29b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e3175a983c5ad867ecb92986b4c8d66bc37020e381bf9e5dadf9096265254ab1f7940f67561a1b8936803af713df3c29f1590649f4d7b90b44d6d9510e61d6d0
|
|
7
|
+
data.tar.gz: c81e2c4cfa1c1e397e999264e39b963601f15fbc56d0a9d5fff529ea52127f45d4f0cb59069a4332dfc304b39cae1a84b05229a80a3df382d0beea3e10591c29
|
data/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# HomeLoan
|
|
2
|
+
|
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/home_loan`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
|
+
|
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'au_loan_calculations'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install au_loan_calculations
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
#### How to calculate monthly repayment for a Loan
|
|
26
|
+
|
|
27
|
+
To calculate the monthly repayment value for a loan call the following class method:
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
AuLoanCalculations::Loan.calculate_monthly_repayment(repayment_type, interest_rate, loan_amount, period=360, iop=0, future_value=0, type=0)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
#### How to convert an amount frequency
|
|
34
|
+
|
|
35
|
+
Convert an amount to other frequency:
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
AuLoanCalculations::Parse.convert_amount(amount, frequency, convert_to)
|
|
39
|
+
```
|
|
40
|
+
The allowed values for **frequency** and **convert_to** are: `weekly`, `fortnightly`, `monthly` and `yearly`.
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
#### How to calculate the PAYG NET income value
|
|
44
|
+
|
|
45
|
+
To calculate the PAYG NET income value call the class method:
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
AuLoanCalculations::Income.calculate_payg_net_value(value, year*)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The `year` parameter is optional. Its default value is the current year.
|
|
52
|
+
|
|
53
|
+
## Development
|
|
54
|
+
|
|
55
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
56
|
+
|
|
57
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
58
|
+
|
|
59
|
+
## Contributing
|
|
60
|
+
|
|
61
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/home_loan. 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.
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
66
|
+
|
|
67
|
+
## Code of Conduct
|
|
68
|
+
|
|
69
|
+
Everyone interacting in the HomeLoan project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/home_loan/blob/master/CODE_OF_CONDUCT.md).
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
require "au_loan_calculations/exception/asset_not_found_error"
|
|
2
|
+
|
|
3
|
+
require "au_loan_calculations/version"
|
|
4
|
+
require "au_loan_calculations/loan"
|
|
5
|
+
require "au_loan_calculations/parse"
|
|
6
|
+
require "au_loan_calculations/income"
|
|
7
|
+
|
|
8
|
+
module AuLoanCalculations
|
|
9
|
+
|
|
10
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'date'
|
|
2
|
+
require 'csv'
|
|
3
|
+
|
|
4
|
+
module AuLoanCalculations
|
|
5
|
+
class Income
|
|
6
|
+
|
|
7
|
+
def self.calculate_payg_net_value(value, year=Date.today.year)
|
|
8
|
+
begin
|
|
9
|
+
# income_tax_rates_file = CSV.read("vendor/assets/csvs/payg_tax_rates/#{year.to_s}.csv", { headers: true })
|
|
10
|
+
gem_path ||= File.expand_path '..', File.dirname(__FILE__)
|
|
11
|
+
assets_path ||= File.join gem_path, "../assets"
|
|
12
|
+
file = File.join assets_path, "csvs/payg_tax_rates/#{year.to_s}.csv"
|
|
13
|
+
|
|
14
|
+
income_tax_rates_file = CSV.read(file, { headers: true })
|
|
15
|
+
|
|
16
|
+
income_tax_rates_file.each do |income_tax_rate|
|
|
17
|
+
|
|
18
|
+
# check the income tax rate
|
|
19
|
+
if value >= income_tax_rate["min_value"].to_i && value <= income_tax_rate["max_value"].to_i
|
|
20
|
+
|
|
21
|
+
# calculate the taxable value
|
|
22
|
+
tax_over_threshold = value - income_tax_rate["threshold"].to_i
|
|
23
|
+
|
|
24
|
+
# sum the taxable value plus range tax value
|
|
25
|
+
tax_value = tax_over_threshold * income_tax_rate["tax_per_dollar_over_threshold"].to_f
|
|
26
|
+
|
|
27
|
+
# calculate medicare levy value
|
|
28
|
+
medicare_levy_value = (value * income_tax_rate["medicare_levy_percentage"].to_f) / 100
|
|
29
|
+
|
|
30
|
+
# calculate total tax (including medicare levy value)
|
|
31
|
+
total_tax = income_tax_rate["tax_over_threshold"].to_i + tax_value + medicare_levy_value
|
|
32
|
+
|
|
33
|
+
# income value - total tax
|
|
34
|
+
return (value - total_tax)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
rescue Errno::ENOENT
|
|
39
|
+
raise AuLoanCalculations::Exception::AssetNotFoundError, "Unable to find the income tax rates for #{year}."
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module AuLoanCalculations
|
|
2
|
+
class Loan
|
|
3
|
+
|
|
4
|
+
# period - number of periods (months)
|
|
5
|
+
# interest_only_period - interest only period (years)
|
|
6
|
+
# type - when the payments are due:
|
|
7
|
+
# 0: end of the period, e.g. end of month (default)
|
|
8
|
+
# 1: beginning of period
|
|
9
|
+
def self.calculate_monthly_repayment(repayment_type, interest_rate, loan_amount, period=360, iop=0, future_value=0, type=0)
|
|
10
|
+
interest_rate = (interest_rate / 100) / 12
|
|
11
|
+
|
|
12
|
+
if repayment_type == "interest_only"
|
|
13
|
+
interest_only_period = iop
|
|
14
|
+
period = period - (interest_only_period * 12)
|
|
15
|
+
else
|
|
16
|
+
period = period
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
return -(loan_amount + future_value)/period if interest_rate == 0
|
|
21
|
+
|
|
22
|
+
pvif = ((1 + interest_rate) ** period)
|
|
23
|
+
pmt = - interest_rate * loan_amount * ( pvif + future_value ) / ( pvif - 1 )
|
|
24
|
+
|
|
25
|
+
pmt = pmt / (1 + interest_rate) if type == 1
|
|
26
|
+
|
|
27
|
+
return pmt.round(2).abs
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module AuLoanCalculations
|
|
2
|
+
class Parse
|
|
3
|
+
|
|
4
|
+
# the amount to be converted.
|
|
5
|
+
# the current frequency - allowed values: weekly, fortnightly, monthly, yearly
|
|
6
|
+
# the frequency the amount should be converted - allowed values: weekly, fortnightly, monthly, yearly
|
|
7
|
+
def self.convert_amount(amount, frequency, convert_to)
|
|
8
|
+
value = case convert_to
|
|
9
|
+
when 'weekly'
|
|
10
|
+
case frequency
|
|
11
|
+
when 'fortnightly'
|
|
12
|
+
amount / 2
|
|
13
|
+
when 'monthly'
|
|
14
|
+
(amount * 12) / 52
|
|
15
|
+
when 'yearly'
|
|
16
|
+
amount / 52
|
|
17
|
+
else
|
|
18
|
+
amount
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
when 'fortnightly'
|
|
22
|
+
case frequency
|
|
23
|
+
when 'weekly'
|
|
24
|
+
amount * 2
|
|
25
|
+
when 'monthly'
|
|
26
|
+
(amount * 12) / 26
|
|
27
|
+
when 'yearly'
|
|
28
|
+
amount / 26
|
|
29
|
+
else
|
|
30
|
+
amount
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
when 'monthly'
|
|
34
|
+
case frequency
|
|
35
|
+
when 'weekly'
|
|
36
|
+
(amount * 52) / 12
|
|
37
|
+
when 'fortnightly'
|
|
38
|
+
(amount * 26) / 12
|
|
39
|
+
when 'yearly'
|
|
40
|
+
amount / 12
|
|
41
|
+
else
|
|
42
|
+
amount
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
when 'yearly'
|
|
46
|
+
case frequency
|
|
47
|
+
when 'weekly'
|
|
48
|
+
amount * 52
|
|
49
|
+
when 'fortnightly'
|
|
50
|
+
amount * 26
|
|
51
|
+
when 'monthly'
|
|
52
|
+
amount * 12
|
|
53
|
+
else
|
|
54
|
+
amount
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
value.round(2)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: au_loan_calculations
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.6
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Andre Possebom
|
|
8
|
+
- Pedro Pereira Santos
|
|
9
|
+
- Rod Dutra
|
|
10
|
+
autorequire:
|
|
11
|
+
bindir: exe
|
|
12
|
+
cert_chain: []
|
|
13
|
+
date: 2018-02-20 00:00:00.000000000 Z
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: bundler
|
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
|
18
|
+
requirements:
|
|
19
|
+
- - "~>"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '1.16'
|
|
22
|
+
type: :development
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - "~>"
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '1.16'
|
|
29
|
+
- !ruby/object:Gem::Dependency
|
|
30
|
+
name: rake
|
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
|
32
|
+
requirements:
|
|
33
|
+
- - "~>"
|
|
34
|
+
- !ruby/object:Gem::Version
|
|
35
|
+
version: '10.0'
|
|
36
|
+
type: :development
|
|
37
|
+
prerelease: false
|
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - "~>"
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '10.0'
|
|
43
|
+
- !ruby/object:Gem::Dependency
|
|
44
|
+
name: rspec
|
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - "~>"
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '3.0'
|
|
50
|
+
type: :development
|
|
51
|
+
prerelease: false
|
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - "~>"
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: '3.0'
|
|
57
|
+
description: AuLoanCalculations library contains a couple of useful functions for
|
|
58
|
+
Austrlian home loans.
|
|
59
|
+
email:
|
|
60
|
+
- andre@loandolphin.com.au
|
|
61
|
+
- pedro@loandolphin.com.au
|
|
62
|
+
- rod@loandolphin.com.au
|
|
63
|
+
executables: []
|
|
64
|
+
extensions: []
|
|
65
|
+
extra_rdoc_files: []
|
|
66
|
+
files:
|
|
67
|
+
- README.md
|
|
68
|
+
- assets/csvs/payg_tax_rates/2018.csv
|
|
69
|
+
- lib/au_loan_calculations.rb
|
|
70
|
+
- lib/au_loan_calculations/exception/asset_not_found_error.rb
|
|
71
|
+
- lib/au_loan_calculations/income.rb
|
|
72
|
+
- lib/au_loan_calculations/loan.rb
|
|
73
|
+
- lib/au_loan_calculations/parse.rb
|
|
74
|
+
- lib/au_loan_calculations/version.rb
|
|
75
|
+
homepage: https://github.com/possebom/au_loan_calculations_gem
|
|
76
|
+
licenses:
|
|
77
|
+
- MIT
|
|
78
|
+
metadata: {}
|
|
79
|
+
post_install_message:
|
|
80
|
+
rdoc_options: []
|
|
81
|
+
require_paths:
|
|
82
|
+
- lib
|
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - ">="
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: '0'
|
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
|
+
requirements:
|
|
90
|
+
- - ">="
|
|
91
|
+
- !ruby/object:Gem::Version
|
|
92
|
+
version: '0'
|
|
93
|
+
requirements: []
|
|
94
|
+
rubyforge_project:
|
|
95
|
+
rubygems_version: 2.7.5
|
|
96
|
+
signing_key:
|
|
97
|
+
specification_version: 4
|
|
98
|
+
summary: This gem contains home loan functions for Australian market.
|
|
99
|
+
test_files: []
|