def find_experiment_ids_by_assets(assets): assets_str = pg.array2pgarray(assets) query = ''' SELECT * FROM experiments WHERE asset_columns = \'{0}\' '''.format(assets_str) return pd.read_sql(query, conn)
experiment = db.load_experiment(experiment_id) backtest_params = db.load_backtests([backtest_id]) returns = db.load_returns(experiment) excess_returns = returns.values train, test = backtest.split_returns( excess_returns, backtest_params['update_periods'], backtest_params['trailing_periods']) portfolios = pg.decimallistseries2nparray(results.portfolio_weights) portfolio_returns = pg.decimallistseries2nparray(results.test_returns) train_mean = ps.mean(portfolios[0,:], train[0]) train_variance = ps.variance(portfolios[0,:], train[0]) eta = results.eta.iloc[0] backtest_statistics = ps.rkw_statistics( portfolios, portfolio_returns, eta=eta) test_statistics = backtest_statistics['statistics'] agg_returns = backtest_statistics['aggregate_returns'] output = test_statistics output['aggregate_returns'] = pg.array2pgarray(agg_returns) output['train_mean_return'] = train_mean output['train_variance'] = train_variance output['parameters_id'] = parameters_id output['experiment_id'] = experiment_id output['backtest_id'] = backtest_id outputs.append(output) output_table = pd.DataFrame(outputs) output_table.to_csv('dcc_backtest_statistics.csv', index=False)