コード例 #1
0
def report_core_company():
    while True:
        error_count = 0
        email_action = EmailInformer()

        try:
            StockTradeDay.record_data(provider='joinquant')
            Stock.record_data(provider='joinquant')
            FinanceFactor.record_data(provider='eastmoney')
            BalanceSheet.record_data(provider='eastmoney')

            latest_day: StockTradeDay = StockTradeDay.query_data(
                order=StockTradeDay.timestamp.desc(),
                limit=1,
                return_type='domain')
            if latest_day:
                target_date = latest_day[0].timestamp
            else:
                target_date = now_pd_timestamp()

            my_selector: TargetSelector = FundamentalSelector(
                start_timestamp='2015-01-01', end_timestamp=target_date)
            my_selector.run()

            long_targets = my_selector.get_open_long_targets(
                timestamp=target_date)
            if long_targets:
                stocks = get_entities(provider='joinquant',
                                      entity_schema=Stock,
                                      entity_ids=long_targets,
                                      return_type='domain')
                info = [f'{stock.name}({stock.code})' for stock in stocks]
                msg = ' '.join(info)
            else:
                msg = 'no targets'

            logger.info(msg)

            email_action.send_message([
                '*****@*****.**', '*****@*****.**',
                '*****@*****.**', '*****@*****.**',
                '*****@*****.**'
            ], f'{to_time_str(target_date)} 核心资产选股结果', msg)

            break
        except Exception as e:
            logger.exception('report_core_company error:{}'.format(e))
            time.sleep(60 * 3)
            error_count = error_count + 1
            if error_count == 10:
                email_action.send_message(
                    "*****@*****.**", f'report_core_company error',
                    'report_core_company error:{}'.format(e))
コード例 #2
0
def test_add_tushare_provider():
    from zvt.contract.register import register_schema
    from zvt.domain.meta.stock_meta import StockMetaBase

    register_schema(providers=['tushare'],
                    db_name='stock_meta',
                    schema_base=StockMetaBase)

    from zvt.domain import Stock
    Stock.query_data(provider='tushare')
    try:
        Stock.record_data(provider='tushare')
        assert False
    except Exception as e:
        print(e)
コード例 #3
0
ファイル: test_reader.py プロジェクト: zvtvz/zvt
def test_china_stock_reader():
    data_reader = DataReader(
        codes=["002572", "000338"],
        data_schema=Stock1dKdata,
        entity_schema=Stock,
        start_timestamp="2019-01-01",
        end_timestamp="2019-06-10",
        entity_provider="eastmoney",
    )

    categories = data_reader.data_df.index.levels[0].to_list()

    df = data_reader.data_df

    assert "stock_sz_002572" in categories
    assert "stock_sz_000338" in categories

    assert ("stock_sz_002572", "2019-01-02") in df.index
    assert ("stock_sz_000338", "2019-01-02") in df.index
    assert ("stock_sz_002572", "2019-06-10") in df.index
    assert ("stock_sz_000338", "2019-06-10") in df.index

    for timestamp in Stock.get_interval_timestamps(
            start_date="2019-06-11",
            end_date="2019-06-14",
            level=IntervalLevel.LEVEL_1DAY):
        data_reader.move_on(to_timestamp=timestamp)

        df = data_reader.data_df

        assert ("stock_sz_002572", timestamp) in df.index
        assert ("stock_sz_000338", to_time_str(timestamp)) in df.index
コード例 #4
0
def test_china_stock_reader():
    data_reader = DataReader(codes=['002572', '000338'],
                             data_schema=Stock1dKdata,
                             entity_schema=Stock,
                             start_timestamp='2019-01-01',
                             end_timestamp='2019-06-10',
                             entity_provider='eastmoney')

    categories = data_reader.data_df.index.levels[0].to_list()

    df = data_reader.data_df

    assert 'stock_sz_002572' in categories
    assert 'stock_sz_000338' in categories

    assert ('stock_sz_002572', '2019-01-02') in df.index
    assert ('stock_sz_000338', '2019-01-02') in df.index
    assert ('stock_sz_002572', '2019-06-10') in df.index
    assert ('stock_sz_000338', '2019-06-10') in df.index

    for timestamp in Stock.get_interval_timestamps(
            start_date='2019-06-11',
            end_date='2019-06-14',
            level=IntervalLevel.LEVEL_1DAY):
        data_reader.move_on(to_timestamp=timestamp)

        df = data_reader.data_df

        assert ('stock_sz_002572', timestamp) in df.index
        assert ('stock_sz_000338', to_time_str(timestamp)) in df.index
コード例 #5
0
ファイル: joinquant_kdata_runner.py プロジェクト: zonwer/zvt
def record_stock():
    while True:
        email_action = EmailInformer()

        try:
            Stock.record_data(provider='joinquant', sleeping_time=1)
            StockTradeDay.record_data(provider='joinquant', sleeping_time=1)
            email_action.send_message("*****@*****.**",
                                      'joinquant record stock finished', '')
            break
        except Exception as e:
            msg = f'joinquant record stock:{e}'
            logger.exception(msg)

            email_action.send_message("*****@*****.**",
                                      'joinquant record stock error', msg)
            time.sleep(60 * 5)
