|
9 | 9 | import pandas as pd
|
10 | 10 | from sklearn.preprocessing import LabelEncoder
|
11 | 11 | import pymc3 as pm
|
| 12 | +import theano.tensor as tt |
12 | 13 | import xarray as xr
|
13 | 14 | from .serialize import to_xarray
|
14 | 15 | from ._version import get_versions
|
15 | 16 | from .base import BayesAlphaResult
|
16 | 17 |
|
17 | 18 | AUTHOR_MODEL_TYPE = 'author-model'
|
| 19 | +APPROX_BDAYS_PER_YEAR = 252 |
18 | 20 |
|
19 | 21 |
|
20 | 22 | class AuthorModelBuilder(object):
|
@@ -114,25 +116,10 @@ def _build_model(self, data):
|
114 | 116 | + mu_author[self.author_to_backtest_encoding]
|
115 | 117 | + mu_algo[self.algo_to_backtest_encoding])
|
116 | 118 |
|
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 | + ) |
136 | 123 |
|
137 | 124 | alpha_author = pm.Deterministic('alpha_author',
|
138 | 125 | mu_global + mu_author)
|
@@ -181,10 +168,10 @@ def fit_authors(data,
|
181 | 168 | backtests), indexed by user, algorithm and code ID.
|
182 | 169 | Note that currently, backtests are deduplicated based on code id.
|
183 | 170 | ::
|
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 |
188 | 175 |
|
189 | 176 | sampler_type : str
|
190 | 177 | Whether to use Markov chain Monte Carlo or variational inference.
|
|
0 commit comments