Skip to content

Tutorial for conducting a monte carlo simulation against a loan amortization schedule.

License

Notifications You must be signed in to change notification settings

Py-Fi-nance/MonteCarlo-Simulation-Loan-Amortization

Repository files navigation

MonteCarlo-Simulation-Loan-Amortization

This Python tutorial is designed to simulate and visualize the potential lifetimes of a loan under various scenarios. It uses a Monte Carlo method to simulate thousands of potential loan payoff trajectories given varying probabilities of making extra payments or late payments.

Python Version

License: MIT

Forks Stars

Table of Contents

  1. Description
  2. Requirements
  3. Usage
  4. Notes
  5. Contributing

Description

Loan Parameters Setup

It starts by defining parameters for a loan, such as the principal amount, annual interest rate, and term in years. These are then used to calculate the monthly payment using a standard loan amortization formula.

Monte Carlo Parameters Setup

It then sets parameters for a Monte Carlo simulation, which includes the number of simulations to run and the probability of making extra payments. These extra payments are randomly applied to some months during the loan payoff period.

Monte Carlo Simulation

The script runs the Monte Carlo simulation, tracking the loan balance month by month and recording how many payments it takes to fully pay off the loan. Each simulation represents a possible loan lifetime.

Results Visualization

The results are plotted in a histogram, showing the distribution of possible loan lifetimes.

Additional Scenarios

The script then runs additional simulations for different probabilities of making extra payments, and for different probabilities of making late payments. The impact of these scenarios on the loan lifetime is visualized in additional histograms.

Empirical Rule Calculation

For each scenario, it computes the mean and standard deviation of the loan lifetimes, and reports the intervals within which 68%, 95%, and 99.7% of loan lifetimes fall (according to the empirical rule in statistics).

Requirements

To run this script, you need Python and several packages including numpy, pandas, matplotlib, numpy-financial, and scipy. You can install these packages using pip.

Usage

Simply run the Python script to start the simulation and generate the plots. You can adjust the loan parameters and the parameters for the Monte Carlo simulations as needed.

Notes

This script assumes that the interest is calculated on a monthly basis. If your loan uses a different compounding period, you will need to adjust the script accordingly. It provides a useful illustration of the potential impact of making extra payments on the speed of loan payoff, as well as the potential consequences of making late payments. For any questions or inquiries, please contact support@pyfi.com - Subject: Github Repo Q, MonteCarlo-Simulation-Loan-Amortization. For a full article walkthrough please visit > (https://www.pyfi.com/blog/monte-carlo-simulation-python) < and learn more about PyFi's award winning Python for Finance courses which have been trusted by the top financial institutions in the United States and Canada multiple years running here >> https://www.pyfi.com << Follow on LinkedIn

Contributing

We welcome contributions to this project. To contribute:

  1. Fork the project.
  2. Create your feature branch (git checkout -b feature/AmazingFeature).
  3. Commit your changes (git commit -m 'Add some AmazingFeature').
  4. Push to the branch (git push origin feature/AmazingFeature).
  5. Open a Pull Request.

About

Tutorial for conducting a monte carlo simulation against a loan amortization schedule.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published