Python for Finance

Installation & Setup

Download & Install Anaconda

Anaconda is a Python package management and distribution tool.

Optional: Install Node.js and iJavascript

Anaconda provides a data science platform that distributes both Jupyter (by default) and Node.js (optionally). iJavascript can be installed in an Anaconda setup as follows:

conda install nodejs
npm install -g ijavascript
ijsinstall

Notice that you need to use the ijsinstall utility to allow Jupyter to use the Javascript kernel.

Setup the Environment

  • This section deals with the installation of all necessary files/ materials for the course
  • Unzip file "Python-for-Finance-Repo-master.zip" to your desired path
  • Open command prompt by searching Anaconda prompt in Windows or simply search for "cmd"
  • At command prompt:
    (base)> conda env create -f environment.yml
    If you see Solving environment: done, do NOT exit! The setup will take a while. A bunch of downloads will occur. When the downloads are finish, type below at command prompt
    (base)> activate pyfinance
    (pyfinance)>
  • For more info on Conda environments, click [here]

Using Jupyter Notebook

To get help

>>> jupyter notebook --help

By default, jupyter notebook opens the notebook dashboard in the current working folder. To open in a different folder, run:

jupyter notebook --notebook-dir=[put your path here]

To start Jupyter Notebook: At Anaconda prompt:

(base)> activate pyfinance
(pyfinance)> jupyter notebook

To change the startup directory in Windows https://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/execute.html#change-jupyter-notebook-startup-folder-windows

If this is the first time using jupyter notebook, make sure that you copy the url with the token for future login http://localhost:8888/?token=e878ff75ee1b5ac82db1be2d135caccf64b7a2fa20b4d03a

Keyboard Commands

shift-enter: execute command shift-tab: get documentation string tab: if press after ".": get list of methods. if press during typing: auto-complete pwd: check the directory where Jupyter notebook is in

Kernel > Restart will restart the kernel e.g. infinite while loop but it will also delete all the variable names assigned earlier. Cell > Run All Above: Re-run code above Cell > Run All Below: Re-run code below

Note on Exercises

jupyter notebook files end with a ipynb extension. You need to press shift+enter to execute the command in the cells above your input cell.