Ejemplo n.º 1
0
    def __init__(self,
                 file_path,
                 metric,
                 num_prev_bars=3,
                 exp_num_ticks_init=100000,
                 batch_size=2e7):
        """
        Constructor

        :param file_path: (String) Path to the csv file containing raw tick data in the format[date_time, price, volume]
        :param metric: (String) type of imbalance bar to create. Example: "dollar_imbalance"
        :param num_prev_bars: (Int) Window size for E[T]
        :param exp_num_ticks_init: (Int) Initial number of expected ticks
        :param batch_size: (Int) Number of rows to read in from the csv, per batch
        """
        BaseBars.__init__(self, file_path, metric, batch_size)

        # Information bar properties
        self.exp_num_ticks_init = exp_num_ticks_init
        # Expected number of ticks extracted from prev bars
        self.exp_num_ticks = self.exp_num_ticks_init
        self.num_prev_bars = num_prev_bars
        self.num_ticks_bar = []  # List of number of ticks from previous bars

        # Named tuple to help with storing the cache
        self.cache_tuple = namedtuple('CacheData', [
            'date_time', 'price', 'high', 'low', 'cum_ticks', 'cum_volume',
            'cum_theta_buy', 'cum_theta_sell'
        ])
        self.imbalance_array = {'buy': [], 'sell': []}
        self.exp_buy_proportion, self.exp_sell_proportion = np.nan, np.nan
Ejemplo n.º 2
0
    def __init__(self, file_path_or_df: Tuple[str, pd.DataFrame], metric: str, threshold: int = 50000,
                 batch_size: int = 20000000):

        BaseBars.__init__(self, file_path_or_df, metric, batch_size)

        # Threshold at which to sample
        self.threshold = threshold
Ejemplo n.º 3
0
    def __init__(self,
                 resolution: str,
                 num_units: int,
                 batch_size: int = 20000000):
        """
        Constructor

        :param resolution: (str) Type of bar resolution: ['D', 'H', 'MIN', 'S']
        :param num_units: (int) Number of days, minutes, etc.
        :param batch_size: (int) Number of rows to read in from the csv, per batch
        """
        BaseBars.__init__(self, metric=None, batch_size=batch_size)

        # Threshold at which to sample (in seconds)
        self.time_bar_thresh_mapping = {
            'D': 86400,
            'H': 3600,
            'MIN': 60,
            'S': 1
        }  # Number of seconds
        assert resolution in self.time_bar_thresh_mapping, "{} resolution is not implemented".format(
            resolution)
        self.resolution = resolution  # Type of bar resolution: 'D', 'H', 'MIN', 'S'
        self.num_units = num_units  # Number of days/minutes/...
        self.threshold = self.num_units * self.time_bar_thresh_mapping[
            self.resolution]
        self.timestamp = None  # Current bar timestamp
Ejemplo n.º 4
0
    def __init__(self, file_path_or_df, resolution, num_units, batch_size=20000000):

        BaseBars.__init__(self, file_path_or_df, metric=None, batch_size=batch_size)

        # Threshold at which to sample (in seconds)
        self.resolution = resolution  # Type of bar resolution: 'D', 'H', 'MIN', 'S'
        self.num_units = num_units  # Number of days/minutes/...
        self.time_bar_thresh_mapping = {'D': 86400, 'H': 3600, 'MIN': 60, 'S': 1}  # Number of seconds
        self.threshold = self.num_units * self.time_bar_thresh_mapping[self.resolution]
        self.timestamp = None  # Next bar timestamp
    def __init__(self, resolution: str, num_units: int, batch_size: int = 20000000):

        BaseBars.__init__(self, metric=None, batch_size=batch_size)

        # Threshold at which to sample (in seconds)
        self.time_bar_thresh_mapping = {'D': 86400, 'H': 3600, 'MIN': 60, 'S': 1}  # Number of seconds
        assert resolution in self.time_bar_thresh_mapping, "{} resolution is not implemented".format(resolution)
        self.resolution = resolution  # Type of bar resolution: 'D', 'H', 'MIN', 'S'
        self.num_units = num_units  # Number of days/minutes/...
        self.threshold = self.num_units * self.time_bar_thresh_mapping[self.resolution]
        self.timestamp = None  # Current bar timestamp
Ejemplo n.º 6
0
    def __init__(self,
                 metric: str,
                 threshold: int = 50000,
                 batch_size: int = 20000000):
        """
        Constructor

        :param metric: (str) Type of run bar to create. Example: "dollar_run"
        :param threshold: (int) Threshold at which to sample
        :param batch_size: (int) Number of rows to read in from the csv, per batch
        """
        BaseBars.__init__(self, metric, batch_size)

        # Threshold at which to sample
        self.threshold = threshold
Ejemplo n.º 7
0
    def __init__(self,
                 file_path,
                 metric,
                 threshold=50000,
                 batch_size=20000000):

        BaseBars.__init__(self, file_path, metric, batch_size)

        # Threshold at which to sample
        self.threshold = threshold
        # Named tuple to help with the cache
        self.cache_tuple = namedtuple('CacheData', [
            'date_time', 'price', 'high', 'low', 'cum_ticks', 'cum_volume',
            'cum_dollar'
        ])
Ejemplo n.º 8
0
    def __init__(self, metric: str, threshold: int = 50000, batch_size: int = 20000000):

        BaseBars.__init__(self, metric, batch_size)

        # Threshold at which to sample
        self.threshold = threshold