示例#1
0
    def _filter(self, R):
        # sh[col] = tools.sharpe(total_ret.div(total_weights, axis=0), alpha=0.000001)
        # to_remove = set(sh.index[sh - full_sharpe > 0.00001])

        SAMPLES = 50
        np.random.seed(42)
        sh = []
        for _ in range(SAMPLES):
            # get bootstrap sample
            R_sample = R.sample(n=len(R), replace=True)
            sh.append({
                col: tools.sharpe(R_sample[col], alpha=0.00001)
                for col in R_sample
            })
        sh = pd.DataFrame(sh)

        sh_diff = sh.subtract(sh["full"], 0)
        cdf = stats.norm.cdf(0.0,
                             loc=sh_diff.mean(),
                             scale=0.01 +
                             sh_diff.std() / np.sqrt(len(sh_diff)))
        to_remove = sh_diff.columns[cdf < self.threshold]
        to_remove = to_remove.drop("full", errors="ignore")

        print(list(to_remove))
        return to_remove
    def _filter(self, R):
        # sh[col] = tools.sharpe(total_ret.div(total_weights, axis=0), alpha=0.000001)
        # to_remove = set(sh.index[sh - full_sharpe > 0.00001])

        SAMPLES = 50
        np.random.seed(42)
        sh = []
        for _ in range(SAMPLES):
            # get bootstrap sample
            R_sample = R.sample(n=len(R), replace=True)
            sh.append({col: tools.sharpe(R_sample[col], alpha=0.00001) for col in R_sample})
        sh = pd.DataFrame(sh)

        sh_diff = sh.subtract(sh['full'], 0)
        cdf = stats.norm.cdf(0., loc=sh_diff.mean(), scale=0.01 + sh_diff.std() / np.sqrt(len(sh_diff)))
        to_remove = sh_diff.columns[cdf < self.threshold]
        to_remove = to_remove.drop('full', errors='ignore')

        print(list(to_remove))
        return to_remove
 def sharpe(self):
     """ Compute annualized sharpe ratio from log returns. If data does
     not contain datetime index, assume daily frequency with 252 trading days a year.
     """
     return tools.sharpe(self.r_log, rf_rate=self.rf_rate, freq=self.freq())
示例#4
0
 def sharpe(self):
     """ Compute annualized sharpe ratio from log returns. If data does
     not contain datetime index, assume daily frequency with 252 trading days a year.
     """
     return tools.sharpe(self.r_log, rf_rate=self.rf_rate, freq=self.freq())