---
# System prepended metadata

title: 'Python for Algorithmic Trading: Quick Guide'
tags: [Documentation, Templates]

---

---
title: 'Python for Algorithmic Trading: Quick Guide'
disqus: hackmd
---

Python for Algorithmic Trading: Quick Guide
===
![downloads](https://img.shields.io/github/downloads/atom/atom/total.svg)
![build](https://img.shields.io/appveyor/ci/:user/:repo.svg)
![chat](https://img.shields.io/discord/:serverId.svg)

## Table of Contents

[TOC]

## Purpose

I'm going to take what's from the book and streamline it from creating the environment to execution. This is the book from Hilpisch, Yves.


Setting up Docker Containers
---
### Purpose
To have a script run on the cloud. Not needing a home computer to run it, avoids risk of power/connection issues to brokerage. This is good for algorithmic deployment purposes.

Steps: 
**1) Server set up script**: running files on droplet.
**2) Python and Jupyter Installation**: have a lab server.
**3) Jupyter Notebook configuration file**: password protection.
**4) RSA Public and Private Key Files**: SSL encryption communication.


### Digital Ocean VM: Droplet
1. Sign up: [here](https://cloud.digitalocean.com/registrations/new)
2. Create first droplet: Django Server
3. Refer to [guide](https://developers.digitalocean.com/guides/)

### Connecting to Ocean VM
**Input**
```bash=
$ ssh <root>@<dropletIP>
```

**Output**
```bash=
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-47-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Tue Dec 29 19:25:28 UTC 2020

  System load:  0.0               Users logged in:       0
  Usage of /:   9.1% of 24.06GB   IPv4 address for eth0: 178.128.72.117
  Memory usage: 32%               IPv4 address for eth0: 10.46.0.5
  Swap usage:   0%                IPv4 address for eth1: 10.120.0.2
  Processes:    123

0 updates can be installed immediately.
0 of these updates are security updates.


The list of available updates is more than a week old.
To check for new updates run: sudo apt update

********************************************************************************

Welcome to DigitalOcean's 1-Click Django Droplet.
To keep this Droplet secure, the UFW firewall is enabled.
All ports are BLOCKED except 22 (SSH), 80 (HTTP), and 443 (HTTPS).
...
```


Creating the Environment w/ Conda
---
Conda in this instance is probably used for the environment and library/module control. 
### Install Miniconda for 3.8 Python
```bash=
$ sudo -s
$ apt-get update; apt-get upgrade -y
...
$ apt-get install -y gcc wget
...
$ cd root
$ wget \
> https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
> -O miniconda.sh
...
$ bash miniconda.sh
...
```

### Update & Profile Dir Conda
```bash=
$ export PATH="/root/miniconda3/bin/:$PATH"
$ conda update -y conda
...
$ echo ". /root/miniconda3/etc/profile.d/conda.sh" >> ~/.bashrc
$ bash
```

### Using Conda
```bash=
$ conda <command> <subject>
```

### Conda Virtual Environment
**Create**
```bash=
$ conda create --name pyalgo3.8 python=3.8
```

**Activate**
```bash=
$ conda activate pyalgo3.8
```

### Package Installation
```bash=
$ conda install -y numpy ipython matplotlib pandas pytables scikit-learn scipy
```


Financial Data
---
Primary focus: importing data, handling data, storing data.

### Importing Data
#### Quandl API
Popular datasource is **Quandl**. It's popular because it grabs quality data from different sources, "opensource" and puts it in a central area. 
#### Eikon Data API
Open data sources aren't enough for professionals. Refinitiv is one of the biggest financial/news data provider. Eikon is equivalent to Terminal by Bloomberg. Eikon is a python wrapper for their api. A local desktop application is required to run the API session. 
##### Setting up Eikon API
Refer to this [link](https://developers.refinitiv.com/en/api-catalog/eikon/eikon-data-api/quick-start#run-eikon) for instruction:
1) Register [Account](https://www.refinitiv.com/en/products/eikon-trading-software/download-eikon) or set up a MyRefinitiv Account
2) Download the [application](https://eikon.thomsonreuters.com/index.html)
3) Set up Python Wrapper: [Documentation](https://developers.refinitiv.com/en/api-catalog/eikon/eikon-data-api/documentation)

### Working with Data: Pandas
Data is efficiently handled with the pandas module. Instead of using pure python, algorithms are made to efficiently process data. It's faster.

### Storing Data: Partition Disk as HDF5 standard
Storing pandas DataFrames are simple. Parsing the data into a pandas HDFStore. It is a dump for DF objects and it allows to write to memory 5 times more than regular.
#### Opening Database File: TsTables
This opens the contents of the database in a more efficient manner.

Trade Idea/Hypothesis
---
What better way to develop a strategy than to find it through research papers?

## Appendix and FAQ

:::info
**Find this document incomplete?** Leave a comment!
:::

###### tags: `Templates` `Documentation`
