请 [注册] 或 [登录]  | 返回主站

量化交易吧 /  数理科学 帖子:3364762 新帖:0

探析资金流-1:股价与资金净额

醒掌天下权发表于:5 月 9 日 23:37回复(1)

昨天发了一篇资金流模型的研究,觉得其中还有很多地方不足,需要对历史数据做些分析来加强自己的判断基础。这个过程中会附带产生一些策略的想法。

探索是个比较长期的过程,之后会继续找些感兴趣的角度来研究。

对于资金流,各位还有其他的剖析角度也请留言。

探析资金流¶

资金流反映了股票的供求关系。传统的量价无法区分市场微观结构的流动性和私有信息对股票的影响,而根据委托的情况测算的资金流,可以体现出微观市场交易者的真实意图和对股价造成的影响。

1.资金流定义¶

股票价格在一段时间中:

(1)资金流入:股价上升状态所产生的成交额,代表推动价格上涨的动力

(2)资金流出:股价下跌过程中产生的成交额,代表推动价格下跌的力量

当天的资金流入与流出的差额,是当天买卖双方力量抵消之后,推动价格变化的净作用量,被定义为当天的资金净流量(MF)。

2.资金流的测算¶

每一个买单都对应有一个买单,真实的资金流入无法准确的计算。我们只能选择通过高频数据,将每笔交易按推动股价上涨和下跌的差异分类,判断为资金的流入或流出,最终汇总成一天的资金流净额。

测算的方法主要在于时间频率的选择上以及参考的价格。

本篇研究将使用分钟频率的数据按照上述方法进行测算。

3.资金流出、流出与股票上涨、下跌的关系¶

我们拿几只股票简单的验证一下。

统计5只股票三年内日度资金流入且上涨、流入且下跌、流出且上涨、流出且下跌的次数。

002697 红旗连锁, 600783 鲁信创投, 000413 东旭光电, 601588 北辰实业

step1. 统计资金净额(MF)¶
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.XSHE600783.XSHG000413.XSHE601588.XSHG
2013-01-04NaNNaNNaNNaN
2013-01-070.0540540.0216780.024938-0.003460
2013-01-08-0.0073260.071033-0.002433-0.013889
2013-01-09-0.033210-0.029285-0.0170730.003521
2013-01-100.0038170.0133100.0074440.014035
step2. 资金净额与第二天股价涨跌统计¶
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.XSHE600783.XSHG000413.XSHE601588.XSHG
2013-01-04-632.015065-853.500162-52.518953-82.400005
2013-01-072777.010564323.959516384.781446-129.990143
2013-01-08-774.4797781778.745617-36.237028-1497.927957
2013-01-09-1297.430313-1063.784692-755.49640160.005794
2013-01-10-115.957243-408.996284821.936128256.398971
2013-01-1119.946978-276.199297-289.954483-534.014179
2013-01-143149.0047011989.192942382.522086633.239465
2013-01-15-624.438327-416.530685567.549185-140.769076
2013-01-16-1301.171309-3282.802560480.037442-835.550557
2013-01-17-1253.026329-1941.776679179.116813-148.990225
2013-01-18-41.380740415.980415-334.765599656.559204
2013-01-21415.767143-814.95642220.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-28561.438750541.574299128.3082857316.523364
2013-01-29754.042939-1580.615012-118.8292686648.796176
2013-01-30-277.726223-1052.95163421.9976685318.535220
2013-01-31-635.522683-384.438339-193.629759-2363.942566
2013-02-01277.012526685.41947643.566250-2887.138367
2013-02-0411.635271-102.498642421.132312406.364862
2013-02-05309.766066201.86494014.241537809.950849
2013-02-06-1375.556692422.981606242.765310-627.891005
2013-02-07-1418.371288-128.40348791.891544207.498181
2013-02-08330.748174-433.632656469.7438773491.495834
2013-02-18730.739319-699.818576-239.0433813523.098242
2013-02-19-589.629329-1204.597839-501.379041-552.376823
2013-02-20-400.295466162.35813665.892002-99.045404
2013-02-21-722.884875-1029.601472-328.228012-202.817184
...............
2015-11-202061.598100286.921900-5652.561000-382.735600
2015-11-233835.7912003341.213600-14269.2361001595.656900
2015-11-24-603.142300-24108.0188003442.2500001066.059800
2015-11-253181.46520010151.729700-11541.1792001230.520500
2015-11-26-3166.144800-22665.9498001554.5589003246.328400
2015-11-27-6959.466700-15944.628000-20758.014400-5534.988800
2015-11-30-97.8534009372.86670031044.335400-841.783500
2015-12-01817.955900-1899.332500-4174.6282006129.797000
2015-12-02-3386.28630019911.657500-13986.9682004098.281900
2015-12-03460.0382007073.116200146.147400-2363.317800
2015-12-04-1166.20200021525.662000-9384.496400-4300.658300
2015-12-0717268.24510046117.1776007958.978200-161.523200
2015-12-08-11015.47160022878.849600-11802.606400-3696.896300
2015-12-09336.53100013673.856300-10230.0061001114.145200
2015-12-101750.174000-16199.938200-3497.415200-1553.772500
2015-12-110.000000-16535.524100-18.6179002606.004300
2015-12-147582.6459008202.0402003321.691700373.558600
2015-12-152518.0927002010.526400-2286.657000458.441500
2015-12-16-1769.178300-32801.7353002220.963400-654.583800
2015-12-171508.7930008473.1553007021.86250010756.190500
2015-12-18-2574.355400-7428.519000-6256.6748005786.952800
2015-12-21842.652300-5842.915900-1923.05570011370.697600
2015-12-222410.238200-17789.575200-258.123600-524.697100
2015-12-23-2802.7077003489.547900-8048.524300-2296.202500
2015-12-24-3219.73800015077.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.65690050.3632001397.116100-43.571600
2015-12-30-289.182200-2568.1855002554.202500-824.561400
2015-12-31-409.671100NaN-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.XSHE600783.XSHG000413.XSHE601588.XSHG
inflow_raise268262249267
inflow_fall15162934
inflow_total283278278301
outflow_raise951358783
outflow_fall272304275273
outflow_total367439362356
nancase77108770

从四只股票三年的样本期统计结果来看:

  1. 资金流入很大程度上推动了股价上涨,约90%的样本显示资金流入后第二天股价会上涨。

  2. 资金流出与股价之间关系薄弱一些。约75%的样本显示资金流出后第二天股价会下跌,但仍有四分之一上涨的可能。

step3. 计算MF与未来n天收益率相关性¶
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天的累计收益率的影响,随着时间期限的增长而减弱,但仍然呈现较强的正相关。

4、推论¶

  1. 当天资金流入的股票第二天较大概率会上涨。

  2. 资金流入量越大的股票上涨幅度越大。

嗯,对的。这个结论并没有什么新意,与人们的主观认识是相符的。

全部回复

0/140

量化课程

    移动端课程