Solutions for exercises from John C. Hull's Risk Management and Financial Institutions using Python and Pandas.
So far I tackled Chapters 10 Volatility, 11 Correlations and Copulas, 13 Market Risk VaR: The Historical Simulation Approach, 14 Market Risk VaR: The Model Building Approach, 18 Fundamental Review of the Trading Book, and 19 Estimating Default Probabilities.
For the majority of problems the following will suffice:
python3 -m pip install -r requirements.txt
For one problem in Chapter 11 Copulas and Correlations and a few problems relying on the Extreme Value Theory in Chapter 13 The Historical Simulation Approach, where we need to solve optimization problems, TensorFlow 2.x will be needed:
python3 -m pip install -r requirements_extra.txt
If you want to avoid mixing up packages in your global python installation, you can prepare the environment as follows:
python3 -m venv venv
source venv/bin/activate
python3 -m pip install -r requirements.txt
python3 -m pip install -r requirements_extra.txt
python3 -m pip install jupyter
The spreadsheet I used for exercises in these chapters can be downloaded from this page.
I used VaRExampleRMFI3eHistoricalSimulation.xls for all these Chapters. Please remove the first row before feeding it to the code (for the spreadsheet in this repository I already did it).
Code in ch14/ replicates the functionality in VaRExampleRMFI3eModelBuilding.xls.
-
Chapter 10: Volatility Using Jupiter.
jupyter notebook ch10.ipynbA full run of the notebook can be seen here.
-
Chapter 11: Correlations and Copulas
jupyter notebook ch11.ipynbA full run of the notebook can be seen here.
You can also run the notebook in Google cloud. This way you don't need to install anything locally. This takes just a few seconds:
- Go to Google Colaboratory in your browser
- In the modal window that appears select
GitHub - Enter the URL of this repository's notebook:
https://github.com/ilchen/RMaFI/blob/master/ch11.ipynb - Click the search icon
- Enjoy
I make heavy use of the SciPy and TensorFlow 2 libraries in these exercises. as they draw heavily on probability theory and solving optimization problems. These exercises are fairly simple from software design point of view, so I limited the implementation to a Jupiter notebook.
Despite there not being that many challenging exercises concerning the tracking and forecasting variances-covariances, I decided to create required classes to track and visualize correlations in a separate Jupiter notebook:
jupyter notebook ch11_variance_covariance.ipynbA full run of the notebook can be seen here.
-
Chapter 13: Market Risk VaR: The Historical Simulation Approach
python3 ch13/hist_simulation.py ./ext/VaRExampleRMFI3eHistoricalSimulation.xlsOr, much better, using Jupiter. For historical simulation exercises that don't utilize the Extreme Value Theory:
jupyter notebook ch13.ipynbFor exercises that make use of the Extreme Value Theory:
jupyter notebook ch13_evt.ipynb -
Chapter 14: Market Risk VaR: The Model Building Approach
python3 ch14/model_build.py ./ext/VaRExampleRMFI3eHistoricalSimulation.xlsOr, much better, using Jupiter.
jupyter notebook ch14.ipynb -
Chapter 18: Fundamental Review of the Trading Book:
python3 ch18/frtb.py ./ext/VaRExampleRMFI3eHistoricalSimulation.xls -
Chapter 19: Estimating Default Probabilities
jupyter notebook ch19.ipynbA full run of the notebook can be seen here.
You can also run the notebook in Google cloud. This way you don't need to install anything locally. This takes just a few seconds:
- Go to Google Colaboratory in your browser
- In the modal window that appears select
GitHub - Enter the URL of this repository's notebook:
https://github.com/ilchen/RMaFI/blob/master/ch19.ipynb - Click the search icon
- Enjoy