Conduct Back Test on Portfolio
This example shows how to conduct a back test on a set of stocks using transaction cost analysis from the Kissell Research Group.
Analyze the implementation of an investment strategy on a specific day or date range.
估计指定历史日期的历史市场影响成本和相应的美元价值。
Analyze the trading costs of different orders on various dates.
To access the example code, enter编辑KRGBackTestingExample.m
at the command line.
Retrieve Market-Impact Parameters and Load Historical Data
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','delimiter',。。。',','ReadRowNames',错误的,'ReadVariableNames',true);
Create a Kissell Research Group transaction cost analysis objectk
。Specify initial settings for the date, market-impact code, and number of trading days.
k = krg(miData,datetime('today'),1,250);
Load the example dataTradeDataBackTest
从文件krgexampledata.mat
, which is included with the Datafeed Toolbox™.
loadKrgexampledataTradeDataBackTest
有关示例数据的描述,请参见Kissell Research Group Data Sets。
Prepare Data for Back Testing
Determine the number of stocksnumRecords
in the portfolio.
numRecords = length(TradeDataBackTest.Symbol);
Preallocate the output data tableo
。
o = table(TradeDataBackTest.Symbol,TradeDataBackTest.Side,。。。TradeDataBackTest.Date,NaN(numRecords,1),NaN(numRecords,1),。。。'VariableNames',{'象征','Side','Date','MI','MIDollar'});
Ensure that the number of shares is a positive value using theabs
function.
TradeDataBackTest.Shares = abs(TradeDataBackTest.Shares);
Convert trade time trade strategy to the percentage of volume trade strategy.
TradeDataBackTest.TradeTime = TradeDataBackTest.TradeTime。。。。* TradeDataBackTest.ADV; TradeDataBackTest.POV = krg.tradetime2pov(TradeDataBackTest.TradeTime,。。。TradeDataBackTest.Shares);
通过估计历史市场影响成本来进行返回测试
Estimate the historical market-impact costs for each stock in the portfolio on different dates usingmarketImpact
。Convert market-impact cost from decimal into local dollars. Retrieve the resulting data in the output data tableo
。
forii = 1:numRecords k.midate = tradeDataBackTest.date(ii);K.Micode = TradeDataBackTest.Micode(ii);o.mi(ii)= marketImpact(k,tradeDataBackTest(ii,:));Midollars =(TradeDataBackTest.Shares(ii) * TradeDataBackTest.Price(ii))。。。* o.mi(ii)/10000 *交易databacktest.fxrate(ii);o.midollar(ii)= midollars;end
显示前三行输出数据。
o(1:3,:)
ans = Symbol Side Date MI MIDollar ______ ____ __________ ____ ________ 'A' 1.00 '5/1/2015' 1.04 103.91 'B' 1.00 '5/1/2015' 3.09 3864.44 'C' 1.00 '5/1/2015' 8.545335.03
The output data contains these variables:
Stock symbol
Side
历史交易日期
Historical market-impact cost in basis points
Historical market-impact value in local dollars
参考
[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.