示例#1
0
 def get_moneyflow_data(provider: Provider, sleep, desc, pc, lock, region,
                        batch):
     # 股票资金流向表
     StockMoneyFlow.record_data(provider=provider,
                                share_para=(desc, pc, lock, True, region),
                                sleeping_time=sleep,
                                batch_size=batch)
示例#2
0
    def record(self, entity, start, end, size, timestamps, http_session):
        # 上证
        if entity.code == '000001':
            all_df = StockMoneyFlow.query_data(
                region=self.region,
                provider=self.provider,
                start_timestamp=start,
                filters=[StockMoneyFlow.entity_id.like('stock_sh%')])
        # 深证
        elif entity.code == '399001':
            all_df = StockMoneyFlow.query_data(
                region=self.region,
                provider=self.provider,
                start_timestamp=start,
                filters=[StockMoneyFlow.entity_id.like('stock_sz%')])
        # 创业板
        elif entity.code == '399006':
            all_df = StockMoneyFlow.query_data(
                region=self.region,
                provider=self.provider,
                start_timestamp=start,
                filters=[StockMoneyFlow.code.like('300%')])
        # 科创板
        elif entity.code == '000688':
            all_df = StockMoneyFlow.query_data(
                region=self.region,
                provider=self.provider,
                start_timestamp=start,
                filters=[StockMoneyFlow.code.like('688%')])

        if pd_is_not_null(all_df):
            return all_df
        return None
示例#3
0
    def record(self, entity, start, end, size, timestamps):
        # 上证
        if entity.code == '000001':
            all_df = StockMoneyFlow.query_data(
                provider=self.provider,
                start_timestamp=start,
                filters=[StockMoneyFlow.entity_id.like('stock_sh%')])
        # 深证
        elif entity.code == '399001':
            all_df = StockMoneyFlow.query_data(
                provider=self.provider,
                start_timestamp=start,
                filters=[StockMoneyFlow.entity_id.like('stock_sz%')])
        # 创业板
        elif entity.code == '399006':
            all_df = StockMoneyFlow.query_data(
                provider=self.provider,
                start_timestamp=start,
                filters=[StockMoneyFlow.code.like('300%')])

        if pd_is_not_null(all_df):
            g = all_df.groupby('timestamp')
            for timestamp, df in g:
                se = pd.Series({
                    'id':
                    "{}_{}".format(entity.id, to_time_str(timestamp)),
                    'entity_id':
                    entity.id,
                    'timestamp':
                    timestamp,
                    'code':
                    entity.code,
                    'name':
                    entity.name
                })
                for col in [
                        'net_main_inflows', 'net_huge_inflows',
                        'net_big_inflows', 'net_medium_inflows',
                        'net_small_inflows'
                ]:
                    se[col] = df[col].sum()

                for col in [
                        'net_main_inflow_rate', 'net_huge_inflow_rate',
                        'net_big_inflow_rate', 'net_medium_inflow_rate',
                        'net_small_inflow_rate'
                ]:
                    se[col] = df[col].sum() / len(df)

                index_df = se.to_frame().T

                self.logger.info(index_df)

                df_to_db(df=index_df,
                         data_schema=self.data_schema,
                         provider=self.provider,
                         force_update=self.force_update)

        return None
示例#4
0
def test_stock_money_flow():
    provider = "joinquant"
    # Stock.record_data(provider=provider)
    StockMoneyFlow.record_data(codes=["300999", "688981"],
                               provider=provider,
                               start_timestamp="2020-12-14",
                               compute_index_money_flow=False)

    data_samples = [
        {
            "id": "stock_sz_300999_2020-12-14",
            "timestamp": "2020-12-14",
            "code": "300999",
            "net_main_inflows": 46378.96 * 10000,
            "net_main_inflow_rate": 9.3 / 100,
            "net_huge_inflows": 50111.54 * 10000,
            "net_huge_inflow_rate": 10.04 / 100,
            "net_big_inflows": -3732.58 * 10000,
            "net_big_inflow_rate": -0.75 / 100,
            "net_medium_inflows": -23493.71 * 10000,
            "net_medium_inflow_rate": -4.71 / 100,
            "net_small_inflows": -22885.25 * 10000,
            "net_small_inflow_rate": -4.59 / 100,
        },
        {
            "id": "stock_sh_688981_2020-12-14",
            "timestamp": "2020-12-14",
            "code": "688981",
            "net_main_inflows": -14523.55 * 10000,
            "net_main_inflow_rate": -10.77 / 100,
            "net_huge_inflows": -17053.72 * 10000,
            "net_huge_inflow_rate": -12.65 / 100,
            "net_big_inflows": 2530.17 * 10000,
            "net_big_inflow_rate": 1.88 / 100,
            "net_medium_inflows": 6945.23 * 10000,
            "net_medium_inflow_rate": 5.15 / 100,
            "net_small_inflows": 7578.32 * 10000,
            "net_small_inflow_rate": 5.62 / 100,
        },
    ]
    StockMoneyFlow.test_data_correctness(provider=provider,
                                         data_samples=data_samples)
