昨天发了一篇资金流模型的研究,觉得其中还有很多地方不足,需要对历史数据做些分析来加强自己的判断基础。这个过程中会附带产生一些策略的想法。
探索是个比较长期的过程,之后会继续找些感兴趣的角度来研究。
对于资金流,各位还有其他的剖析角度也请留言。
资金流反映了股票的供求关系。传统的量价无法区分市场微观结构的流动性和私有信息对股票的影响,而根据委托的情况测算的资金流,可以体现出微观市场交易者的真实意图和对股价造成的影响。
股票价格在一段时间中:
(1)资金流入:股价上升状态所产生的成交额,代表推动价格上涨的动力
(2)资金流出:股价下跌过程中产生的成交额,代表推动价格下跌的力量
当天的资金流入与流出的差额,是当天买卖双方力量抵消之后,推动价格变化的净作用量,被定义为当天的资金净流量(MF)。
每一个买单都对应有一个买单,真实的资金流入无法准确的计算。我们只能选择通过高频数据,将每笔交易按推动股价上涨和下跌的差异分类,判断为资金的流入或流出,最终汇总成一天的资金流净额。
测算的方法主要在于时间频率的选择上以及参考的价格。
本篇研究将使用分钟频率的数据按照上述方法进行测算。
我们拿几只股票简单的验证一下。
统计5只股票三年内日度资金流入且上涨、流入且下跌、流出且上涨、流出且下跌的次数。
002697 红旗连锁, 600783 鲁信创投, 000413 东旭光电, 601588 北辰实业
stock = ['002697.XSHE','600783.XSHG','000413.XSHE','601588.XSHG']start_date = '2013-01-01'end_date = '2015-12-31'df = get_price(stock, start_date, end_date, 'daily',['close'])data = df['close']returns = data/data.shift(1)-1returns.head()
002697.XSHE | 600783.XSHG | 000413.XSHE | 601588.XSHG | |
---|---|---|---|---|
2013-01-04 | NaN | NaN | NaN | NaN |
2013-01-07 | 0.054054 | 0.021678 | 0.024938 | -0.003460 |
2013-01-08 | -0.007326 | 0.071033 | -0.002433 | -0.013889 |
2013-01-09 | -0.033210 | -0.029285 | -0.017073 | 0.003521 |
2013-01-10 | 0.003817 | 0.013310 | 0.007444 | 0.014035 |
import pandas as pdyear = ['2013','2014','2015']month = ['01','02','03','04','05','06','07','08','09','10','11','12']result = {}mf = pd.DataFrame()for i in range(3*12):print 'enter loops'startdate = year[i/12] + '-' + month[i%12] + '-01'try:enddate = year[(i+1)/12] + '-' + month[(i+1)%12] + '-01'except IndexError:enddate = '2016-01-01'print 'startdate %s'%startdatefor st in stock:try:df = get_price(st,startdate, enddate,frequency='1m', fields=['close','volume','money'])except:df = get_price(st,startdate, enddate,frequency='1m', fields=['close','volume','money'])df_delay1 = df['close'].shift(1)df["MF"] = df['volume']*df['close']*abs(df['close']-df_delay1)/(df['close']-df_delay1)datelist = get_price(st,startdate, enddate,frequency='1d', fields=['close']).indexfor i in range(len(datelist)):mf.ix[datelist[i],st] = df['MF'].iloc[240*i:240*i+240].sum()/10000mf
enter loops startdate 2013-01-01 enter loops startdate 2013-02-01 enter loops startdate 2013-03-01 enter loops startdate 2013-04-01 enter loops startdate 2013-05-01 enter loops startdate 2013-06-01 enter loops startdate 2013-07-01 enter loops startdate 2013-08-01 enter loops startdate 2013-09-01 enter loops startdate 2013-10-01 enter loops startdate 2013-11-01 enter loops startdate 2013-12-01 enter loops startdate 2014-01-01 enter loops startdate 2014-02-01 enter loops startdate 2014-03-01 enter loops startdate 2014-04-01 enter loops startdate 2014-05-01 enter loops startdate 2014-06-01 enter loops startdate 2014-07-01 enter loops startdate 2014-08-01 enter loops startdate 2014-09-01 enter loops startdate 2014-10-01 enter loops startdate 2014-11-01 enter loops startdate 2014-12-01 enter loops startdate 2015-01-01 enter loops startdate 2015-02-01 enter loops startdate 2015-03-01 enter loops startdate 2015-04-01 enter loops startdate 2015-05-01 enter loops startdate 2015-06-01 enter loops startdate 2015-07-01 enter loops startdate 2015-08-01 enter loops startdate 2015-09-01 enter loops startdate 2015-10-01 enter loops startdate 2015-11-01 enter loops startdate 2015-12-01
002697.XSHE | 600783.XSHG | 000413.XSHE | 601588.XSHG | |
---|---|---|---|---|
2013-01-04 | -632.015065 | -853.500162 | -52.518953 | -82.400005 |
2013-01-07 | 2777.010564 | 323.959516 | 384.781446 | -129.990143 |
2013-01-08 | -774.479778 | 1778.745617 | -36.237028 | -1497.927957 |
2013-01-09 | -1297.430313 | -1063.784692 | -755.496401 | 60.005794 |
2013-01-10 | -115.957243 | -408.996284 | 821.936128 | 256.398971 |
2013-01-11 | 19.946978 | -276.199297 | -289.954483 | -534.014179 |
2013-01-14 | 3149.004701 | 1989.192942 | 382.522086 | 633.239465 |
2013-01-15 | -624.438327 | -416.530685 | 567.549185 | -140.769076 |
2013-01-16 | -1301.171309 | -3282.802560 | 480.037442 | -835.550557 |
2013-01-17 | -1253.026329 | -1941.776679 | 179.116813 | -148.990225 |
2013-01-18 | -41.380740 | 415.980415 | -334.765599 | 656.559204 |
2013-01-21 | 415.767143 | -814.956422 | 20.181959 | -82.334610 |
2013-01-22 | -847.820498 | -1217.228048 | -318.102868 | -911.571609 |
2013-01-23 | -742.446714 | -80.019624 | -402.194852 | -85.497960 |
2013-01-24 | -176.337027 | -245.781003 | -476.244984 | -859.051229 |
2013-01-25 | -114.088941 | -88.472009 | -223.357691 | -21.877810 |
2013-01-28 | 561.438750 | 541.574299 | 128.308285 | 7316.523364 |
2013-01-29 | 754.042939 | -1580.615012 | -118.829268 | 6648.796176 |
2013-01-30 | -277.726223 | -1052.951634 | 21.997668 | 5318.535220 |
2013-01-31 | -635.522683 | -384.438339 | -193.629759 | -2363.942566 |
2013-02-01 | 277.012526 | 685.419476 | 43.566250 | -2887.138367 |
2013-02-04 | 11.635271 | -102.498642 | 421.132312 | 406.364862 |
2013-02-05 | 309.766066 | 201.864940 | 14.241537 | 809.950849 |
2013-02-06 | -1375.556692 | 422.981606 | 242.765310 | -627.891005 |
2013-02-07 | -1418.371288 | -128.403487 | 91.891544 | 207.498181 |
2013-02-08 | 330.748174 | -433.632656 | 469.743877 | 3491.495834 |
2013-02-18 | 730.739319 | -699.818576 | -239.043381 | 3523.098242 |
2013-02-19 | -589.629329 | -1204.597839 | -501.379041 | -552.376823 |
2013-02-20 | -400.295466 | 162.358136 | 65.892002 | -99.045404 |
2013-02-21 | -722.884875 | -1029.601472 | -328.228012 | -202.817184 |
... | ... | ... | ... | ... |
2015-11-20 | 2061.598100 | 286.921900 | -5652.561000 | -382.735600 |
2015-11-23 | 3835.791200 | 3341.213600 | -14269.236100 | 1595.656900 |
2015-11-24 | -603.142300 | -24108.018800 | 3442.250000 | 1066.059800 |
2015-11-25 | 3181.465200 | 10151.729700 | -11541.179200 | 1230.520500 |
2015-11-26 | -3166.144800 | -22665.949800 | 1554.558900 | 3246.328400 |
2015-11-27 | -6959.466700 | -15944.628000 | -20758.014400 | -5534.988800 |
2015-11-30 | -97.853400 | 9372.866700 | 31044.335400 | -841.783500 |
2015-12-01 | 817.955900 | -1899.332500 | -4174.628200 | 6129.797000 |
2015-12-02 | -3386.286300 | 19911.657500 | -13986.968200 | 4098.281900 |
2015-12-03 | 460.038200 | 7073.116200 | 146.147400 | -2363.317800 |
2015-12-04 | -1166.202000 | 21525.662000 | -9384.496400 | -4300.658300 |
2015-12-07 | 17268.245100 | 46117.177600 | 7958.978200 | -161.523200 |
2015-12-08 | -11015.471600 | 22878.849600 | -11802.606400 | -3696.896300 |
2015-12-09 | 336.531000 | 13673.856300 | -10230.006100 | 1114.145200 |
2015-12-10 | 1750.174000 | -16199.938200 | -3497.415200 | -1553.772500 |
2015-12-11 | 0.000000 | -16535.524100 | -18.617900 | 2606.004300 |
2015-12-14 | 7582.645900 | 8202.040200 | 3321.691700 | 373.558600 |
2015-12-15 | 2518.092700 | 2010.526400 | -2286.657000 | 458.441500 |
2015-12-16 | -1769.178300 | -32801.735300 | 2220.963400 | -654.583800 |
2015-12-17 | 1508.793000 | 8473.155300 | 7021.862500 | 10756.190500 |
2015-12-18 | -2574.355400 | -7428.519000 | -6256.674800 | 5786.952800 |
2015-12-21 | 842.652300 | -5842.915900 | -1923.055700 | 11370.697600 |
2015-12-22 | 2410.238200 | -17789.575200 | -258.123600 | -524.697100 |
2015-12-23 | -2802.707700 | 3489.547900 | -8048.524300 | -2296.202500 |
2015-12-24 | -3219.738000 | 15077.986200 | -691.512900 | -6165.277300 |
2015-12-25 | -37.568900 | -16338.972900 | -2975.415900 | -403.621400 |
2015-12-28 | -2042.185800 | -56722.714200 | -11981.833000 | -5276.584800 |
2015-12-29 | -1021.656900 | 50.363200 | 1397.116100 | -43.571600 |
2015-12-30 | -289.182200 | -2568.185500 | 2554.202500 | -824.561400 |
2015-12-31 | -409.671100 | NaN | -5376.076600 | -1774.697900 |
727 rows × 4 columns
from pandas import DataFrameresult = pd.DataFrame(index = ['inflow_raise','inflow_fall','inflow_total','outflow_raise','outflow_fall','outflow_total','nancase'])index = list(mf.index)print 'total observation %s'%len(index)for st in stock:inflow_raise = 0inflow_fall = 0outflow_raise = 0outflow_fall = 0nancase =0for i in index:if mf[st][i]>0 and returns[st][i]>0:inflow_raise +=1elif mf[st][i]>0 and returns[st][i]<0:inflow_fall +=1elif mf[st][i]<0 and returns[st][i]>0:outflow_raise +=1elif mf[st][i]<0 and returns[st][i]<0:outflow_fall +=1else:nancase +=1result.ix['inflow_raise',st] = inflow_raiseresult.ix['inflow_fall',st] = inflow_fallresult.ix['inflow_total',st] = inflow_raise + inflow_fallresult.ix['outflow_raise',st] = outflow_raiseresult.ix['outflow_fall',st] = outflow_fallresult.ix['outflow_total',st] = outflow_raise + outflow_fallresult.ix['nancase',st] = nancaseDataFrame(result)
total observation 727
002697.XSHE | 600783.XSHG | 000413.XSHE | 601588.XSHG | |
---|---|---|---|---|
inflow_raise | 268 | 262 | 249 | 267 |
inflow_fall | 15 | 16 | 29 | 34 |
inflow_total | 283 | 278 | 278 | 301 |
outflow_raise | 95 | 135 | 87 | 83 |
outflow_fall | 272 | 304 | 275 | 273 |
outflow_total | 367 | 439 | 362 | 356 |
nancase | 77 | 10 | 87 | 70 |
从四只股票三年的样本期统计结果来看:
资金流入很大程度上推动了股价上涨,约90%的样本显示资金流入后第二天股价会上涨。
资金流出与股价之间关系薄弱一些。约75%的样本显示资金流出后第二天股价会下跌,但仍有四分之一上涨的可能。
for i in range(3):print '\n-lag %d day-\n'%(i+1)for st in stock:print 'stock %s'%stprint 'relation between MF and returns %s'%mf[st].corr((data/data.shift(i+1)-1)[st])
-lag 1 day- stock 002697.XSHE relation between MF and returns 0.748903697509 stock 600783.XSHG relation between MF and returns 0.701385956416 stock 000413.XSHE relation between MF and returns 0.569819177204 stock 601588.XSHG relation between MF and returns 0.690081144963 -lag 2 day- stock 002697.XSHE relation between MF and returns 0.53775599578 stock 600783.XSHG relation between MF and returns 0.478376536913 stock 000413.XSHE relation between MF and returns 0.397615101759 stock 601588.XSHG relation between MF and returns 0.530967880278 -lag 3 day- stock 002697.XSHE relation between MF and returns 0.447300486377 stock 600783.XSHG relation between MF and returns 0.35553321953 stock 000413.XSHE relation between MF and returns 0.278029798308 stock 601588.XSHG relation between MF and returns 0.371966529902
我们这里观察了接下来n天的股票累计收益率。n选取1-3。
从相关性上来讲,当天资金净额对接下来n天的累计收益率的影响,随着时间期限的增长而减弱,但仍然呈现较强的正相关。
当天资金流入的股票第二天较大概率会上涨。
资金流入量越大的股票上涨幅度越大。
嗯,对的。这个结论并没有什么新意,与人们的主观认识是相符的。
本社区仅针对特定人员开放
查看需注册登录并通过风险意识测评
5秒后跳转登录页面...