国庆期间,A股休市,港股正常交易,而同时在两地上市的公司目前有一百多家,于是有了跨市场套利的思路。
港股交易时间
09:30 - 12:00
13:00 - 16:00
A股交易时间
09:30 - 11:30
13:00 - 15:00
即上午多出半个小时,下午多出一个小时。那么是否可以利用港股15:00 - 16:00的表现来推断下一天A股的表现?
上图是郑煤机的30分钟线,红色是港股行情,黄色是A股行情。在9/11, 15:00 - 16:00这段时间内,港股上涨了约2.58%,一天后,A股开始反应,随即上涨。
在复盘过程中,我发现也有很多失效的情况发生,于是在以下的研究中,我也考虑了过去半年和一年的AH相关性分析,以作参考。
由于平台目前没有港股分钟行情,我写了一个简单的爬虫从新浪财经获取,但新浪通过json格式返回的分钟数据最多只有5天,所以还在考虑如何获取历史港股分钟行情。
欢迎讨论!
共勉!
import pandas as pd
from tqdm import tqdm_notebook
from bs4 import BeautifulSoup
import requests
import json
from jqdata import finance, macro
# get hk stock minute data from sina finance
def get_ret(code):
url = 'https://quotes.sina.cn/hk/api/openapi.php/HK_MinlineService.getMinline?symbol={}&day=1'.format(code)
html = requests.get(url).text
data = json.loads(html)['result']['data'][0]
if len(data) == 0:
return None
df = pd.DataFrame(data)
df.index = df['m']
start_time = '15:00:00'
end_time = df.index[-1]
if start_time not in df.index:
return None
df['price'] = df['price'].apply(lambda x: float(x))
ret = (df.loc[end_time, 'price'] / df.loc[start_time, 'price'] - 1).round(4)
return {
'ret': ret,
'start_time': start_time,
'end_time': end_time
}
def get_ah_corr(code, date, N):
# AH price
table_name = finance.STK_AH_PRICE_COMP
q = query(
table_name.day, table_name.a_price, table_name.h_price
).filter(
table_name.h_code==code, table_name.day<=date
).order_by(table_name.day.desc()).limit(N)
ah_df = finance.run_query(q)
start = ah_df['day'].tolist()[-1]
end = ah_df['day'].tolist()[0]
# forex
table_name = macro.MAC_RMB_EXCHANGE_RATE
q = query(
table_name.day, table_name.bank_reduced_prc
).filter(
table_name.currency_name=='港币', table_name.day>=start, table_name.day<=end
).order_by(table_name.day.desc())
forex_df = macro.run_query(q)
# calc corr
ah_df['day'] = ah_df['day'].apply(lambda x: str(x))
ah_df = pd.merge(ah_df, forex_df, on='day')
ah_df['h_price_rmb'] = ah_df['h_price'] * ah_df['bank_reduced_prc'] / 100
corr = round(ah_df[['a_price', 'h_price_rmb']].corr().values[0, 1], 4)
return corr
date = '2019-9-30'
table_name = finance.STK_AH_PRICE_COMP
q = query(table_name.h_code, table_name.a_code, table_name.name).filter(table_name.day==date)
code_info = finance.run_query(q).to_dict('records')
ret_list = []
for code_dict in tqdm_notebook(code_info):
code = code_dict['h_code']
ret_dict = get_ret(code)
if ret_dict is None:
continue
corr_6mon = get_ah_corr(code, date, 120)
corr_1y = get_ah_corr(code, date, 250)
ret_list.append({
'code': code,
'a_code': code_dict['a_code'],
'name': code_dict['name'],
'ret': ret_dict['ret'],
'start_time': ret_dict['start_time'],
'end_time': ret_dict['end_time'],
'corr_6mon': corr_6mon,
'corr_1y': corr_1y
})
result_df = pd.DataFrame(ret_list).sort_values(by='ret', ascending=False)
result_df
a_code | code | corr_1y | corr_6mon | end_time | name | ret | start_time | |
---|---|---|---|---|---|---|---|---|
109 | 601717.XSHG | 00564 | 0.7135 | 0.7407 | 15:59:00 | 郑煤机 | 0.0323 | 15:00:00 |
49 | 002460.XSHE | 01772 | 0.6224 | 0.8427 | 15:58:00 | 赣锋锂业 | 0.0278 | 15:00:00 |
20 | 600871.XSHG | 01033 | 0.7684 | 0.9221 | 15:59:00 | 石化油服 | 0.0253 | 15:00:00 |
21 | 600775.XSHG | 00553 | 0.6482 | 0.6073 | 15:59:00 | 南京熊猫 | 0.0200 | 15:00:00 |
94 | 600548.XSHG | 00548 | 0.8487 | 0.4284 | 15:59:00 | 深高速 | 0.0138 | 15:00:00 |
19 | 601038.XSHG | 00038 | -0.2251 | 0.1926 | 15:59:00 | 一拖股份 | 0.0129 | 15:00:00 |
111 | 600026.XSHG | 01138 | 0.6627 | 0.5468 | 15:59:00 | 中远海能 | 0.0122 | 15:00:00 |
91 | 600196.XSHG | 02196 | 0.8936 | 0.8801 | 15:59:00 | 复星医药 | 0.0120 | 15:00:00 |
30 | 603157.XSHG | 06116 | 0.8606 | 0.9427 | 15:23:00 | 拉夏贝尔 | 0.0120 | 15:00:00 |
58 | 601633.XSHG | 02333 | 0.8639 | 0.8850 | 15:59:00 | 长城汽车 | 0.0118 | 15:00:00 |
107 | 600874.XSHG | 01065 | 0.7866 | 0.7589 | 15:53:00 | 创业环保 | 0.0115 | 15:00:00 |
37 | 688009.XSHG | 03969 | 0.2672 | 0.2672 | 15:59:00 | 中国通号 | 0.0110 | 15:00:00 |
72 | 002202.XSHE | 02208 | 0.9181 | 0.9289 | 15:59:00 | 金风科技 | 0.0106 | 15:00:00 |
46 | 601088.XSHG | 01088 | 0.5831 | 0.6948 | 15:59:00 | 中国神华 | 0.0102 | 15:00:00 |
12 | 601857.XSHG | 00857 | 0.9455 | 0.9131 | 15:59:00 | 中国石油 | 0.0102 | 15:00:00 |
103 | 600685.XSHG | 00317 | 0.8465 | 0.7081 | 15:59:00 | 中船防务 | 0.0086 | 15:00:00 |
4 | 601598.XSHG | 00598 | 0.6606 | 0.9438 | 15:59:00 | 中国外运 | 0.0085 | 15:00:00 |
62 | 601600.XSHG | 02600 | 0.6826 | 0.9137 | 15:59:00 | 中国铝业 | 0.0083 | 15:00:00 |
93 | 601238.XSHG | 02238 | 0.6423 | 0.8341 | 15:59:00 | 广汽集团 | 0.0080 | 15:00:00 |
29 | 601328.XSHG | 03328 | 0.9176 | 0.9578 | 15:59:00 | 交通银行 | 0.0079 | 15:00:00 |
106 | 603993.XSHG | 03993 | 0.7844 | 0.8666 | 15:59:00 | 洛阳钼业 | 0.0079 | 15:00:00 |
69 | 600600.XSHG | 00168 | 0.9296 | 0.6944 | 15:59:00 | 青岛啤酒 | 0.0074 | 15:00:00 |
32 | 601881.XSHG | 06881 | 0.7638 | 0.7468 | 15:59:00 | 中国银河 | 0.0074 | 15:00:00 |
78 | 000513.XSHE | 01513 | 0.8888 | 0.9778 | 15:59:00 | 丽珠集团 | 0.0073 | 15:00:00 |
79 | 601601.XSHG | 02601 | 0.9426 | 0.9209 | 15:59:00 | 中国太保 | 0.0071 | 15:00:00 |
65 | 600999.XSHG | 06099 | 0.3081 | 0.6876 | 15:59:00 | 招商证券 | 0.0069 | 15:00:00 |
34 | 601688.XSHG | 06886 | 0.7201 | 0.7191 | 15:59:00 | 华泰证券 | 0.0069 | 15:00:00 |
53 | 002594.XSHE | 01211 | 0.4864 | 0.8021 | 15:59:00 | 比亚迪 | 0.0066 | 15:00:00 |
80 | 600585.XSHG | 00914 | 0.9544 | 0.9101 | 15:59:00 | 海螺水泥 | 0.0065 | 15:00:00 |
45 | 601336.XSHG | 01336 | 0.8541 | 0.9346 | 15:59:00 | 新华保险 | 0.0065 | 15:00:00 |
... | ... | ... | ... | ... | ... | ... | ... | ... |
6 | 600635.XSHG | 01635 | 0.7436 | 0.9297 | 16:00:00 | 大众公用 | 0.0000 | 15:00:00 |
51 | 601618.XSHG | 01618 | 0.8285 | 0.8715 | 15:59:00 | 中国中冶 | 0.0000 | 15:00:00 |
104 | 601788.XSHG | 06178 | 0.4161 | 0.8721 | 15:59:00 | 光大证券 | 0.0000 | 15:00:00 |
55 | 002910.XSHE | 01533 | 0.2788 | 0.0380 | 16:00:00 | 庄园牧场 | 0.0000 | 15:00:00 |
57 | 601068.XSHG | 02068 | 0.6439 | 0.2381 | 16:00:00 | 中铝国际 | 0.0000 | 15:00:00 |
61 | 003816.XSHE | 01816 | 0.4450 | 0.4450 | 15:59:00 | 中国广核 | 0.0000 | 15:00:00 |
63 | 000585.XSHE | 00042 | 0.7499 | 0.7111 | 15:58:00 | ST东电 | 0.0000 | 15:00:00 |
66 | 002948.XSHE | 03866 | -0.0362 | 0.0437 | 16:00:00 | 青岛银行 | 0.0000 | 15:00:00 |
44 | 601186.XSHG | 01186 | 0.6855 | 0.4075 | 15:59:00 | 中国铁建 | -0.0011 | 15:00:00 |
102 | 002672.XSHE | 00895 | 0.8261 | 0.9511 | 15:59:00 | 东江环保 | -0.0014 | 15:00:00 |
68 | 601390.XSHG | 00390 | 0.8758 | 0.8313 | 15:59:00 | 中国中铁 | -0.0021 | 15:00:00 |
18 | 600028.XSHG | 00386 | 0.9255 | 0.9366 | 15:59:00 | 中国石化 | -0.0022 | 15:00:00 |
3 | 600547.XSHG | 01787 | 0.1463 | 0.1045 | 15:59:00 | 山东黄金 | -0.0025 | 15:00:00 |
9 | 601898.XSHG | 01898 | 0.8209 | 0.9093 | 15:59:00 | 中煤能源 | -0.0032 | 15:00:00 |
71 | 000488.XSHE | 01812 | 0.8750 | 0.9692 | 15:58:00 | 晨鸣纸业 | -0.0033 | 15:00:00 |
97 | 601298.XSHG | 06198 | 0.5342 | 0.4058 | 15:59:00 | 青岛港 | -0.0043 | 15:00:00 |
10 | 600688.XSHG | 00338 | 0.9250 | 0.9449 | 15:59:00 | 上海石化 | -0.0044 | 15:00:00 |
85 | 601107.XSHG | 00107 | 0.5821 | 0.8444 | 15:58:00 | 四川成渝 | -0.0044 | 15:00:00 |
41 | 601828.XSHG | 01528 | 0.6982 | 0.8689 | 15:59:00 | 美凯龙 | -0.0047 | 15:00:00 |
16 | 600875.XSHG | 01072 | 0.7646 | 0.9350 | 15:59:00 | 东方电气 | -0.0047 | 15:00:00 |
101 | 000157.XSHE | 01157 | 0.9895 | 0.9018 | 15:59:00 | 中联重科 | -0.0053 | 15:00:00 |
99 | 601375.XSHG | 01375 | 0.6372 | 0.8573 | 15:58:00 | 中原证券 | -0.0066 | 15:00:00 |
0 | 000898.XSHE | 00347 | 0.9126 | 0.8591 | 15:59:00 | 鞍钢股份 | -0.0072 | 15:00:00 |
110 | 601588.XSHG | 00588 | 0.9258 | 0.8371 | 15:59:00 | 北辰实业 | -0.0085 | 15:00:00 |
54 | 002490.XSHE | 00568 | 0.8619 | 0.9292 | 15:56:00 | 山东墨龙 | -0.0096 | 15:00:00 |
1 | 000039.XSHE | 02039 | 0.8918 | 0.8851 | 15:59:00 | 中集集团 | -0.0118 | 15:00:00 |
108 | 000756.XSHE | 00719 | 0.4950 | 0.9154 | 15:58:00 | 新华制药 | -0.0148 | 15:00:00 |
7 | 601330.XSHG | 01330 | -0.3826 | -0.0109 | 15:58:00 | 绿色动力 | -0.0157 | 15:00:00 |
17 | 601326.XSHG | 03369 | 0.3930 | 0.9071 | 15:56:00 | 秦港股份 | -0.0207 | 15:00:00 |
56 | 601005.XSHG | 01053 | 0.8151 | 0.9286 | 15:59:00 | 重庆钢铁 | -0.0312 | 15:00:00 |
112 rows × 8 columns
本社区仅针对特定人员开放
查看需注册登录并通过风险意识测评
5秒后跳转登录页面...
移动端课程