Esempio n. 1
0
def short_line_ma(days=5):
    # 连续n天股价 ma5*1.08>收盘价>=ma5, 最低价>=ma10,ma10*1.05>ma5
    # ma5>ma10>ma20>ma60>ma120
    ds_tushare = DataServiceTushare()
    lst_code_picked = list()
    code_lst = ds_tushare.get_stock_list()
    for item_code in code_lst:
        date_begin = ds_tushare.get_pre_trade_date('202200804', days)
        k_data_lst = ds_tushare.get_stock_price_lst(item_code, date_begin,
                                                    '202200804')
        if len(k_data_lst) == 0:
            continue
        cnt = 0
        for item_price in k_data_lst:
            if item_price['close'] < item_price['ma_5'] or item_price[
                    'close'] > item_price['ma_5'] * 1.08 or item_price[
                        'low'] < item_price['ma_10']:
                break
            if item_price['ma_5'] > item_price['ma_10'] * 1.05:
                break
            if item_price['ma_120'] > item_price['ma_60'] or item_price['ma_60'] > item_price['ma_30'] or item_price['ma_30'] > item_price['ma_20'] \
                or item_price['ma_20'] > item_price['ma_10'] or item_price['ma_10'] > item_price['ma_5']:
                break
            cnt += 1
            if cnt == days:
                print(item_price['ts_code'])
                lst_code_picked.append(item_price['ts_code'])
    print(lst_code_picked)
Esempio n. 2
0
 def pick_stock(self, date_picked):
     ds_tushare = DataServiceTushare()
     lst_code_picked = list()
     for ts_code in ds_tushare.get_stock_list():
         stock_basic = ds_tushare.get_stock_basic_info(ts_code)
         if stock_basic is None:
             self.logger.info('None stock basic info %s' % ts_code)
             continue
         dt_date = string_to_datetime(date_picked)
         d = timedelta(days=-365 * self.n_years)
         if stock_basic['list_date'] > time_to_str(
                 dt_date + d, '%Y%m%d') or 'ST' in stock_basic['name']:
             # 排除上市时间小于2年和st股票
             continue
         dic_stock_price = ds_tushare.get_stock_price_info(
             ts_code, date_picked)
         if dic_stock_price is None:
             # 排除选股日停牌的股票
             continue
         str_ma_long = 'ma_' + str(self.ma_long)
         flag_in_pool = True
         try:
             if dic_stock_price['high_250'] / dic_stock_price['low_250'] < self.max_times_in_year \
                 and dic_stock_price['ma_120'] > dic_stock_price['ma_250'] \
                     and dic_stock_price['ma_250'] > dic_stock_price['ma_500'] and dic_stock_price['close'] < dic_stock_price['high_250'] * (1.0 - self.pct_back)\
                         and dic_stock_price['close'] > dic_stock_price[str_ma_long] * (1.0-self.pct_near) and dic_stock_price['close'] < dic_stock_price[str_ma_long] * (1.0+self.pct_near):
                 date_pre = ds_tushare.get_pre_trade_date(date_picked)
                 price_pre = ds_tushare.get_stock_price_info(
                     ts_code, date_pre)
                 if dic_stock_price['ma_500'] > price_pre[
                         'ma_500'] and dic_stock_price[
                             'ma_250'] > price_pre['ma_250']:
                     cal = ds_tushare.get_pre_n_trade_date(
                         dic_stock_price['trade_date'],
                         self.day_ma_long_effective)
                     k_data_lst = ds_tushare.get_stock_price_lst(
                         dic_stock_price['ts_code'], cal[-1], cal[0])
                     for k_data in k_data_lst:
                         if (k_data['close'] < k_data[str_ma_long]):
                             flag_in_pool = False
                             break
                     if flag_in_pool is True:
                         lst_code_picked.append(dic_stock_price['ts_code'])
         except:
             self.logger.info(
                 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
             self.logger.info(dic_stock_price)
     return lst_code_picked
Esempio n. 3
0
 def pick_stock(self, date_picked):
     ds_tushare = DataServiceTushare()
     lst_code_picked = list()
     for ts_code in ds_tushare.get_stock_list():
         stock_basic = ds_tushare.get_stock_basic_info(ts_code)
         if stock_basic is None:
             self.logger.info('None stock basic info %s' % ts_code)
             continue
         dt_date = string_to_datetime(date_picked)
         d = timedelta(days=-365 * self.n_years)
         if stock_basic['list_date'] > time_to_str(
                 dt_date + d, '%Y%m%d') or 'ST' in stock_basic['name']:
             # 排除上市时间小于2年和st股票
             continue
         dic_stock_price = ds_tushare.get_stock_price_info(
             ts_code, date_picked)
         if dic_stock_price is None:
             # 排除选股日停牌的股票
             continue
         high_gap = 'high_' + str(self.days_gap)
         low_gap = 'low_' + str(self.days_gap)
         days_break_gap = 'high_' + str(self.days_break)
         try:
             if dic_stock_price['high_250'] / dic_stock_price['low_250'] < self.max_times_in_year and \
                 dic_stock_price['ma_60'] > dic_stock_price['ma_120'] and \
                     dic_stock_price['ma_120'] > dic_stock_price['ma_250']:
                 date_pre = ds_tushare.get_pre_trade_date(
                     date_picked, self.days_gap)
                 price_pre = ds_tushare.get_stock_price_info(
                     ts_code, date_pre)
                 if dic_stock_price['ts_code'] == '000998_SZ':
                     a = 1
                 if price_pre['high'] < dic_stock_price[low_gap] and \
                     price_pre['high'] > price_pre[days_break_gap]*(1.0-self.pct_high_break) and \
                         dic_stock_price['low'] < price_pre['high']*(1.0+self.pct_near_gap) and \
                             dic_stock_price[high_gap]/price_pre['high'] < (1.0+self.pct_max):
                     lst_code_picked.append(dic_stock_price['ts_code'])
         except:
             self.logger.info(
                 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
             self.logger.info(dic_stock_price)
     return lst_code_picked
Esempio n. 4
0
import pandas as pd
import numpy as np
df = pd.read_csv(
    'D:\code\quant_big_a\\trade_stock_digu\\dingzengjiejin2020.csv')
from data_service import DataServiceTushare

df1 = df[df['date_free'] < 20200801]
# 计算定增解禁期间股票表现情况
# 计算定增解禁股解禁日前后20个交易日信息
# 解禁日之前的20日作为基准日:计算收盘最大涨幅(跌幅)平均值和中位数
ds_tushare = DataServiceTushare()
lst_up = list()
lst_down = list()
for index, row in df1.iterrows():
    date_end = ds_tushare.get_next_trade_date(str(row["date_free"]), 20)
    date_start = ds_tushare.get_pre_trade_date(str(row["date_free"]), 20)
    lst_close = list()
    code = row["code"].replace('.', '_')
    lst_k_data = ds_tushare.get_stock_price_lst(code, date_start, date_end)
    for item in lst_k_data:
        lst_close.append(item['close'])
    if len(lst_close) == 0:
        continue
    price_base = lst_close[0]
    pct_up = (max(lst_close) - price_base) / price_base
    pct_down = (min(lst_close) - price_base) / price_base
    lst_up.append(pct_up)
    lst_down.append(pct_down)
mean_up = np.mean(lst_up)
mean_down = np.mean(lst_down)
median_up = np.median(lst_up)