关于测算新股打板容量规模的一些思考

别等时光非礼了梦想. 提交于 2020-02-06 05:51:26

这里所述新股打板策略是指新股上市后两三天一字涨停时在集合竞价买入,然后在开板或者成交量急剧放大后卖出。策略核心是技术+交易所撮合细节。
根据这一思路对2019年新股打板策略容量进行初步测算。2019年市场整体约130亿,但实际受多种因素影响会少很多。

import datetime
import re
from jqdatasdk import *
import numpy as np
import pandas as pd

auth('137XXXXXXXX','XXXXXXXX')
print(__version__)
print(get_query_count())

# 根据给定日期获取所有证券情况
year = list(range(2015,2020))

for j in year:
    all_securities = get_all_securities(types=['stock'], date=str(j) + '-12-31')
    all_securities['code_jk'] = all_securities.index

    # 通过正则表达式从合约代码中提取证券代码为688开头(科创板)
    def get_kechuangban(code:str) -> str:
        return re.findall('^\d+', str(code))[0]

    all_securities['code_num'] = all_securities.apply(lambda row: get_kechuangban(row['code_jk']), axis=1)

    # 筛选code_num列排除以688开头的(科创板)数据
    fun = all_securities['code_num'].apply(lambda x: x.startswith('688'))
    all_securities = all_securities[fun == False]

    # 筛选当年新股
    all_securities_new = all_securities[(all_securities.start_date >= datetime.date(j,1,1)) & (all_securities.start_date <= datetime.date(j,12,31))]

    df0 = pd.DataFrame(data=None,index=[0])
    for i in list(all_securities_new.index):
        start_date = all_securities_new.loc[i,'start_date']
        df = get_price(i, start_date=str(j) + '-01-01', end_date=str(j) + '-12-31', frequency='daily', fields=['open','close','high','low','volume','money','high_limit','low_limit'], skip_paused=False, fq='pre')
        df['date'] = df.index
        df['volume_before_kaiban'] = df.apply(lambda row:row['volume'] if row['low'] == row['high_limit'] and ((row['date'] - start_date) <= datetime.timedelta(days=30)) else 0,axis=1)
        df['money_before_kaiban'] = df.apply(lambda row:row['money'] if row['low'] == row['high_limit'] and ((row['date'] - start_date) <= datetime.timedelta(days=30)) else 0,axis=1)
        df['cum_volume_before_kaiban_%s'%(i)] = df['volume_before_kaiban'].cumsum()
        df['cum_money_before_kaiban_%s'%(i)] = df['money_before_kaiban'].cumsum()
        df = df[['cum_volume_before_kaiban_%s'%(i),'cum_money_before_kaiban_%s'%(i)]]
        df0 = pd.merge(df,df0,left_index=True,right_index=True,how='left')
    df0 = df0.filter(regex=('cum_money_before_kaiban_.*'))
    df0['sum'] = df0.sum(axis=1)
    df0.to_csv(r'D:\data1\data4\etf\cum_money_before_kaiban_%s.csv'%(j),encoding='gbk')
    print('%s done'%(j))
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!