def calculate_beta(self):
        # it doesn't make much sense to calculate beta for less than two
        # values, so return none.
        if len(self.algorithm_returns) < 2:
            return 0.0

        returns_matrix = np.vstack([self.algorithm_returns,
                                    self.benchmark_returns])
        C = np.cov(returns_matrix, ddof=1)
        algorithm_covariance = C[0][1]
        benchmark_variance = C[1][1]
        beta = algorithm_covariance / benchmark_variance

        return beta
|OpcPackage| instance this part belongs to.
dataset/ETHPy150Open quantopian/zipline/zipline/finance/risk/cumulative.py/RiskMetricsCumulative.calculate_beta--crossover with--dataset/ETHPy150Open scanny/python-pptx/pptx/opc/package.py/Part.package