Skip to content

Instantly share code, notes, and snippets.

@yhilpisch
Last active March 17, 2025 13:43
Show Gist options
  • Save yhilpisch/df8fa41b150c408995f62749fd11e2ad to your computer and use it in GitHub Desktop.
Save yhilpisch/df8fa41b150c408995f62749fd11e2ad to your computer and use it in GitHub Desktop.

AI in Finance (O'Reilly)

Setting up a Python environment to run the code in Docker

Book by Dr. Yves J. Hilpisch

CEO The Python Quants

Artificial Intelligence in Finance

My book about AI & RL in finance and RL applied to algorithmic trading (http://home.tpq.io/books/aiif).

Docker

To install Docker see https://docs.docker.com/install/.

To run a Ubuntu-based Docker container, execute on the shell (Linux/Mac) the following:

docker run -ti -p 9999:9999 -h aiifenv -v $(pwd):/root/local ubuntu:latest /bin/bash

Make sure to adjust the folder to be mounted accordingly.

Or run the bash script:

bash run_docker.sh

Miniconda Installer

You might need to adjust the URL for the Miniconda installer in the setup.sh script. See the list of available installers here:

https://repo.anaconda.com/miniconda/

Environment

Next, once in Docker, execute the following:

cd /root/aiifenv
bash setup.sh

On your local machine, you should be able to access Jupyter Lab in the browser at:

https://127.0.0.1:9999/lab

The environment does NOT install all packages required. But those that are needed for the DL/ML/RL parts with TensorFlow/Keras.

Further Resources

name: aiif
channels:
- conda-forge
- defaults
dependencies:
- python=3.10
- numpy=1.26
- tensorflow=2.10
- scikit-learn=1.3.1
- pandas
- gym
- sympy
- nltk
- statsmodels
- lxml
- ipywidgets
- matplotlib
- pip
- pip:
- scikeras==0.10.0
docker run -ti -h aiif -v $(pwd):/root/aiif -p 9999:9999 ubuntu:latest /bin/bash
#!/bin/bash
#
# Installing Python Environment
# for AI in Finance Book (O'Reilly)
# by Dr. Yves J. Hilpisch
#
# System updates
apt update
apt upgrade -y
# Install basic dependencies
apt install -y wget git
# Download Miniconda installer if not present (here for Apple Silicon)
# [replace the filename with the appropriate installer for your Docker host platform]
if [ ! -f miniconda.sh ]; then
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh -O miniconda.sh
fi
# Install Miniconda silently
bash miniconda.sh -b -p "/root/miniconda3"
# Set conda path temporarily and permanently
export PATH="/root/miniconda3/bin:$PATH"
echo 'export PATH="/root/miniconda3/bin:$PATH"' >> ~/.bashrc
# Initialize conda
conda init bash
source ~/.bashrc
# Create environment from YAML file (corrected)
conda env create -f aiif.yaml
# Activate new environment
source activate aiif
# Install additional packages
conda install -y ipython jupyterlab
# Set Jupyter server password (this prompts interactively!)
echo "Please set your Jupyter server password:"
jupyter server password
# Cloning AIIF repository
git clone --depth=1 https://github.com/yhilpisch/aiif git
# Launch JupyterLab
echo "Launching JupyterLab..."
jupyter lab --allow-root --ip 0.0.0.0 --port 9999
gist -u df8fa41b150c408995f62749fd11e2ad *
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment