Ejemplo n.º 1
0
    def init_selectors(self,
                       entity_ids,
                       entity_schema,
                       exchanges,
                       codes,
                       start_timestamp,
                       end_timestamp,
                       adjust_type=None):
        ma_vol_selector = TargetSelector(region=self.region,
                                         entity_ids=entity_ids,
                                         entity_schema=entity_schema,
                                         exchanges=exchanges,
                                         codes=codes,
                                         start_timestamp=start_timestamp,
                                         end_timestamp=end_timestamp,
                                         provider=Provider.JoinQuant,
                                         level=IntervalLevel.LEVEL_1DAY)
        # 放量突破年线
        ma_vol_factor = VolumeUpMaFactor(region=self.region,
                                         entity_ids=entity_ids,
                                         entity_schema=entity_schema,
                                         exchanges=exchanges,
                                         codes=codes,
                                         start_timestamp=start_timestamp -
                                         datetime.timedelta(365),
                                         end_timestamp=end_timestamp,
                                         provider=Provider.JoinQuant,
                                         level=IntervalLevel.LEVEL_1DAY)
        ma_vol_selector.add_filter_factor(ma_vol_factor)

        self.selectors.append(ma_vol_selector)
Ejemplo n.º 2
0
    def init_selectors(self,
                       entity_ids,
                       entity_schema,
                       exchanges,
                       codes,
                       start_timestamp,
                       end_timestamp,
                       adjust_type=None):
        ma_vol_selector = TargetSelector(entity_ids=entity_ids,
                                         entity_schema=entity_schema,
                                         exchanges=exchanges,
                                         codes=codes,
                                         start_timestamp=start_timestamp,
                                         end_timestamp=end_timestamp,
                                         provider='joinquant',
                                         level=IntervalLevel.LEVEL_1DAY)
        # 放量突破年线
        ma_vol_factor = VolumeUpMaFactor(entity_ids=entity_ids,
                                         entity_schema=entity_schema,
                                         exchanges=exchanges,
                                         codes=codes,
                                         start_timestamp=start_timestamp -
                                         datetime.timedelta(365),
                                         end_timestamp=end_timestamp,
                                         provider='joinquant',
                                         level=IntervalLevel.LEVEL_1DAY)
        # 底部附近突破
        cross_factor = CrossTopBottomFactor(entity_ids=entity_ids,
                                            entity_schema=entity_schema,
                                            exchanges=exchanges,
                                            codes=codes,
                                            start_timestamp=start_timestamp -
                                            datetime.timedelta(365),
                                            end_timestamp=end_timestamp,
                                            provider='joinquant',
                                            level=IntervalLevel.LEVEL_1DAY)
        ma_vol_selector.add_filter_factor(ma_vol_factor)
        ma_vol_selector.add_filter_factor(cross_factor)

        self.selectors.append(ma_vol_selector)
Ejemplo n.º 3
0
def report_vol_up_250():
    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

            # 计算均线
            my_selector = TargetSelector(start_timestamp='2018-10-01',
                                         end_timestamp=target_date)
            # add the factors
            factor1 = VolumeUpMaFactor(start_timestamp='2018-10-01',
                                       end_timestamp=target_date)

            my_selector.add_filter_factor(factor1)

            my_selector.run()

            long_stocks = my_selector.get_open_long_targets(
                timestamp=target_date)

            msg = 'no targets'

            # 过滤亏损股
            # check StockValuation data
            pe_date = target_date - datetime.timedelta(10)
            if StockValuation.query_data(start_timestamp=pe_date,
                                         limit=1,
                                         return_type='domain'):
                positive_df = StockValuation.query_data(
                    provider='joinquant',
                    entity_ids=long_stocks,
                    start_timestamp=pe_date,
                    filters=[StockValuation.pe > 0],
                    columns=['entity_id'])
                bad_stocks = set(long_stocks) - set(
                    positive_df['entity_id'].tolist())
                if bad_stocks:
                    stocks = get_entities(provider='joinquant',
                                          entity_schema=Stock,
                                          entity_ids=bad_stocks,
                                          return_type='domain')
                    info = [f'{stock.name}({stock.code})' for stock in stocks]
                    msg = '亏损股:' + ' '.join(info) + '\n'

                long_stocks = set(positive_df['entity_id'].tolist())

            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(
                        "*****@*****.**", f'report_vol_up_250 error',
                        'report_vol_up_250 error:{}'.format(e))

                info = [f'{stock.name}({stock.code})' for stock in stocks]
                msg = msg + '盈利股:' + ' '.join(info) + '\n'

            logger.info(msg)

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

            break
        except Exception as e:
            logger.exception('report_vol_up_250 error:{}'.format(e))
            time.sleep(60 * 3)
            error_count = error_count + 1
            if error_count == 10:
                email_action.send_message(
                    "*****@*****.**", f'report_vol_up_250 error',
                    'report_vol_up_250 error:{}'.format(e))
Ejemplo n.º 4
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))