Python for Finance Automation Project: Make a Mortgage Loan Analysis Class

Поделиться
HTML-код
  • Опубликовано: 31 май 2024
  • ​@MattMacarty
    #python #project #finance
    Python for Finance Projects - Loan Analysis
    Looking for something to work on to improve Python intermediate skills? Try this Python project focused on financial concepts involved with money lending. Hands-on project designed to improve your coding skills. In part 1, we write a Loan class and in part 2 we use the loan class to develop a menu-driven application
    ✅ Please SUBSCRIBE:
    ruclips.net/user/subscription_...
    Automate the process of analyzing mortgage PART I
    Learn how to create and use classes in Python
    How do you calculate monthly payment in Python?
    How do you do amortization in Python?
    What is plotting mortgages in Python?
    Which Python libraries do you use to calculate a loan payment like Excel?
    ✅ PART II: • Python Automation Proj...
    NumPy Financial is a small stand-alone Python module of legacy NumPy functionality that was split off in NumPy 1.17. The module contains basic "spreadsheet" style functions for dealing with common time value of money models.
    ✅ The notebook used in this demonstration can be downloaded from:
    github.com/mjmacarty/numpy_fi...
    Python for Finance example:
    This video is Part I of a Loan Analysis Application. Demonstrates several use cases for the NumPy Financial library. Learn how to write a Python class and automate loan analysis.
    In these following video tutorials, we're going to be making a loan class to handle some of the common, repetitive tasks that are involved in loan analysis and then make an application based on the class. So when we're done, not only will you have a menu-driven application, but you will also be able to import and use the class in your Python applications.
    The application will handle a number of common loan analysis tasks, very simply with minimal user inputs the interest rate, the term and the amount of money we're borrowing. With just those three inputs you can call payment, generate a summary and amortization table. You can always add functionality to this analyzer to make it better fit your needs.
    We start off by importing matplotlib, pandas for the amortization table and NumPy Financial, for the time value of money calculations. NumPy Financial used to be part of NumPy, but is now its own module, so you may have to install it. Assuming you are working from an Anaconda installation you should already have matplotlib and pandas. We are also going to use another third party library that you will also likely have to install: dateutils, to synchronize our loan to the beginning of a month. To install them, you can launch a command line interface and use pip to install:
    pip install numpy-financial
    pip install dateutils
    Once we have our imports, we will go ahead and define our class, and initializer. To instantiate a Loan object we will pass in interest rate, term, and the amount borrowed as well as a starting date. We are going to set our start date to default to the first of the month following the current date, but you will be able to manually enter any iso date if desired as well.
    With these basic inputs, we will use NumPy Financial to calculate a payment. I am going to give developers access to the float value of the loan payment as well as a string version which will be convenient for some outputs.
    Next up, we will write a method to generate an amortization table. Inside the method we will make a few arrays and then combine them into a pandas DataFrame to create our amortization table. First up, we will convert the term into monthly periods, starting at some user-specified date. This will be the DataFrame index. We will also enumerate our interest and principal per period, again leveraging NumPy Financial here. With these initial "columns" defined, we can create a preliminary DataFrame.
    Then usually these amortization tables have a running balance in them and this is easy to add based on our preliminary columns and a cumulative sum of principal paid. We'll take our initial loan amount and subtract the cumulative principal away.
    Next we will add another method to plot the interest paid against the balance over time. This is basically a convenience method so the user doesn't have to waste time completing common tasks. So we'll just define a method called plot balances and it won't take any arguments because we'll just use some of these class variables from the amortization table.
    Other methods developed include analyzing the impact of accelerating payments.

Комментарии • 11

  • @kiriobavince7426
    @kiriobavince7426 2 года назад

    Great Job !

  • @mpumisetshedii
    @mpumisetshedii Год назад

    Thank you for making this

  • @philtoa334
    @philtoa334 Год назад

    😱Great Thx_.

  • @konnen4518
    @konnen4518 Год назад

    What do the 'month_start' and 'fromisoformat' functions do and what's their relevance to the line of code ***self.start = month_start(dt.date.fromisoformat(start)) + dt.timedelta(31)***? In other words, in what way are they helping? Looking forward to hearing from you! Thank you!

    • @MattMacarty
      @MattMacarty  Год назад +1

      Hi, so basically if you get a mortgage loan, they are almost universally indexed to the first day of the month, so I am trying to mimic this with the month_start function in dateutils. Working with dates in Python can be kind of a pain, for example if you use the datetime library, dates are basically tuple objects, or a comma separated year, mo, day. I am using isoformat function to handle more typical date inputs. There are other ways to do this, but I didn't want to spend a bunch of time talking about dates in Python

  • @sayednab
    @sayednab 4 месяца назад

    is it possible to add LIBOR rates either through API or manually ?

    • @MattMacarty
      @MattMacarty  4 месяца назад

      If you can find LIBOR rates, I don't see why not. I think LIBOR has been retired and there is some proxy rate that is being used now.

    • @sayednab
      @sayednab 4 месяца назад

      I have all the rates, but the challenge is that the bank utilizes LIBOR and computes multiple rates in a month. These rates are calculated from the date they have been valued. How can I accurately calculate them? Any assistance would be greatly appreciated. Thanks.