Skip to content

Instantly share code, notes, and snippets.

@twiecki
twiecki / ppc.ipynb
Last active August 29, 2015 14:25
Example NB to run a PPC test using new random() methods.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@twiecki
twiecki / table.html
Last active September 15, 2015 14:07
<html>
<table id="comparetable" class="clean">
<tr>
<td class="blank"> </td>
<th>Machine Learning</th>
<th>Frequentist<br>Statistics</th>
<th>Probabilistic<br>Programming</th>
</tr>
<tr>
<td class="rowTitle">Prediction</td>
@twiecki
twiecki / abstract
Created January 15, 2016 11:00
Thomas Wiecki Strata Hadoop World London 2016 submission -- accepted
All that glitters is not gold: Comparing backtest and out-of-sample performance of 800.000 trading algorithms
“Past performance is no guarantee of future returns”. This cautionary message will certainly match the experience of many
investors. When automated trading strategies are developed and evaluated using backtests on historical pricing data, there
is always a tendency, intentional or not, to overfit to the past. As a result, strategies that show fantastic performance on
historical data often flounder when deployed with real capital.
Quantopian is an online platform that allows users to develop, backtest, and trade algorithmic investing strategies. By
pooling all strategies developed on our platform we constructed a huge and unique data set of over 800.000 trading algorith
ms. Although we do not have access to source code, we have returns and portfolio allocations as well as the time the
@twiecki
twiecki / bayesian_neural_network.ipynb
Last active August 30, 2025 08:45
Bayesian Neural Network in PyMC3
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
def initialize(context):
fetch_csv('URL',
date_format='%d/%m/%y',
universe_func=my_universe)
def my_universe(context, fetcher_data):
my_stocks = set(fetcher_data['sid'])
# log the size of the universe for debugging
context.count = len(my_stocks)
class BayesianModel(object):
samples = 2000
def __init__(self, cache_model=True):
self.cached_model = None
self.cached_start = None
self.cached_sampler = None
self.shared_vars = {}
def cache_model(self, **inputs):
self.shared_vars = self._create_shared_vars(**inputs)
@twiecki
twiecki / custom_rolling.py
Created July 11, 2016 13:43
Rolling window and rolling apply with flexible lookback and resample behavior that also support parallelism.
import pandas as pd
from pandas.tseries.offsets import *
def rolling_window(data, resample='1BM', lookback=12 * BMonthEnd()):
dts = data.resample(resample).index
if lookback == 'aggregate':
for dt in dts:
yield data.loc[:dt]
else:
import scipy.cluster.hierarchy as sch
import random
import numpy as np
import pandas as pd
def getIVP(cov, **kargs):
# Compute the inverse-variance portfolio
ivp = 1. / np.diag(cov)
ivp /= ivp.sum()
return ivp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.