def model_best(y1, y2, samples=<NUM_LIT:1000>, progressbar=True):
y = np.concatenate((y1, y2))<EOL>mu_m = np.mean(y)<EOL>mu_p = <NUM_LIT> * <NUM_LIT:1> / np.std(y)**<NUM_LIT:2><EOL>sigma_low = np.std(y) / <NUM_LIT:1000><EOL>sigma_high = np.std(y) * <NUM_LIT:1000><EOL>with pm.Model() as model:<EOL><INDENT>group1_mean = pm.Normal('<STR_LIT>', mu=mu_m, tau=mu_p,<EOL>testval=y1.mean())<EOL>group2_mean = pm.Normal('<STR_LIT>', mu=mu_m, tau=mu_p,<EOL>testval=y2.mean())<EOL>group1_std = pm.Uniform('<STR_LIT>', lower=sigma_low,<EOL>upper=sigma_high, testval=y1.std())<EOL>group2_std = pm.Uniform('<STR_LIT>', lower=sigma_low,<EOL>upper=sigma_high, testval=y2.std())<EOL>nu = pm.Exponential('<STR_LIT>', <NUM_LIT:1> / <NUM_LIT>, testval=<NUM_LIT>) + <NUM_LIT><EOL>returns_group1 = pm.StudentT('<STR_LIT>', nu=nu, mu=group1_mean,<EOL>lam=group1_std**-<NUM_LIT:2>, observed=y1)<EOL>returns_group2 = pm.StudentT('<STR_LIT>', nu=nu, mu=group2_mean,<EOL>lam=group2_std**-<NUM_LIT:2>, observed=y2)<EOL>diff_of_means = pm.Deterministic('<STR_LIT>',<EOL>group2_mean - group1_mean)<EOL>pm.Deterministic('<STR_LIT>',<EOL>group2_std - group1_std)<EOL>pm.Deterministic('<STR_LIT>', diff_of_means /<EOL>pm.math.sqrt((group1_std**<NUM_LIT:2> +<EOL>group2_std**<NUM_LIT:2>) / <NUM_LIT:2>))<EOL>pm.Deterministic('<STR_LIT>',<EOL>returns_group1.distribution.variance**<NUM_LIT> *<EOL>np.sqrt(<NUM_LIT>))<EOL>pm.Deterministic('<STR_LIT>',<EOL>returns_group2.distribution.variance**<NUM_LIT> *<EOL>np.sqrt(<NUM_LIT>))<EOL>pm.Deterministic('<STR_LIT>', returns_group1.distribution.mean /<EOL>returns_group1.distribution.variance**<NUM_LIT> *<EOL>np.sqrt(<NUM_LIT>))<EOL>pm.Deterministic('<STR_LIT>', returns_group2.distribution.mean /<EOL>returns_group2.distribution.variance**<NUM_LIT> *<EOL>np.sqrt(<NUM_LIT>))<EOL>trace = pm.sample(samples, progressbar=progressbar)<EOL><DEDENT>return model, trace<EOL>
Bayesian Estimation Supersedes the T-Test

This model runs a Bayesian hypothesis comparing if y1 and y2 come
from the same distribution. Returns are assumed to be T-distributed.

In addition, computes annual volatility and Sharpe of in and
out-of-sample periods.

This model replicates the example used in:
Kruschke, John. (2012) Bayesian estimation supersedes the t
test. Journal of Experimental Psychology: General.

Parameters
----------
y1 : array-like
    Array of returns (e.g. in-sample)
y2 : array-like
    Array of returns (e.g. out-of-sample)
samples : int, optional
    Number of posterior samples to draw.

Returns
-------
model : pymc.Model object
    PyMC3 model containing all random variables.
trace : pymc3.sampling.BaseTrace object
    A PyMC3 trace object that contains samples for each parameter
    of the posterior.

See Also
--------
plot_stoch_vol : plotting of tochastic volatility model