コード例 #1
0
ファイル: analyzes.py プロジェクト: vzs/ppQuanTrade
    def overall_metrics(self, timestamp='one_month', metrics=None, save=False, db_id=None):
        '''
        Use zipline results to compute some performance indicators and store it in database
        '''
        perfs = dict()

        # If no rolling perfs provided, computes it
        if metrics is None:
            metrics = self.rolling_performances(timestamp=timestamp, save=False, db_id=db_id)
        riskfree = np.mean(metrics['Treasury.Returns'])

        #NOTE Script args define default database table name (test), make it consistent
        if db_id is None:
            db_id = self.configuration['algorithm'] + pd.datetime.strftime(pd.datetime.now(), format='%Y%m%d')
        perfs['Name']              = db_id
        perfs['Sharpe.Ratio']      = qstk_get_sharpe_ratio(metrics['Returns'].values, risk_free=riskfree)
        perfs['Returns']           = (((metrics['Returns'] + 1).cumprod()) - 1)[-1]
        perfs['Max.Drawdown']      = max(metrics['Max.Drawdown'])
        perfs['Volatility']        = np.mean(metrics['Volatility'])
        perfs['Beta']              = np.mean(metrics['Beta'])
        perfs['Alpha']             = np.mean(metrics['Alpha'])
        perfs['Benchmark.Returns'] = (((metrics['Benchmark.Returns'] + 1).cumprod()) - 1)[-1]

        if save:
            self.datafeed.stock_db.save_performances(perfs)
        return perfs
コード例 #2
0
    def overall_metrics(self, timestamp='one_month', metrics=None, save=False, db_id=None):
        '''
        Use zipline results to compute some performance indicators and store it in database
        '''
        perfs = dict()

        # If no rolling perfs provided, computes it
        if metrics is None:
            metrics = self.rolling_performances(timestamp=timestamp, save=False, db_id=db_id)
        riskfree = np.mean(metrics['Treasury.Returns'])

        #NOTE Script args define default database table name (test), make it consistent
        if db_id is None:
            db_id = self.configuration['algorithm'] + pd.datetime.strftime(pd.datetime.now(), format='%Y%m%d')
        perfs['Name']              = db_id
        perfs['Sharpe.Ratio']      = qstk_get_sharpe_ratio(metrics['Returns'].values, risk_free=riskfree)
        perfs['Returns']           = (((metrics['Returns'] + 1).cumprod()) - 1)[-1]
        perfs['Max.Drawdown']      = max(metrics['Max.Drawdown'])
        perfs['Volatility']        = np.mean(metrics['Volatility'])
        perfs['Beta']              = np.mean(metrics['Beta'])
        perfs['Alpha']             = np.mean(metrics['Alpha'])
        perfs['Benchmark.Returns'] = (((metrics['Benchmark.Returns'] + 1).cumprod()) - 1)[-1]

        if save:
            self.datafeed.stock_db.save_performances(perfs)
        return perfs
コード例 #3
0
ファイル: analyzes.py プロジェクト: SethCalkins/intuition
    def overall_metrics(self, timestamp='one_month', metrics=None):
        '''
        Use zipline results to compute some performance indicators
        '''
        perfs = dict()

        # If no rolling perfs provided, computes it
        if metrics is None:
            metrics = self.rolling_performances(timestamp=timestamp)
        riskfree = np.mean(metrics['treasury_period_return'])

        perfs['sharpe'] = qstk_get_sharpe_ratio(
            metrics['algorithm_period_return'].values, risk_free=riskfree)
        perfs['algorithm_period_return'] = (
            ((metrics['algorithm_period_return'] + 1).cumprod()) - 1)[-1]
        perfs['max_drawdown'] = max(metrics['max_drawdown'])
        perfs['algo_volatility'] = np.mean(metrics['algo_volatility'])
        perfs['beta'] = np.mean(metrics['beta'])
        perfs['alpha'] = np.mean(metrics['alpha'])
        perfs['benchmark_period_return'] = (
            ((metrics['benchmark_period_return'] + 1).cumprod()) - 1)[-1]

        return perfs