示例#1
0
 def __init__(self, alpha):
     if isinstance(alpha, AlphaBase):
         self.alpha = alpha.get_alphas()
     else:
         self.alpha = api.format(alpha)
     self.alpha = self.alpha[np.isfinite(self.alpha)]
     self.startdate = self.alpha.index[0]
示例#2
0
 def __init__(self, alpha):
     if isinstance(alpha, AlphaBase):
         self.alpha = alpha.get_alphas()
     else:
         self.alpha = api.format(alpha)
     self.alpha = self.alpha[np.isfinite(self.alpha)]
     self.startdate = self.alpha.index[0]
示例#3
0
 def test_format(self):
     df1 = pd.DataFrame(np.random.randn(20, 40),
                        index=DATES[:20],
                        columns=SIDS[:40])
     df2 = api.format(df1)
     self.assertTrue((df2.index == pd.to_datetime(df1.index)).all() and \
             (list(df2.columns) == SIDS))
示例#4
0
    def get_alphas(self):
        """Return the generated alphas in a DataFrame."""
        if self._alphas is not None:
            return self._alphas

        df = format(pd.DataFrame(self.alphas).T, full_sids=False)
        self._alphas = df
        return df
示例#5
0
 def __init__(self, alpha):
     if isinstance(alpha, AlphaBase):
         self.alpha = alpha.get_alphas()
     else:
         self.alpha = api.format(alpha)
     self.dates = np.unique(self.alpha.index.date)
     self.startdate = self.dates[0]
     self.freq = len(self.alpha) / len(self.dates)
     self.freq = str(240 / self.freq) + 'min'
示例#6
0
 def __init__(self, alpha):
     if isinstance(alpha, AlphaBase):
         self.alpha = alpha.get_alphas()
     else:
         self.alpha = api.format(alpha)
     self.dates = np.unique(self.alpha.index.date)
     self.startdate = self.dates[0]
     self.freq = len(self.alpha) / len(self.dates)
     self.freq = str(240 / self.freq) + 'min'
示例#7
0
 def __init__(self, alpha, n, rank=None):
     self.alpha = api.format(alpha)
     self.rank_alpha = self.alpha.rank(axis=1, ascending=False)
     self.rank_alpha = self.rank_alpha[self.rank_alpha <= n]
     if rank is None:
         self.alpha = (self.rank_alpha <= n).astype(float)
     else:
         if rank < 0:
             self.alpha = self.alpha[self.rank_alpha <= n]
         else:
             self.alpha = rank - np.floor(self.rank_alpha / (n + 1) * rank)
     self.alpha = api.scale(self.alpha)
     self.dates = dateutil.to_datestr(self.alpha.index)
示例#8
0
 def set_index_components(cls, index, components):
     """Call this method to set index components data so that for future uses, there is no need to interact with MongoDB."""
     with cls.mongo_lock:
         cls.index_components[index] = api.format(components).fillna(False)
示例#9
0
 def set_returns(cls, returns):
     """Call this method to set returns so that for future uses, there is no need to interact with MongoDB."""
     with cls.mongo_lock:
         cls.returns = api.format(returns)
示例#10
0
 def set_index_components(cls, index, components):
     """Call this method to set index components data so that for future uses, there is no need to interact with MongoDB."""
     with cls.mongo_lock:
         cls.index_components[index] = api.format(components).fillna(False)
示例#11
0
 def set_returns(cls, returns):
     """Call this method to set returns so that for future uses, there is no need to interact with MongoDB."""
     with cls.mongo_lock:
         cls.returns = api.format(returns)