Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Gist for the For Python Quants Bootcamp in New York City, May 2017

For Python Quants Bootcamp

This is the Gist the FPQ bootcamp in New York, 08.-11. May 2017 (http://fpq.io)

Notebooks & Code Files

Additional files (eg Jupyter Notebooks) are found under:

https://gist.github.com/yhilpisch/64aeedbeb334c89aa05529a79881ceeb

Slides

Overview slides

Slides by Jorge Santos

Twitter Handle

http://twitter.com/dyjh

Recommended Books

  • Jake VanderPlas (2016): Python Data Science Handbook. O'Reilly.
  • Wes McKinney (2017): Python for Data Analysis. 2nd ed., O'Reilly.
  • Luciano Ramalho (2015): Fluent Python. O'Reilly.

Python Cheat Sheets

Some Docker Basics

Linux/Mac

open a shell window and type

docker version

to test whether it is installed

to run a docker container type

docker run -ti -h fpq -p 8888:8888 ubuntu:latest /bin/bash

  Windows

open the Docker Quickstart Terminal

to run a docker container type

docker run -ti -h fpq -p 8888:8888 -e MACHINE_IP=$(docker-machine ip) ubuntu:latest /bin/bash

Setting Up the Python Environment

(Assuming Ubuntu running in a Docker container, for instance)

Linux

updates and installs

 apt-get update apt-get upgrade apt-get install wget bzip2 screen vim gcc  

Miniconda

to install it

wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
bash miniconda.sh

open new shell instance to activate the new Python install

Python

see http://conda.io

see https://conda.io/docs/_downloads/conda-cheatsheet.pdf

to create an environment

conda create -n fpq python=3.6
source activate fpq

to install Python packages

conda install ipython jupyter numpy pandas scikit-learn matplotlib pytables

TensorFlow (on Windows) for Py 3.6

http://www.lfd.uci.edu/~gohlke/pythonlibs/#tensorflow

Download this:

tensorflow‑1.1.0‑cp36‑cp36m‑win_amd64.whl

pip install <path/to/wheel>
"","Class","Sex","Age","Survived","Freq"
"1","1st","Male","Child","No",0
"2","2nd","Male","Child","No",0
"3","3rd","Male","Child","No",35
"4","Crew","Male","Child","No",0
"5","1st","Female","Child","No",0
"6","2nd","Female","Child","No",0
"7","3rd","Female","Child","No",17
"8","Crew","Female","Child","No",0
"9","1st","Male","Adult","No",118
"10","2nd","Male","Adult","No",154
"11","3rd","Male","Adult","No",387
"12","Crew","Male","Adult","No",670
"13","1st","Female","Adult","No",4
"14","2nd","Female","Adult","No",13
"15","3rd","Female","Adult","No",89
"16","Crew","Female","Adult","No",3
"17","1st","Male","Child","Yes",5
"18","2nd","Male","Child","Yes",11
"19","3rd","Male","Child","Yes",13
"20","Crew","Male","Child","Yes",0
"21","1st","Female","Child","Yes",1
"22","2nd","Female","Child","Yes",13
"23","3rd","Female","Child","Yes",14
"24","Crew","Female","Child","Yes",0
"25","1st","Male","Adult","Yes",57
"26","2nd","Male","Adult","Yes",14
"27","3rd","Male","Adult","Yes",75
"28","Crew","Male","Adult","Yes",192
"29","1st","Female","Adult","Yes",140
"30","2nd","Female","Adult","Yes",80
"31","3rd","Female","Adult","Yes",76
"32","Crew","Female","Adult","Yes",20
Class Sex Age Survived Freq
1 1st Male Child No 0
2 2nd Male Child No 0
3 3rd Male Child No 35
4 Crew Male Child No 0
5 1st Female Child No 0
6 2nd Female Child No 0
7 3rd Female Child No 17
8 Crew Female Child No 0
9 1st Male Adult No 118
10 2nd Male Adult No 154
11 3rd Male Adult No 387
12 Crew Male Adult No 670
13 1st Female Adult No 4
14 2nd Female Adult No 13
15 3rd Female Adult No 89
16 Crew Female Adult No 3
17 1st Male Child Yes 5
18 2nd Male Child Yes 11
19 3rd Male Child Yes 13
20 Crew Male Child Yes 0
21 1st Female Child Yes 1
22 2nd Female Child Yes 13
23 3rd Female Child Yes 14
24 Crew Female Child Yes 0
25 1st Male Adult Yes 57
26 2nd Male Adult Yes 14
27 3rd Male Adult Yes 75
28 Crew Male Adult Yes 192
29 1st Female Adult Yes 140
30 2nd Female Adult Yes 80
31 3rd Female Adult Yes 76
32 Crew Female Adult Yes 20
#
# Simple Web Service
# with Flask
#
from flask import Flask
app = Flask(__name__)
page = '''
For Python Quants Bootcamp.
'''
@app.route('/')
def home():
return page
if __name__ == '__main__':
app.run(port=7777, debug=True)
#
# Simple Web Service
# with Flask
#
from flask import Flask, request
from pandas_datareader import data as web
app = Flask(__name__)
page = '''
<style>body {font-family: "Arial"; text-align: center; color: #08088A;}
table {margin-right: auto; margin-left: auto;}
</style>
<h1>For Python Quants Bootcamp</h1>
<p>Symbol: %s</p>
'''
@app.route('/')
def home():
symbol = request.args['symbol'].upper()
data = web.DataReader(symbol, data_source='yahoo')
html = page % symbol
return html + data.head().to_html()
if __name__ == '__main__':
app.run(port=7777, debug=True)
#
# Simple Web Service
# with Flask
#
# URL
# http://127.0.0.1:7777/?symbol=amzn&rows=100
#
import random
import pandas as pd
from pylab import plt
from flask import Flask, request
from pandas_datareader import data as web
plt.style.use('seaborn')
app = Flask(__name__)
page = '''
<style>body {font-family: "Arial"; text-align: center; color: #08088A;}
table {margin-right: auto; margin-left: auto;}
</style>
<h1>For Python Quants Bootcamp</h1>
<p>Symbol: %s</p>
<img src="static/plot.png?d=%s">
'''
@app.route('/')
def home():
symbol = request.args['symbol'].upper()
rows = int(request.args['rows'])
data = web.DataReader(symbol, data_source='yahoo')
plt.figure()
data['Adj Close'].plot(title=symbol)
plt.savefig('static/plot.png')
rn = str(random.gauss(0, 1))[2:]
html = page % (symbol, rn)
return html + data.tail(rows).to_html()
if __name__ == '__main__':
app.run(port=7777, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment