This project is a deterministic Portfolio Immunization Engine implemented in Python.
It computes two asset cashflows, cf_x and cf_y, that satisfy either Full or Redington immunization conditions at time t = 0, given:
- a user-selected immunization type (Full or Redington),
- a base interest rate
i0at which the portfolio is immunized, - a set of liability cashflow amounts,
- corresponding liability times, and
- exactly two asset times for
cf_xandcf_y.
For Redington immunization only, the engine additionally computes an interval of solvency, defined as the set of interest rates for which the portfolio surplus remains non-negative.
For both immunization types, the engine supports rebalancing under a change in interest rate to i_n and time to t_n, recalculating the asset cashflows required to re-immunize the portfolio and reporting the resulting surplus at i_n.
The present values of the asset cashflows at t = 0 are also reported under their corresponding interest rates (i_0 or i_n).
The project also includes a graphical representation of the surplus function ( S(i) ), allowing visualization of surplus behavior across interest rates for both Full and Redington immunization cases.
- Constructs asset cashflows that match liabilities satisfying the Full immunization conditions:
- Present Value matching
- Duration matching
- ALA (Asset–Liability–Asset) cashflow structure.
- Recalculates asset cashflows required to re-immunize the portfolio under changes in interest rate
i_nand timet_n, and reports the resulting surplus ati_n.
- Constructs asset cashflows satisfying the Redington immunization conditions:
- Present Value matching
- Duration matching
- Positive second derivative of the surplus function,
S''(i) > 0
- Allows general asset–liability cashflow structures.
- Recalculates asset cashflows required to re-immunize the portfolio under changes in interest rate
i_nand timet_n, and reports the resulting surplus ati_n. - Computes a finite interval of solvency directly from the surplus function.
This project operates under the classical assumptions of immunization theory:
- The yield curve is assumed to be flat.
- Only parallel shifts in the yield curve are permitted.
- All computations are performed within a deterministic framework.
The asset cashflows produced by the engine are theoretical constructs and may not correspond to securities that exist or are tradable in real markets. Accordingly, this project should be viewed as an exercise in theoretical financial mathematics, rather than a practical portfolio construction tool.
- Python 3.10+
- matplotlib
- numpy
- scipy
- sympy
pip install -r requirements.txt
This guide explains how to run the project locally using Windows with minimal setup.
Before running the project, Python must be installed.
- Go to https://www.python.org
- Download Python 3.x for Windows.
- During installation, check the box labeled “Add Python to PATH”.
- Complete the installation.
Verify Python is installed by opening a terminal and running:
python --version- Go to the GitHub repository.
- Click the green
<> Codebutton. - Select Download ZIP.
- Extract the ZIP file to any location on your computer (e.g.
Documents).
- Open the extracted project folder.
- Right-click on an empty area inside the folder.
- Select “Open in Terminal” or “Open Command Prompt here”
(the wording depends on your Windows version).
A terminal window should now open at the project directory.
From the terminal run:
pip install -r requirements.txtAll user-editable inputs are controlled through config.py.
- Open
config.pyusing any text editor (Notepad, VS Code, etc.). - Modify the parameters, including:
- immunization type (Full or Redington),
- base interest rate,
- asset times,
- liability amounts and their corresponding times.
- Save the file after making changes.
No other files need to be edited.
From the terminal, run:
python main.pyClose the plot window before re-running the model.
Feedback and suggestions are welcome.
If you encounter a bug, unexpected behavior, or edge case, feel free to open an issue describing:
- the inputs used,
- the observed behavior,
- and the expected behavior.
Contributions, extensions, and theoretical discussions related to asset–liability immunization are also welcome.
Please open an issue or pull request if you would like to collaborate.
Christopher Baez
Finance & Risk Management Major | Future Actuary
Email: [chris_baez18@hotmail.com]
This project is licensed under the MIT License — you are free to use, modify, and distribute it with proper attribution.