Tutorial, Part 1

Introduction

Welcome to the modeling framework tutorial! This tutorial assumes the audience:

  • Has no prior Python knowledge or experience, but some basic programming experience in another language (like Visual Basic for Applications (VBA)).

  • Has some actuarial modeling knowledge.

  • Runs a Windows 10 desktop environment.

  • Has administrator privileges on their device, and can install and configure software.

This tutorial is split into 3 parts:

  1. A brief, practical introduction to setting up a working environment and generating a set of model results.

  2. A conceptual overview of the modeling framework.

  3. A deeper dive into how the modeling framework is used to create a sample annuity model.

Note

The modeling framework relies on Object-Oriented Programming (OOP) concepts and mechanics. We’ll introduce these as we go.

Installation and Setup

This modeling framework was developed using (and works best with) PyCharm Community Edition. To set up the model:

  1. Download and Install Python

    1. Download Python 3.11.X from here:

      https://www.python.org/ftp/python/3.11.3/python-3.11.3-amd64.exe

    2. Install Python by double-clicking on the executable:

      _images/install_python.png
      1. Check Use admin privileges when install py.exe.

      2. Check Add python.exe to PATH.

      3. Click Install Now when ready.

    3. Once the installer completes, click Disable path length limit:

      _images/install_python_path_length_limit.png
  2. Download and Install PyCharm Community Edition

    1. Download PyCharm Community Edition from here:

      https://www.jetbrains.com/pycharm/download/download-thanks.html?platform=windows&code=PCC

    2. Install PyCharm by double-clicking on the executable. Under the Installation Options, select Add “Open Folder as Project”:

      _images/install_pycharm_options.png
  3. Download and Unzip the Project from GitHub

    1. Download the project from here:

      https://github.com/chingdaotze/actuarial-model/archive/refs/heads/main.zip

    2. Unzip the project by right-clicking and selecting Extract All…:

      _images/python_project_extract.png
  4. Open the Project in PyCharm

    1. Navigate to the extraction location and right-click. Then click Open Folder as PyCharm Community Edition Project:

      _images/python_project_open.png
    2. If prompted, select Trust Project:

      _images/trust_project.png
  5. Set up a Virtual Environment

    1. Go to File > Settings…

      _images/pycharm_settings.png
    2. Navigate to Project: * > Python Interpreter > Add Interpreter:

      _images/pycharm_add_interpreter.png

      And click on Add Local Interpreter.

      _images/pycharm_add_interpreter_confirm.png

      Then click OK.

    3. Click OK again to save your changes and exit the Settings dialog.

      _images/pycharm_ok.png
  6. Install the Required Packages

    1. Near the bottom of the window, click on Terminal to open up a terminal session:

      _images/open_terminal.png
    2. In the terminal session, type:

      pip install -r "install\requirements.txt"
      
      _images/install_reqs.png

      Then hit ENTER to execute the command.

    3. Once the command completes, you can quit the terminal session:

      _images/close_terminal.png

Running the Model

To run the model:

  1. In the upper right-hand corner, ensure that the run configuration is set to main. Then click the “Play” button to run the model:

    _images/run_model_1.png
  2. The model should start running and console output should appear in PyCharm’s Run window:

    _images/run_model_2.png

    Note

    Console output is also piped to a log file as plain text. The location of the log file can be found in the console output:

    _images/run_model_3.png
  3. Model output can be found in the modeling framework’s output directory:

    _images/run_model_4.png

    For the sample annuity model, the output directory is organized like so:

    \ Model point ID
        \ Economic scenario number
            Model output *.csv files