Esempio n. 1
0
    def init_selectors(self,
                       entity_ids,
                       entity_schema,
                       exchanges,
                       codes,
                       start_timestamp,
                       end_timestamp,
                       adjust_type=None):
        myselector = TargetSelector(
            entity_ids=entity_ids,
            entity_schema=entity_schema,
            exchanges=exchanges,
            codes=codes,
            start_timestamp=start_timestamp,
            end_timestamp=end_timestamp,
            provider="joinquant",
        )

        myselector.add_factor(
            BullFactor(
                entity_ids=entity_ids,
                entity_schema=entity_schema,
                exchanges=exchanges,
                codes=codes,
                start_timestamp=start_timestamp,
                end_timestamp=end_timestamp,
                adjust_type=adjust_type,
            ))

        self.selectors.append(myselector)
Esempio n. 2
0
    def init_selectors(self,
                       entity_ids,
                       entity_schema,
                       exchanges,
                       codes,
                       start_timestamp,
                       end_timestamp,
                       adjust_type=None):
        myselector = TargetSelector(
            entity_ids=entity_ids,
            entity_schema=entity_schema,
            exchanges=exchanges,
            codes=codes,
            start_timestamp=start_timestamp,
            end_timestamp=end_timestamp,
            provider="joinquant",
        )

        myselector.add_factor(
            CrossMaFactor(
                entity_ids=entity_ids,
                entity_schema=entity_schema,
                exchanges=exchanges,
                codes=codes,
                start_timestamp=start_timestamp,
                end_timestamp=end_timestamp,
                windows=[5, 10],
                need_persist=False,
                adjust_type=adjust_type,
            ))

        self.selectors.append(myselector)
Esempio n. 3
0
def test_cross_ma_selector():
    entity_ids = ["stock_sz_000338"]
    entity_type = "stock"
    start_timestamp = "2018-01-01"
    end_timestamp = "2019-06-30"
    my_selector = TargetSelector(entity_ids=entity_ids,
                                 entity_schema=entity_type,
                                 start_timestamp=start_timestamp,
                                 end_timestamp=end_timestamp)
    # add the factors
    my_selector.add_factor(
        CrossMaFactor(
            entity_ids=entity_ids,
            start_timestamp=start_timestamp,
            end_timestamp=end_timestamp,
            computing_window=10,
            windows=[5, 10],
            need_persist=False,
            level=IntervalLevel.LEVEL_1DAY,
            adjust_type="hfq",
        ))
    my_selector.run()
    print(my_selector.open_long_df)
    print(my_selector.open_short_df)
    assert "stock_sz_000338" in my_selector.get_open_short_targets(
        "2018-01-29")
Esempio n. 4
0
def report_bull():
    while True:
        error_count = 0
        email_action = EmailInformer()

        try:
            latest_day: Stock1dHfqKdata = Stock1dHfqKdata.query_data(order=Stock1dHfqKdata.timestamp.desc(), limit=1,
                                                                     return_type='domain')
            target_date = latest_day[0].timestamp

            # 计算均线
            start = '2019-01-01'
            my_selector = TargetSelector(start_timestamp=start, end_timestamp=target_date)
            # add the factors
            factor1 = BullFactor(start_timestamp=start, end_timestamp=target_date)
            factor2 = CrossMaVolumeFactor(start_timestamp=start, end_timestamp=target_date,
                                          windows=[5, 120, 250])

            my_selector.add_factor(factor1)
            my_selector.add_factor(factor2)

            my_selector.run()

            long_stocks = my_selector.get_open_long_targets(timestamp=target_date)

            msg = 'no targets'

            if long_stocks:
                stocks = get_entities(provider='joinquant', entity_schema=Stock, entity_ids=long_stocks,
                                      return_type='domain')
                # add them to eastmoney
                try:
                    try:
                        eastmoneypy.del_group('bull')
                    except:
                        pass
                    eastmoneypy.create_group('bull')
                    for stock in stocks:
                        eastmoneypy.add_to_group(stock.code, group_name='bull')
                except Exception as e:
                    email_action.send_message(zvt_config['email_username'], f'report_bull error',
                                              'report_bull error:{}'.format(e))

                infos = stocks_with_info(stocks)
                msg = '\n'.join(infos) + '\n'

            logger.info(msg)

            email_action.send_message(zvt_config['email_username'], f'{target_date} bull选股结果', msg)

            break
        except Exception as e:
            logger.exception('report_bull error:{}'.format(e))
            time.sleep(60 * 3)
            error_count = error_count + 1
            if error_count == 10:
                email_action.send_message(zvt_config['email_username'], f'report_bull error',
                                          'report_bull error:{}'.format(e))
Esempio n. 5
0
def report_vol_up():
    while True:
        error_count = 0
        email_action = EmailInformer()

        try:
            # 抓取k线数据
            # StockTradeDay.record_data(provider='joinquant')
            # Stock1dKdata.record_data(provider='joinquant')

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

            start_timestamp = next_date(target_date, -50)
            # 成交量
            vol_df = get_top_volume_entities(entity_type='stock',
                                             start_timestamp=start_timestamp,
                                             end_timestamp=target_date,
                                             pct=0.4)
            current_entity_pool = vol_df.index.tolist()

            # 计算均线
            start = '2019-01-01'
            my_selector = TargetSelector(start_timestamp=start,
                                         end_timestamp=target_date,
                                         select_mode=SelectMode.condition_or)
            # add the factors
            factor1 = VolumeUpMaFactor(entity_ids=current_entity_pool,
                                       start_timestamp=start,
                                       end_timestamp=target_date,
                                       windows=[120, 250],
                                       over_mode='or')

            my_selector.add_factor(factor1)

            my_selector.run()

            long_stocks = my_selector.get_open_long_targets(
                timestamp=target_date)

            msg = 'no targets'

            if long_stocks:
                stocks = get_entities(provider='joinquant',
                                      entity_schema=Stock,
                                      entity_ids=long_stocks,
                                      return_type='domain')
                # add them to eastmoney
                try:
                    try:
                        eastmoneypy.del_group('tech')
                    except:
                        pass
                    eastmoneypy.create_group('tech')
                    for stock in stocks:
                        eastmoneypy.add_to_group(stock.code, group_name='tech')
                except Exception as e:
                    email_action.send_message(
                        zvt_config['email_username'], f'report_vol_up error',
                        'report_vol_up error:{}'.format(e))

                infos = stocks_with_info(stocks)
                msg = '\n'.join(infos) + '\n'

            logger.info(msg)

            email_action.send_message(zvt_config['email_username'],
                                      f'{target_date} 改进版放量突破(半)年线选股结果', msg)

            break
        except Exception as e:
            logger.exception('report_vol_up error:{}'.format(e))
            time.sleep(60 * 3)
            error_count = error_count + 1
            if error_count == 10:
                email_action.send_message(zvt_config['email_username'],
                                          f'report_vol_up error',
                                          'report_vol_up error:{}'.format(e))