Пример #1
0
    def __init__(self,
                 region: Region,
                 entity_schema: Type[EntityMixin] = Stock,
                 provider: Provider = Provider.Default,
                 entity_ids: List[str] = None,
                 exchanges: List[str] = None,
                 codes: List[str] = None,
                 the_timestamp: Union[str, pd.Timestamp] = None,
                 start_timestamp: Union[str, pd.Timestamp] = None,
                 end_timestamp: Union[str, pd.Timestamp] = None,
                 columns: List = None,
                 filters: List = None,
                 order: object = None,
                 limit: int = None,
                 level: Union[str, IntervalLevel] = IntervalLevel.LEVEL_1DAY,
                 category_field: str = 'entity_id',
                 time_field: str = 'timestamp',
                 computing_window: int = None,
                 keep_all_timestamp: bool = False,
                 fill_method: str = 'ffill',
                 effective_number: int = None,
                 transformer: Transformer = None,
                 accumulator: Accumulator = None,
                 need_persist: bool = False,
                 dry_run: bool = False,
                 factor_name: str = None,
                 clear_state: bool = False,
                 not_load_data: bool = False,
                 adjust_type: Union[AdjustType, str] = None) -> None:
        if columns is None:
            columns = [
                'id', 'entity_id', 'timestamp', 'level', 'open', 'close',
                'high', 'low'
            ]

        # 股票默认使用后复权
        if entity_schema == Stock and not adjust_type:
            adjust_type = AdjustType.hfq

        self.adjust_type = adjust_type
        entityType = EntityType(entity_schema.__name__.lower())
        self.data_schema = get_kdata_schema(entityType,
                                            level=level,
                                            adjust_type=adjust_type)

        if not factor_name:
            if type(level) == str:
                factor_name = f'{type(self).__name__.lower()}_{level}'
            else:
                factor_name = f'{type(self).__name__.lower()}_{level.value}'

        super().__init__(region, self.data_schema, entity_schema, provider,
                         entity_ids, exchanges, codes, the_timestamp,
                         start_timestamp, end_timestamp, columns, filters,
                         order, limit, level, category_field, time_field,
                         computing_window, keep_all_timestamp, fill_method,
                         effective_number, transformer, accumulator,
                         need_persist, dry_run, factor_name, clear_state,
                         not_load_data)
Пример #2
0
    def register(cls):
        # register the entity
        if issubclass(cls, EntityMixin):
            entity_type_ = entity_type
            if not entity_type:
                entity_type_ = EntityType(cls.__name__.lower())

            if entity_type_ not in entity_types:
                entity_types.append(entity_type_)
            zvt_context.entity_schema_map[entity_type_] = cls
        return cls
Пример #3
0
    def __init__(self,
                 region: Region,
                 entity_id,
                 timestamp,
                 window=100,
                 level=IntervalLevel.LEVEL_1DAY,
                 entity_schema=Stock,
                 range=0.3,
                 std=1) -> None:
        self.entity_id = entity_id
        self.window = window

        data_schema = get_kdata_schema(EntityType(entity_schema.__name__.lower()), level=level)

        self.df = get_kdata(region=region, entity_id=entity_id, level=level, end_timestamp=timestamp,
                            order=data_schema.timestamp.desc(),
                            limit=window, columns=['volume', 'open', 'close', 'high', 'low'])
        self.range = range
        self.std = std
Пример #4
0
def get_ref_vector(region: Region,
                   entity_id,
                   end,
                   window=100,
                   level=IntervalLevel.LEVEL_1DAY,
                   entity_schema=Stock):
    data_schema = get_kdata_schema(EntityType(entity_schema.__name__.lower()),
                                   level=level)

    df = get_kdata(region=region,
                   entity_id=entity_id,
                   level=level,
                   end_timestamp=end,
                   order=data_schema.timestamp.desc(),
                   limit=window,
                   columns=['close', 'volume'])

    exp_data = np.zeros((window, 2))
    exp_data[:, 0] = df['close']
    exp_data[:, 1] = df['volume']

    return exp_data
Пример #5
0
def decode_entity_id(entity_id: str):
    result = entity_id.split('_')
    entity_type = EntityType(result[0].lower())
    exchange = result[1]
    code = ''.join(result[2:])
    return entity_type, exchange, code