Skip to content

Commit be5a093

Browse files
eigenfootwiecki
authored andcommitted
ENH: estimate sigma backtest (#56)
* MAINT: update test data with trading days * MAINT: estimate sigma_backtest
1 parent fd84cc8 commit be5a093

File tree

2 files changed

+336
-335
lines changed

2 files changed

+336
-335
lines changed

bayesalpha/author_model.py

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
import pandas as pd
1010
from sklearn.preprocessing import LabelEncoder
1111
import pymc3 as pm
12+
import theano.tensor as tt
1213
import xarray as xr
1314
from .serialize import to_xarray
1415
from ._version import get_versions
1516
from .base import BayesAlphaResult
1617

1718
AUTHOR_MODEL_TYPE = 'author-model'
19+
APPROX_BDAYS_PER_YEAR = 252
1820

1921

2022
class AuthorModelBuilder(object):
@@ -114,25 +116,10 @@ def _build_model(self, data):
114116
+ mu_author[self.author_to_backtest_encoding]
115117
+ mu_algo[self.algo_to_backtest_encoding])
116118

117-
sigma_author_sd = pm.HalfNormal('sigma_author_sd', sd=1)
118-
sigma_algo_sd = pm.HalfNormal('sigma_algo_sd', sd=1)
119-
120-
sigma_author = pm.HalfNormal('sigma_author', sd=sigma_author_sd,
121-
shape=self.num_authors)
122-
sigma_algo = pm.HalfNormal('sigma_algo', sd=sigma_algo_sd,
123-
shape=self.num_algos)
124-
sigma_backtest = \
125-
pm.Deterministic(
126-
'sigma_backtest',
127-
np.sqrt(
128-
np.square(
129-
sigma_author[self.author_to_backtest_encoding]
130-
)
131-
+ np.square(
132-
sigma_algo[self.algo_to_backtest_encoding]
133-
)
134-
)
135-
)
119+
sigma_backtest = pm.Deterministic(
120+
'sigma_backtest',
121+
tt.sqrt(APPROX_BDAYS_PER_YEAR / data.meta_trading_days)
122+
)
136123

137124
alpha_author = pm.Deterministic('alpha_author',
138125
mu_global + mu_author)
@@ -181,10 +168,10 @@ def fit_authors(data,
181168
backtests), indexed by user, algorithm and code ID.
182169
Note that currently, backtests are deduplicated based on code id.
183170
::
184-
meta_user_id meta_algorithm_id meta_code_id sharpe_ratio
185-
0 abcdef123456 ghijkl789123 abcdef000000 0.919407
186-
1 abcdef123456 ghijkl789123 abcdef000001 1.129353
187-
2 abcdef123456 ghijkl789123 abcdef000002 -0.005934
171+
meta_user_id meta_algorithm_id meta_code_id meta_trading_days sharpe_ratio
172+
0 abcdef123456 ghijkl789123 abcdef000000 136 0.919407
173+
1 abcdef123456 ghijkl789123 abcdef000001 271 1.129353
174+
2 abcdef123456 ghijkl789123 abcdef000002 229 -0.005934
188175
189176
sampler_type : str
190177
Whether to use Markov chain Monte Carlo or variational inference.

0 commit comments

Comments
 (0)