コード例 #6
0
    def tag(self, timestamp):
        stock_df = Stock.query_data(filters=[Stock.list_date <= timestamp],
                                    index="entity_id")
        block_df = Block.query_data(provider="eastmoney",
                                    filters=[Block.category == "industry"],
                                    index="entity_id")
        block_ids = block_df.index.tolist()
        block_stock_df = BlockStock.query_data(
            provider="eastmoney",
            entity_ids=block_ids,
            filters=[BlockStock.stock_id.in_(stock_df.index.tolist())],
            index="stock_id",
        )
        block_stock_df["cycle_tag"] = block_stock_df["name"].apply(
            lambda name: get_cycle_tag(name))
        strong_cycle_stocks = block_stock_df[block_stock_df.cycle_tag ==
                                             "strong_cycle"]["stock_id"]
        weak_cycle_stocks = block_stock_df[block_stock_df.cycle_tag ==
                                           "weak_cycle"]["stock_id"]
        non_cycle_stocks = block_stock_df[block_stock_df.cycle_tag ==
                                          "non_cycle"]["stock_id"]

        strong_cycle_domains = self.get_tag_domains(
            entity_ids=strong_cycle_stocks,
            timestamp=timestamp,
            cycle_tag=CycleTag.strong_cycle.value)
        weak_cycle_domains = self.get_tag_domains(
            entity_ids=weak_cycle_stocks,
            timestamp=timestamp,
            cycle_tag=CycleTag.weak_cycle.value)
        non_cycle_domains = self.get_tag_domains(
            entity_ids=non_cycle_stocks,
            timestamp=timestamp,
            cycle_tag=CycleTag.non_cycle.value)

        self.session.add_all(strong_cycle_domains)
        self.session.add_all(weak_cycle_domains)
        self.session.add_all(non_cycle_domains)
        self.session.commit()
コード例 #7
0
    def tag(self, timestamp):
        stock_df = Stock.query_data(filters=[Stock.list_date <= timestamp],
                                    index='entity_id')
        block_df = Block.query_data(provider='eastmoney',
                                    filters=[Block.category == 'industry'],
                                    index='entity_id')
        block_ids = block_df.index.tolist()
        block_stock_df = BlockStock.query_data(
            provider='eastmoney',
            entity_ids=block_ids,
            filters=[BlockStock.stock_id.in_(stock_df.index.tolist())],
            index='stock_id')
        block_stock_df['cycle_tag'] = block_stock_df['name'].apply(
            lambda name: get_cycle_tag(name))
        strong_cycle_stocks = block_stock_df[block_stock_df.cycle_tag ==
                                             'strong_cycle']['stock_id']
        weak_cycle_stocks = block_stock_df[block_stock_df.cycle_tag ==
                                           'weak_cycle']['stock_id']
        non_cycle_stocks = block_stock_df[block_stock_df.cycle_tag ==
                                          'non_cycle']['stock_id']

        strong_cycle_domains = self.get_tag_domains(
            entity_ids=strong_cycle_stocks,
            timestamp=timestamp,
            cycle_tag=CycleTag.strong_cycle.value)
        weak_cycle_domains = self.get_tag_domains(
            entity_ids=weak_cycle_stocks,
            timestamp=timestamp,
            cycle_tag=CycleTag.weak_cycle.value)
        non_cycle_domains = self.get_tag_domains(
            entity_ids=non_cycle_stocks,
            timestamp=timestamp,
            cycle_tag=CycleTag.non_cycle.value)

        self.session.add_all(strong_cycle_domains)
        self.session.add_all(weak_cycle_domains)
        self.session.add_all(non_cycle_domains)
        self.session.commit()
コード例 #8
0
    def make_decision(self, timestamp, trading_level: IntervalLevel):
        longs, shorts = super().make_decision(timestamp, trading_level)
        if longs or shorts:
            # 成交超过1亿的前300个股
            df = Stock1dKdata.query_data(
                start_timestamp=timestamp,
                end_timestamp=timestamp,
                columns=[Stock1dKdata.entity_id],
                filters=[Stock1dKdata.turnover > 100000000],
                limit=300,
                order=Stock1dKdata.volume.desc())
            longs1 = set(df['entity_id'].to_list())
            long_targets = set(longs) & longs1

            if shorts:
                all = Stock.query_data(columns=[Stock.entity_id])
                short_targets = set(shorts) | (
                    set(all['entity_id'].to_list()) - longs1)
            else:
                short_targets = shorts

            return long_targets, short_targets
        return longs, shorts
コード例 #9
0
ファイル: run.py プロジェクト: huanjka119/FinanceCenter
 def get_stock_list_data(provider: Provider):
     # 股票列表
     Stock.record_data(provider=provider, sleeping_time=0)