Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Famafrench bayes #200

Merged
merged 1 commit into from
Nov 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions pyfolio/bayesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import scipy as sp
from scipy import stats
import seaborn as sns
import theano.tensor as tt

import matplotlib.pyplot as plt

Expand All @@ -34,14 +35,16 @@ def model_returns_t_alpha_beta(data, bmark, samples=2000):
return sets. Usually, these will be algorithm returns and
benchmark returns (e.g. S&P500). The data is assumed to be T
distributed and thus is robust to outliers and takes tail events
into account.
into account. If a pandas.DataFrame is passed as a benchmark, then
multiple linear regression is used to estimate alpha and beta.

Parameters
----------
returns : pandas.Series
Series of simple returns of an algorithm or stock.
bmark : pandas.Series
Series of simple returns of a benchmark like the S&P500.
bmark : pandas.DataFrame
DataFrame of benchmark returns (e.g., S&P500) or risk factors (e.g.,
Fama-French SMB, HML, and UMD).
If bmark has more recent returns than returns_train, these dates
will be treated as missing values and predictions will be
generated for them taking market correlations into account.
Expand All @@ -55,10 +58,15 @@ def model_returns_t_alpha_beta(data, bmark, samples=2000):
of the posterior.
"""

if len(data) != len(bmark):
# pad missing data
bmark = bmark.dropna()

if data.shape[0] != bmark.shape[0]:
data = pd.Series(data, index=bmark.index)

if bmark.ndim > 1:
Nbmark = bmark.shape[1]
else:
Nbmark = 1
data_no_missing = data.dropna()

with pm.Model():
Expand All @@ -69,16 +77,19 @@ def model_returns_t_alpha_beta(data, bmark, samples=2000):
nu = pm.Exponential('nu_minus_two', 1. / 10., testval=.3)

# alpha and beta
beta_init, alpha_init = sp.stats.linregress(
bmark.loc[data_no_missing.index],
data_no_missing)[:2]

alpha_reg = pm.Normal('alpha', mu=0, sd=.1, testval=alpha_init)
beta_reg = pm.Normal('beta', mu=0, sd=1, testval=beta_init)

X = bmark.loc[data_no_missing.index]
X['ones'] = np.ones(len(X))
y = data_no_missing
alphabeta_init = np.linalg.lstsq(X, y)[0]#[:2]

alpha_reg = pm.Normal('alpha', mu=0, sd=.1, testval=alphabeta_init[-1])
beta_reg = pm.Normal('beta', mu=0, sd=1,
testval=alphabeta_init[:-1], shape=Nbmark)
bmark_theano = tt.as_tensor_variable(bmark.ix[data_no_missing.index].T)
mu_reg = alpha_reg + tt.dot(beta_reg, bmark_theano)
pm.T('returns',
nu=nu + 2,
mu=alpha_reg + beta_reg * bmark,
mu=mu_reg,
sd=sigma,
observed=data)
start = pm.find_MAP(fmin=sp.optimize.fmin_powell)
Expand Down Expand Up @@ -528,7 +539,7 @@ def run_model(model, returns_train, returns_test=None,
Out-of-sample returns. Datetimes in returns_test will be added to
returns_train as missing values and predictions will be generated
for them.
bmark : pd.Series (optional)
bmark : pd.Series or pd.DataFrame (optional)
Only used for alpha_beta to estimate regression coefficients.
If bmark has more recent returns than returns_train, these dates
will be treated as missing values and predictions will be
Expand Down
209 changes: 209 additions & 0 deletions pyfolio/examples/Fama-French Benchmark.ipynb

Large diffs are not rendered by default.

66 changes: 33 additions & 33 deletions pyfolio/examples/bayesian.ipynb

Large diffs are not rendered by default.

Binary file added pyfolio/examples/fama-french-beta.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
195 changes: 195 additions & 0 deletions pyfolio/examples/linear algebra tests.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"x = np.array([0, 1, 2, 3])"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"y = np.array([-1, 0.2, 0.9, 2.1])"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"A = np.vstack([x, np.ones(len(x)), np.ones(len(x))]).T"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(4, 3)"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A.shape"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0., 1., 1.],\n",
" [ 1., 1., 1.],\n",
" [ 2., 1., 1.],\n",
" [ 3., 1., 1.]])"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"mcc = np.linalg.lstsq(A, y)[0]"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([ 1. , -0.475, -0.475])"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mcc"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEACAYAAAC08h1NAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAH6ZJREFUeJzt3XtwVPXdx/H3F4xILGAUAQmXyGCnVR4vVGhCFVdsHWsV\nb5HaKuoz9sGxajsOdtSqTUTE1pHWVm3Fjt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Pu3ttkNqpG7hERApMdj16UUREepwKv4hIgVHhFxEpMCr8IiIF\nRoVfRKTAqPCLiBQYFX4RkQKjwi8iUmD+H7zWL1hRa4t/AAAAAElFTkSuQmCC\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x1062b1710>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.plot(x, y, 'o', label='Original data', markersize=10)\n",
"plt.plot(x, m*x + c, 'r', label='Fitted line')\n",
"plt.legend()\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Loading