This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# After seeing Ex Machina I tweeted: | |
# "So disappointed in #ExMachina -- the #Python wasn't PEP8 compatible..." | |
# https://twitter.com/twiecki/status/599615426922938368 | |
# For the original code in the movie as well as what it does (it's kinda neat), see: | |
# http://moviecode.tumblr.com/post/119171520870/in-the-movie-ex-machina-which-is-really-great | |
# To put my code where my mouth is, I decided to make the code PEP8 compatible which you can see below. | |
# I also did some minor cosmetic changes like changing i = i + 1 to i += 1 | |
# Other ideas for improvements? Comment below. |