示例#5
0
def test_stock_money_flow():
    region = Region.CHN
    provider = Provider.JoinQuant

    StockMoneyFlow.record_data(codes=['300999', '688981'],
                               provider=provider,
                               start_timestamp='2020-12-14',
                               compute_index_money_flow=False)

    data_samples = [{
        "id": 'stock_sz_300999_2020-12-14',
        "timestamp": '2020-12-14',
        "code": "300999",
        "net_main_inflows": 46378.96 * 10000,
        "net_main_inflow_rate": 9.3 / 100,
        "net_huge_inflows": 50111.54 * 10000,
        "net_huge_inflow_rate": 10.04 / 100,
        "net_big_inflows": -3732.58 * 10000,
        "net_big_inflow_rate": -0.75 / 100,
        "net_medium_inflows": -23493.71 * 10000,
        "net_medium_inflow_rate": -4.71 / 100,
        "net_small_inflows": -22885.25 * 10000,
        "net_small_inflow_rate": -4.59 / 100
    }, {
        "id": 'stock_sh_688981_2020-12-14',
        "timestamp": '2020-12-14',
        "code": "688981",
        "net_main_inflows": -14523.55 * 10000,
        "net_main_inflow_rate": -10.77 / 100,
        "net_huge_inflows": -17053.72 * 10000,
        "net_huge_inflow_rate": -12.65 / 100,
        "net_big_inflows": 2530.17 * 10000,
        "net_big_inflow_rate": 1.88 / 100,
        "net_medium_inflows": 6945.23 * 10000,
        "net_medium_inflow_rate": 5.15 / 100,
        "net_small_inflows": 7578.32 * 10000,
        "net_small_inflow_rate": 5.62 / 100
    }]
    StockMoneyFlow.test_data_correctness(region=region,
                                         provider=provider,
                                         data_samples=data_samples)
    def record(self, entity, start, end, size, timestamps):
        # 上证
        if entity.code == "000001":
            all_df = StockMoneyFlow.query_data(
                provider=self.provider, start_timestamp=start, filters=[StockMoneyFlow.entity_id.like("stock_sh%")]
            )
        # 深证
        elif entity.code == "399001":
            all_df = StockMoneyFlow.query_data(
                provider=self.provider, start_timestamp=start, filters=[StockMoneyFlow.entity_id.like("stock_sz%")]
            )
        # 创业板
        elif entity.code == "399006":
            all_df = StockMoneyFlow.query_data(
                provider=self.provider, start_timestamp=start, filters=[StockMoneyFlow.code.like("300%")]
            )
        # 科创板
        elif entity.code == "000688":
            all_df = StockMoneyFlow.query_data(
                provider=self.provider, start_timestamp=start, filters=[StockMoneyFlow.code.like("688%")]
            )

        if pd_is_not_null(all_df):
            g = all_df.groupby("timestamp")
            for timestamp, df in g:
                se = pd.Series(
                    {
                        "id": "{}_{}".format(entity.id, to_time_str(timestamp)),
                        "entity_id": entity.id,
                        "timestamp": timestamp,
                        "code": entity.code,
                        "name": entity.name,
                    }
                )
                for col in [
                    "net_main_inflows",
                    "net_huge_inflows",
                    "net_big_inflows",
                    "net_medium_inflows",
                    "net_small_inflows",
                ]:
                    se[col] = df[col].sum()

                for col in [
                    "net_main_inflow_rate",
                    "net_huge_inflow_rate",
                    "net_big_inflow_rate",
                    "net_medium_inflow_rate",
                    "net_small_inflow_rate",
                ]:
                    se[col] = df[col].sum() / len(df)

                index_df = se.to_frame().T

                self.logger.info(index_df)

                df_to_db(
                    df=index_df, data_schema=self.data_schema, provider=self.provider, force_update=self.force_update
                )

        return None