Skip to content

Instantly share code, notes, and snippets.

@yhilpisch
Last active March 22, 2025 18:56
Show Gist options
  • Save yhilpisch/cc7a12ddefe42109f08db577919ab30e to your computer and use it in GitHub Desktop.
Save yhilpisch/cc7a12ddefe42109f08db577919ab30e to your computer and use it in GitHub Desktop.

Python & AI for Algorithmic Trading Bootcamp

3-Day Online Bootcamp about Python & AI for Algorithmic Trading

Dr. Yves J. Hilpisch

Director CPF Program | CEO The Python Quants

Online, November 13-15, 2024

Short Link

http://bit.ly/algo_bc_2024

Slides

https://certificate.tpq.io/algo_bc_2024.pdf

Quant Platform

https://bootcamp.pqp.io (registration)
https://base.pqp.io (login)

GotoWebinar

https://attendee.gotowebinar.com/register/1865757326257212505

Discord Server

https://discord.gg/eanaY3vfKp

Importance of Large Returns (Tails)

https://certificate.tpq.io/large_returns_importance.html

Oanda Demo Account

Go to https://www.oanda.com/uk-en/

Open a demo account, indicating that you are located in/from the UK.

We use this wrapper for the v20 API:

https://github.com/yhilpisch/tpqoa

Miniconda Installer

https://conda.io/en/main/miniconda.html

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 algobc -v $(pwd):/root/live ubuntu:latest /bin/bash

Make sure to adjust the folder to be mounted accordingly.

Once, JupyterLab is installed, run it with the following command:

jupyter-lab --allow-root --port 9999 --ip 0.0.0.0

Cloud

Use this link to get a 200 USD bonus on DigitalOcean when signing up for a new account.

Further Resources

Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#
# Deployment of TF/Keras Model
#
import tpqoa
import numpy as np
import pandas as pd
import tensorflow as tf
from tensorflow import keras
mu = -0.000002
std = 0.000124
lags = 5
class DLTrader(tpqoa.tpqoa):
def __init__(self, config_file):
super().__init__(config_file)
self.position = 0
self.tick_data = pd.DataFrame()
self.model = tf.keras.models.load_model('dltrader.keras')
def on_success(self, time, bid, ask):
df = pd.DataFrame({'bid': bid, 'ask': ask,
'mid': (bid + ask) / 2},
index=[pd.Timestamp(time)])
self.tick_data = pd.concat((self.tick_data, df))
self.data = self.tick_data.resample('3s', label='right').last().ffill()
self.data['r'] = np.log(self.data['mid'] / self.data['mid'].shift(1))
self.data_ = (self.data - mu) / std
if len(self.data) > lags + 2:
print('*** PREDICTION ***')
f = self.data_['r'].iloc[-lags:].values.reshape(1, -1)
p = self.model.predict(f)[0, 0]
signal = np.where(p > 0.5, 1, -1)
print(p, signal)
if signal == 1 and self.position in [0, -1]:
# go long
print('GOING LONG')
self.create_order('BCO_USD',
units=(1 - self.position) * 10)
self.position = 1
elif signal == -1 and self.position in [0, 1]:
# go short
print('GOING SHORT')
self.create_order('BCO_USD',
units=-(1 + self.position) * 10)
self.position = -1
else:
print('POSITION UNCHANGED')
if __name__ == '__main__':
dlt = DLTrader('oanda.cfg')
dlt.stream_data('BCO_USD', stop=50)
dlt.create_order('BCO_USD', units=-dlt.position * 10)
print('*** CLOSED OUT FINAL POSITION ***')
#
# install.sh
#
apt update
apt upgrade -y
apt install vim -y
apt install git -y
apt install screen -y
apt install htop -y
apt install python3 -y
apt install pipx -y
export PATH=$PATH:/root/.local/bin
pipx install jupyterlab
pipx inject jupyterlab numpy
pipx inject jupyterlab pandas
pipx inject jupyterlab matplotlib
pipx inject jupyterlab scikit-learn
pipx inject jupyterlab tensorflow
pipx inject jupyterlab tf_keras
pipx inject jupyterlab quantstats
pipx inject jupyterlab "git+https://github.com/yhilpisch/tpqoa.git"
ln -s /root/.local/share/pipx/venvs/jupyterlab/bin/ipython /root/.local/bin
ln -s /root/.local/share/pipx/venvs/jupyterlab/bin/python /root/.local/bin
screen
#
# install.sh
#
apt update
apt upgrade -y
apt install vim -y
apt install git -y
apt install screen -y
apt install htop -y
apt install python3 -y
apt install pipx -y
# On a small Droplet, ececute:
# mkdir -p ~/tmp
# export TMPDIR=~/tmp
export PATH=$PATH:/root/.local/bin
pipx install jupyterlab
pipx inject jupyterlab numpy
pipx inject jupyterlab pandas
pipx inject jupyterlab matplotlib
pipx inject jupyterlab scikit-learn
pipx inject jupyterlab tensorflow
pipx inject jupyterlab tf_keras
pipx inject jupyterlab quantstats
pipx inject jupyterlab "git+https://github.com/yhilpisch/tpqoa.git"
ln -s /root/.local/share/pipx/venvs/jupyterlab/bin/ipython /root/.local/bin
ln -s /root/.local/share/pipx/venvs/jupyterlab/bin/python /root/.local/bin
screen
{
"shortcuts": [
{"command": "kernelmenu:restart-and-clear",
"keys": [
"Ctrl Shift 0"
],
"selector": "body"},
{"command": "runmenu:run-all",
"keys": [
"Ctrl Shift A"
],
"selector": "body"},
{"command": "runmenu:restart-and-run-all",
"keys": [
"Ctrl Shift N"
],
"selector": "body"},
{"command": "notebook:run-all-above",
"keys": [
"Ctrl Shift Y"
],
"selector": "body"},
{"command": "notebook:run-all-below",
"keys": [
"Ctrl Shift X"
],
"selector": "body"},
{
"command": "application:activate-next-tab",
"keys": [
"Ctrl Shift ]"
],
"selector": "body",
"disabled": true
},
{
"command": "application:activate-previous-tab",
"keys": [
"Ctrl Shift ["
],
"selector": "body",
"disabled": true
},
{
"command": "application:activate-next-tab",
"keys": [
"Ctrl Shift L"
],
"selector": "body"
},
{
"command": "application:activate-previous-tab",
"keys": [
"Ctrl Shift K"
],
"selector": "body"
},
{
"command": "application:activate-next-tab",
"keys": [
"Ctrl Shift ]"
],
"selector": "body",
"disabled": true
},
{
"command": "application:activate-previous-tab",
"keys": [
"Ctrl Shift ["
],
"selector": "body",
"disabled": true
},
{
"command": "application:activate-next-tab",
"keys": [
"Ctrl Shift L"
],
"selector": "body"
},
{
"command": "application:activate-previous-tab",
"keys": [
"Ctrl Shift K"
],
"selector": "body"
}, ]
}
gist -u cc7a12ddefe42109f08db577919ab30e *.md *.ipynb *.sh *.json *.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment