对投资组合进行压力测试
This example shows how to conduct a stress test on a set of stocks using transaction cost analysis from the Kissell Research Group.
Estimate historical market-impact costs and the corresponding dollar values for the specified date range.
Use trading costs to screen stocks in a portfolio and estimate the cost to liquidate or purchase a specified number of shares.
Analyze trading costs during volatile periods of time such as a financial crisis, flash crash, or debt crisis.
To access the example code, enteredit KRGStressTestingExample.m
at the command line.
检索市场影响参数并加载历史数据
Retrieve the market-impact data from the Kissell Research Group FTP site. Connect to the FTP site using theftp
使用用户名和密码函数。导航到MI_Parameters
folder and retrieve the market-impact data in theMI_Encrypted_Parameters.csv
文件。miData
包含加密的市场影响日期,代码和参数。
f = ftp('ftp.kissellresearch.com','用户名','PWD');mget(f,'MI_Encrypted_Parameters.csv');关闭(f)midata =可读取('MI_Encrypted_Parameters.csv',“定界符”,。。。',','ReadRowNames',错误的,'ReadVariableNames',true);
Load the example dataTradeDataStressTest
从文件krgexampledata.mat
, which is included with the Datafeed Toolbox™.
loadKrgexampledataTradeDataStressTest
有关示例数据的描述,请参见Kissell研究小组数据集。
创建Kissell研究小组交易成本分析对象k
。Specify initial settings for the date, market-impact code, and number of trading days.
k = krg(miData,datetime('today'),1,250);
准备压力测试的数据
Specify the date range from May 1, 2015, through July 31, 2015.
StartDate ='5/1/2015'; endDate ='7/31/2015';
确定股票数量numStocks
在portfolio. Create a date rangedateRange
从指定的日期。找到天数数字
in the date range.
numStocks = length(TradeDataStressTest.Symbol); dateRange = (datenum(startDate):datenum(endDate))'; numDates = length(dateRange);
Preallocate the output data tableo
。
outlength = numStocks*numdates;符号= tradeDataStressTest.symbol(:,ones(1,numdates));side = tradeDataStressTest.side(:,ones(1,numdates));dates = depaterange(:,一个(1,numstocks))';o = table(符号(:),侧(:),日期(:),nan(outlength,1),nan(utlength,1),。。。'VariableNames',{'象征','Side','Date','MI','MIDollar'});
确保使用的股票数量是正值abs
function.
TradeDataStressTest.Shares = abs(TradeDataStressTest.Shares);
Convert trade time trade strategy to the percentage of volume trade strategy.
TradeDataStressTest.TradeTime = TradeDataStressTest.TradeTime。。。。TradeDataStressTest.pov = Krg.TradeTime2Pov(TradeDataStressTest.TradEtime,TradeDateTime,。。。TradeDataStressTest.Shares);
Conduct Stress Test by Estimating Historical Market-Impact Costs
Estimate the historical market-impact costs for each stock in the portfolio for the date range usingmarketImpact
。将市场影响的成本从十进制转换为本地美元。在输出数据表中检索结果数据o
。
kk = 1;forii =过多(1):过多(结束)forjj = 1:numStocks k.MiCode = TradeDataStressTest.MICode(jj); k.MiDate = ii; o.MI(kk) = marketImpact(k,TradeDataStressTest(jj,:)); o.MIDollar(kk) = (TradeDataStressTest.Shares(jj)。。。* TradeDataStressTest.Price(JJ))。。。* o.mi(kk) /10000 * tradeDataStressTest.fxrate(JJ);kk = kk + 1;endend
显示前三行输出数据。
o(1:3,:)
ans = Symbol Side Date MI MIDollar ______ ____ _________ _____ ________ 'A' 1.00 736085.00 3.84 384.31 'B' 1.00 736085.00 11.43 14292.24 'C' 1.00 736085.00 32.69 20430.65
The output data contains these variables:
库存符号
边
历史交易日期
Historical market-impact cost in basis points
Historical market-impact value in local dollars
Retrieve the daily market-impact costdailyCost
。Determine the number of daysnumDays
in the output data. Loop through the data and sum the market-impact costs for individual stocks for each day.
numdays =长度(o.date)/numstocks;idx = 1;fori = 1:numDays dailyCost.Date(i) = o.Date(idx); dailyCost.DailyMiCost(i) = sum(o.MI(idx:idx+(numStocks-1))); idx = idx+numStocks;end
Display the daily market-impact cost in the specified date range. This figure demonstrates how market-impact costs change over time.
plot(b.Date,b.DailyMiCost) ylabel({“每日费用”,'(bps)'}) title(“每日市场影响力压力测试”)xlabel('Date') 网格上xData = linspace(b.date(1),b.date(92),11);a = gca;a.xaxis.ticklabels = datester(xdata,'mm/dd/yyyy');a.XTickLabelRotation = 45;
参考
[1] Kissell, Robert. “Creating Dynamic Pre-Trade Models: Beyond the Black Box.”Journal of Trading。卷。6,第4号,2011年秋季,第8-15页。
[2] Kissell, Robert. “TCA in the Investment Process: An Overview.”Journal of Index Investing。卷。2, Number 1, Summer 2011, pp. 60–64.
[3] Kissell, Robert.算法交易和投资组合管理科学。马萨诸塞州剑桥:Elsevier/Academic Press,2013年。
[4] Chung, Grace and Robert Kissell. “An Application of Transaction Costs in the Portfolio Optimization Process.”Journal of Trading。卷。11, Number 2, Spring 2016, pp. 11–20.