GithubHelp home page GithubHelp logo

roniemartinez / amortization Goto Github PK

View Code? Open in Web Editor NEW
21.0 4.0 12.0 586 KB

Python library for calculating amortizations and generating amortization schedules

License: MIT License

Python 92.01% Makefile 7.99%
amortization

amortization's Introduction

I am a software developer from the Philippines.

Philippines ๐Ÿ‡ต๐Ÿ‡ญ โžก๏ธ Germany ๐Ÿ‡ฉ๐Ÿ‡ช โžก๏ธ United Kingdom ๐Ÿ‡ฌ๐Ÿ‡ง

I am now in the UK. ๐Ÿ‡ฌ๐Ÿ‡ง

So what do I do in the world of software engineering?

Sponsors keep me motivated in writing, maintaining projects, help open source and building new things.

Buy Me A Coffee

Use my DigitalOcean referral below.

DigitalOcean Referral Badge

amortization's People

Contributors

dependabot[bot] avatar drasco64 avatar roniemartinez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

amortization's Issues

Feature request: Total interest paid at bottom

Very cool software! Thanks! <3
It would be great if at the bottom of --schedule it also listed the total Interest paid over the course of the loan?
(Oh oops I created this with the wrong github account, highlighting @jhannah which is the account I meant to use.)

Use Decimals?

Is there any particular reason you are using floats instead of decimals? I've found floating point precision in Python to be a problem, especially when working with data around finance.

calculate_amortization_amount formula is off

Example:

Principal (P) = 150,000 
Interest (i) = .01
Term (n) = 36

It took me a while to figure out why calculate_amortization_amount was returning 4,982.14 when all the online calculators were returning 4,231.21. Turns out the interest needs to be adjusted from the annual rate to the monthly rate... Not sure why this isn't more explicitly stated in the formulas, would have saved me some digging! Probably common knowledge for financial folk.

Finally, I read through this and found where it states:

"the interest rate per period is 0.06/12 since we are working with monthly payments, and our number of payments is 36, which is twelve payments per year for three years"

Anyways, long story short I think if the formula is adjusted to something like:

    adjusted_interest = interest_rate / 12
    x = (1 + adjusted_interest) ** period
    return principal * (adjusted_interest * x) / (x - 1)

It should work ๐Ÿ˜ƒ

amortization table not working

I literally copy pasted example from README and just changed the numbers and it stopped working.


from amortization.schedule import amortization_schedule
from tabulate import tabulate

principal = 450_000
interest_rate = 1 / 26 * 8.5
period = 26 * 30

table = (x for x in amortization_schedule(principal=principal, interest_rate=interest_rate, period=period))
print(
    tabulate(
        table,
        headers=["Number", "Amount", "Interest", "Principal", "Balance"],
        floatfmt=",.2f",
        numalign="right"
    )
)

I get the same numbers in all rows

Unexpected results

Either I'm misunderstanding how to use this software, or there is an issue with the numbers. When I use the sample site and enter Principle=300,000, APR=5%, Payment period = 30 years with monthly payments, I get the following (which matches what I would expect):

Number | Amortization | Interest | Principal | Balance
1 | 1,610.46 | 1,250.00 | 360.46 | 299,639.54
2 | 1,610.46 | 1,248.50 | 361.97 | 299,277.57
3 | 1,610.46 | 1,246.99 | 363.48 | 298,914.09
4 | 1,610.46 | 1,245.48 | 364.99 | 298,549.10
5 | 1,610.46 | 1,243.95 | 366.51 | 298,182.59
...
356 | 1,610.46 | 33.14 | 1,577.33 | 6,375.31
357 | 1,610.46 | 26.56 | 1,583.90 | 4,791.41
358 | 1,610.46 | 19.96 | 1,590.50 | 3,200.91
359 | 1,610.46 | 13.34 | 1,597.13 | 1,603.78
360 | 1,610.46 | 6.68 | 1,603.78 | 0.00


If I use the tool with table = (x for x in amortization_schedule(300000, 0.05, 360)), I get:

  Number     Amount    Interest    Principal     Balance
--------  ---------  ----------  -----------  ----------
       1  15,000.00   15,000.00         0.00  300,000.00
       2  15,000.00   15,000.00         0.00  300,000.00
       3  15,000.00   15,000.00         0.00  300,000.00
       4  15,000.00   15,000.00         0.00  300,000.00
       5  15,000.00   15,000.00         0.00  300,000.00
       ...
      355  15,000.00    3,806.77    11,193.23   64,942.15
     356  15,000.00    3,247.11    11,752.89   53,189.26
     357  15,000.00    2,659.46    12,340.54   40,848.72
     358  15,000.00    2,042.44    12,957.56   27,891.16
     359  15,000.00    1,394.56    13,605.44   14,285.72
     360  15,000.00      714.29    14,285.71        0.00

Feature request: Allow me to specify --payment not --period

Hello. I used your software to generate a schedule for a 15 year loan. Worked great, thanks!
But now, after payment 12, I want to make a principle-only extra payment.
So effectively I'm taking out a "new loan" with 168 payments remaining. And a lower Balance.
But my monthly payment shouldn't change, it should stay the same.
Currently --period is mandatory. It would be great if, optionally, --amount was mandatory, and Period was calculated. (I'll have a couple fewer payments to make 13 years from now. ๐Ÿ˜„)
Thanks! โค๏ธ

implicit assumptions about pay period

I get paid fornightly but apparently, there is an implicit monthly pay period in implementation

def amortization_schedule(
    principal: float, interest_rate: float, period: int
) -> Iterator[Tuple[int, float, float, float, float]]:
    """
    Generates amortization schedule

    :param principal: Principal amount
    :param interest_rate: Interest rate per period
    :param period: Total number of periods
    :return: Rows containing period, amount, interest, principal, balance, etc
    """
    amortization_amount = calculate_amortization_amount(principal, interest_rate, period)
    adjusted_interest = interest_rate / 12
    balance = principal
    for number in range(1, period + 1):
        interest = round(balance * adjusted_interest, 2)
        if number < period:
            principal = amortization_amount - interest
            balance -= principal
        else:
            principal, amortization_amount, balance = balance, balance + interest, 0
        yield number, amortization_amount, interest, principal, balance

can we please have it more flexible and explicit?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.