def test_ma_transformer(): df = get_kdata(entity_id='stock_sz_000338', start_timestamp='2019-01-01', provider='joinquant') t = MaTransformer(windows=[5, 10]) result_df = t.transform(df) print(result_df)
def test_ma_transformer(): df = get_kdata(region=Region.CHN, entity_id='stock_sz_000338', start_timestamp='2019-01-01', provider=Provider.JoinQuant, index=['entity_id', 'timestamp']) t = MaTransformer(windows=[5, 10]) result_df = t.transform(df) print(result_df)
def test_ma_transformer(): df = get_kdata( entity_id="stock_sz_000338", start_timestamp="2019-01-01", provider="joinquant", index=["entity_id", "timestamp"], ) t = MaTransformer(windows=[5, 10]) result_df = t.transform(df) print(result_df)
def __init__(self, entity_ids: List[str] = None, entity_type: str = 'stock', exchanges: List[str] = ['sh', 'sz'], 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, provider: str = 'joinquant', level: Union[str, IntervalLevel] = IntervalLevel.LEVEL_1DAY, category_field: str = 'entity_id', time_field: str = 'timestamp', computing_window: int = 250, keep_all_timestamp: bool = False, fill_method: str = 'ffill', effective_number: int = 10, need_persist: bool = True, dry_run: bool = True, windows=[5, 10, 34, 55, 89, 144, 120, 250]) -> None: self.factor_schema = get_ma_factor_schema(entity_type=entity_type, level=level) self.windows = windows transformer: Transformer = MaTransformer(windows=windows) super().__init__(entity_ids, entity_type, exchanges, codes, the_timestamp, start_timestamp, end_timestamp, columns, filters, order, limit, provider, level, category_field, time_field, computing_window, keep_all_timestamp, fill_method, effective_number, transformer, None, need_persist, dry_run)
def test_ma(): factor = TechnicalFactor(codes=['000338'], start_timestamp='2019-01-01', end_timestamp='2019-06-10', level=IntervalLevel.LEVEL_1DAY, provider=Provider.JoinQuant, computing_window=30, transformer=MaTransformer(windows=[5, 10, 30]), adjust_type='qfq') print(factor.factor_df.tail()) # compare with east money manually ma5 = factor.factor_df['ma5'] ma10 = factor.factor_df['ma10'] ma30 = factor.factor_df['ma30'] assert round(ma5.loc[('stock_sz_000338', '2019-06-10')], 2) <= 11.23 assert round(ma10.loc[('stock_sz_000338', '2019-06-10')], 2) <= 11.43 assert round(ma30.loc[('stock_sz_000338', '2019-06-10')], 2) <= 11.52 factor.move_on(to_timestamp='2019-06-17') ma5 = factor.factor_df['ma5'] ma10 = factor.factor_df['ma10'] ma30 = factor.factor_df['ma30'] assert round(ma5.loc[('stock_sz_000338', '2019-06-17')], 2) <= 12.06 assert round(ma10.loc[('stock_sz_000338', '2019-06-17')], 2) <= 11.64 assert round(ma30.loc[('stock_sz_000338', '2019-06-17')], 2) <= 11.50
def __init__(self, entity_ids: List[str] = None, entity_type: str = 'stock', exchanges: List[str] = ['sh', 'sz'], 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, provider: str = 'joinquant', level: IntervalLevel = IntervalLevel.LEVEL_1DAY, need_persist: bool = False, dry_run: bool = False, # child added arguments short_window=5, long_window=10) -> None: self.short_window = short_window self.long_window = long_window transformer = MaTransformer(windows=[short_window, long_window]) super().__init__(entity_ids, entity_type, exchanges, codes, the_timestamp, start_timestamp, end_timestamp, columns, filters, order, limit, provider, level, 'entity_id', 'timestamp', long_window, False, None, None, transformer, None, need_persist, dry_run)
def test_ma(): factor = TechnicalFactor( provider="joinquant", codes=["000338"], start_timestamp="2019-01-01", end_timestamp="2019-06-10", level=IntervalLevel.LEVEL_1DAY, computing_window=30, transformer=MaTransformer(windows=[5, 10, 30]), adjust_type="qfq", ) print(factor.factor_df.tail()) # compare with east money manually ma5 = factor.factor_df["ma5"] ma10 = factor.factor_df["ma10"] ma30 = factor.factor_df["ma30"] assert round(ma5.loc[("stock_sz_000338", "2019-06-10")], 2) <= 11.23 assert round(ma10.loc[("stock_sz_000338", "2019-06-10")], 2) <= 11.43 assert round(ma30.loc[("stock_sz_000338", "2019-06-10")], 2) <= 11.52 factor.move_on(to_timestamp="2019-06-17") ma5 = factor.factor_df["ma5"] ma10 = factor.factor_df["ma10"] ma30 = factor.factor_df["ma30"] assert round(ma5.loc[("stock_sz_000338", "2019-06-17")], 2) <= 12.06 assert round(ma10.loc[("stock_sz_000338", "2019-06-17")], 2) <= 11.64 assert round(ma30.loc[("stock_sz_000338", "2019-06-17")], 2) <= 11.50
def __init__( self, region: Region, entity_schema: EntityMixin = Stock, provider: Provider = Provider.Default, entity_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 = [ 'id', 'entity_id', 'timestamp', 'level', 'open', 'close', 'high', 'low' ], 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 = 10, keep_all_timestamp: bool = False, fill_method: str = 'ffill', effective_number: int = None, need_persist: bool = True, dry_run: bool = True, # added fields short_window: int = 5, long_window: int = 10) -> None: self.factor_schema = get_ma_state_stats_schema(entity_type=EntityType( entity_schema.__name__.lower()), level=level) self.short_window = short_window self.long_window = long_window transformer: Transformer = MaTransformer( windows=[short_window, long_window], cal_change_pct=True) accumulator = MaAccumulator(short_window=short_window, long_window=long_window) super().__init__(region, entity_schema, provider, entity_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)
def __init__(self, region: Region, entity_schema: EntityMixin = Stock, provider: Provider = Provider.Default, entity_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 = [ 'id', 'entity_id', 'timestamp', 'level', 'open', 'close', 'high', 'low' ], 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, accumulator: Accumulator = None, need_persist: bool = False, dry_run: bool = False, windows=[5, 10, 34, 55, 89, 144, 120, 250], adjust_type: Union[AdjustType, str] = None) -> None: self.adjust_type = adjust_type self.factor_schema = get_ma_factor_schema(entity_type=EntityType( entity_schema.__name__.lower()), level=level) self.windows = windows transformer: Transformer = MaTransformer(windows=windows) super().__init__(region, entity_schema, provider, entity_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, adjust_type)
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, 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, windows=None) -> None: if need_persist: self.factor_schema = get_ma_factor_schema( entity_type=entity_schema.__name__, level=level) if not windows: windows = [5, 10, 34, 55, 89, 144, 120, 250] self.windows = windows transformer: Transformer = MaTransformer(windows=windows) super().__init__(region, 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, None, need_persist, dry_run, factor_name, clear_state, not_load_data, adjust_type)
def __init__(self, entity_ids: List[str] = None, entity_type: str = 'stock', exchanges: List[str] = ['sh', 'sz'], 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, provider: str = 'joinquant', level: Union[str, IntervalLevel] = IntervalLevel.LEVEL_1DAY, category_field: str = 'entity_id', time_field: str = 'timestamp', computing_window: int = 10, keep_all_timestamp: bool = False, fill_method: str = 'ffill', effective_number: int = 10, persist_factor: bool = True, dry_run: bool = True, # added fields short_window: int = 5, long_window: int = 10) -> None: self.factor_schema = get_ma_state_stats_schema(entity_type=entity_type, level=level) self.short_window = short_window self.long_window = long_window transformer: Transformer = MaTransformer(windows=[short_window, long_window]) acc = MaAccumulator(short_window=short_window, long_window=long_window) super().__init__(entity_ids, entity_type, exchanges, codes, the_timestamp, start_timestamp, end_timestamp, columns, filters, order, limit, provider, level, category_field, time_field, computing_window, keep_all_timestamp, fill_method, effective_number, transformer, acc, persist_factor, dry_run)
def __init__( self, entity_schema: Type[TradableEntity] = Stock, provider: str = None, entity_provider: str = None, entity_ids: List[str] = None, exchanges: List[str] = None, codes: List[str] = 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, need_persist: bool = False, only_compute_factor: bool = False, factor_name: str = None, clear_state: bool = False, only_load_factor: bool = False, adjust_type: Union[AdjustType, str] = None, windows=None, ) -> None: if need_persist: self.factor_schema = get_ma_factor_schema(entity_type=entity_schema.__name__, level=level) if not windows: windows = [5, 10, 34, 55, 89, 144, 120, 250] self.windows = windows transformer: Transformer = MaTransformer(windows=windows) super().__init__( entity_schema, provider, entity_provider, entity_ids, exchanges, codes, start_timestamp, end_timestamp, columns, filters, order, limit, level, category_field, time_field, computing_window, keep_all_timestamp, fill_method, effective_number, transformer, None, need_persist, only_compute_factor, factor_name, clear_state, only_load_factor, adjust_type, )