def random_intalpha(startdate='20140103', freq='30min', n=None): if not n >= 0: n = np.random.randint(10, 20) dates = dateutil.get_startfrom(DATES, dateutil.compliment_datestring(str(startdate), -1, True), n) times = dateutil.generate_intervals(int(freq[:-3])*60) dts = pd.to_datetime([d+' '+t for d in dates for t in times]) df = pd.DataFrame(np.random.randn(len(dts), len(SIDS)), index=dts, columns=SIDS) return df
def random_alpha(startdate='20140103', n=None, datetime_index=True): """Generate a random alpha(i.e. a DataFrame of random floats with DatetimeINdex and full sids columns). :param startdate: Starting point. Default: '20140103' :type startdate: int, str :param int n: Length of the returned DataFrame; when None, it will be a random number between 50 and 100. Default: None :param boolean datetime_index: Whether to format the DataFrame with DatetimeIndex. Default: True """ if not n >= 0: n = np.random.randint(50, 100) dates = dateutil.get_startfrom(DATES, dateutil.compliment_datestring(str(startdate), -1, True), n) df = pd.DataFrame(np.random.randn(n, len(SIDS)), index=dates, columns=SIDS) if datetime_index: df.index = pd.to_datetime(df.index) return df
frames_equal, ) from orca.utils import dateutil from orca.universe.special import ( TickerFilter, TradingDaysFilter, ActiveFilter, ComponentsFilter, IndustryFilter, ) from orca.universe.rules import ( startswith, count_gt, ) window = dateutil.get_startfrom(DATES, '20140104', 50) close = QuoteFetcher(datetime_index=True, reindex=True).fetch_window('close', window) hs300 = ComponentsFetcher(datetime_index=True, reindex=True).fetch_window('HS300', window) sector = IndustryFetcher(datetime_index=True, reindex=True).fetch_window('sector', window) class SpecialTestCase(unittest.TestCase): def test_ticker_filter(self): sh = TickerFilter(startswith('60')).filter_daily(window[0]) dct = {sid: sid[:2] == '60' for sid in SIDS} self.assertEqual(sh.to_dict(), dct) def test_trading_days_filter(self):
def setUp(self): self.fetcher = IndexQuoteFetcher() self.dates = dateutil.get_startfrom(DATES, '20140101', 20)
def setUp(self): self.fetcher = KDayFetcherDummy() self.dates_str = dateutil.get_startfrom(DATES, '20140101', 50) self.dates_pddt = pd.to_datetime(self.dates_str)
def setUp(self): self.fetcher = KMinFetcherDummy() self.dates_str = dateutil.get_startfrom(DATES, '20140101', 50) self.times = list( dateutil.generate_timestamps('100000', '113000', 30 * 60)) self.dates_pddt = pd.to_datetime(self.dates_str)
def setUp(self): self.filter = SimpleDataFilterDummy() self.fetcher = QuoteFetcher(datetime_index=True, reindex=True) self.dates = dateutil.get_startfrom(DATES, '20140801', 20) self.startdate, self.enddate = self.dates[0], self.dates[-1] self.si, self.ei = map(DATES.index, [self.startdate, self.enddate])
def setUp(self): self.fetcher = ComponentsFetcher() self.dates = dateutil.get_startfrom(DATES, '20140101', 10)
def setUp(self): self.adjfetcher = AdjQuoteFetcher() self.fetcher = QuoteFetcher() self.dates = get_startfrom(DATES, '20140101', 50)
def setUp(self): self.fetcher = KMinFetcherDummy() self.dates_str = dateutil.get_startfrom(DATES, '20140101', 50) self.times = list(dateutil.generate_timestamps('100000', '113000', 30*60)) self.dates_pddt = pd.to_datetime(self.dates_str)
import numpy as np import pandas as pd from orca import ( DATES, SIDS, ) from orca.utils.testing import ( series_equal, frames_equal, ) from orca.utils import dateutil from orca.perf.analyser import Analyser from orca.perf.performance import Performance dates = pd.to_datetime(dateutil.get_startfrom(DATES, '20140101', 120)) alpha1 = pd.DataFrame(np.random.randn(len(dates), len(SIDS)), index=dates, columns=SIDS) valid = pd.DataFrame(np.random.randint(3, size=alpha1.shape), index=dates, columns=SIDS).astype(bool) alpha1[~valid] = np.nan # long-short alpha alpha1 = alpha1.subtract(alpha1.mean(axis=1), axis=0) valid = pd.DataFrame(np.random.randint(4, size=alpha1.shape), index=dates, columns=SIDS).astype(bool) data = pd.DataFrame(np.random.randn(*alpha1.shape), index=dates, columns=SIDS) data[~valid] = np.nan # long part alpha2 = alpha1[alpha1>0] # short part alpha3 = -alpha1[alpha1<0]
frames_equal, ) from orca.utils import dateutil from orca.universe.special import ( TickerFilter, TradingDaysFilter, ActiveFilter, ComponentsFilter, IndustryFilter, ) from orca.universe.rules import ( startswith, count_gt, ) window = dateutil.get_startfrom(DATES, '20140104', 50) close = QuoteFetcher(datetime_index=True, reindex=True).fetch_window('close', window) hs300 = ComponentsFetcher(datetime_index=True, reindex=True).fetch_window('HS300', window) sector = IndustryFetcher(datetime_index=True, reindex=True).fetch_window('sector', window) class SpecialTestCase(unittest.TestCase): def test_ticker_filter(self): sh = TickerFilter(startswith('60')).filter_daily(window[0]) dct = {sid: sid[:2] == '60' for sid in SIDS} self.assertEqual(sh.to_dict(), dct) def test_trading_days_filter(self): trd_filter = TradingDaysFilter(50, count_gt(40), delay=0) trd1 = trd_filter.filter_daily(window[-1])
import numpy as np import pandas as pd from orca import ( DATES, SIDS, ) from orca.utils.testing import ( series_equal, frames_equal, ) from orca.utils import dateutil from orca.perf.analyser import Analyser from orca.perf.performance import Performance dates = pd.to_datetime(dateutil.get_startfrom(DATES, '20140101', 120)) alpha1 = pd.DataFrame(np.random.randn(len(dates), len(SIDS)), index=dates, columns=SIDS) valid = pd.DataFrame(np.random.randint(3, size=alpha1.shape), index=dates, columns=SIDS).astype(bool) alpha1[~valid] = np.nan # long-short alpha alpha1 = alpha1.subtract(alpha1.mean(axis=1), axis=0) valid = pd.DataFrame(np.random.randint(4, size=alpha1.shape), index=dates, columns=SIDS).astype(bool) data = pd.DataFrame(np.random.randn(*alpha1.shape), index=dates, columns=SIDS) data[~valid] = np.nan
def setUp(self): self.fetcher = QuoteFetcher() self.dates = get_startfrom(DATES, '2014010', 50)