Main Content

Optimize Trade Schedule Trading Strategy

This example shows how to optimize the strategy for a single stock by minimizing trading costs using transaction cost analysis from the Kissell Research Group. The optimization minimizes trading costs associated with the trade schedule trading strategy and a specified risk aversion parameter Lambda. The trading cost minimization is expressed as


where trading costs are market impact MI, price appreciation PA, and timing risk TR. For details, see marketImpact, priceAppreciation, and timingRisk.

This example requires an Optimization Toolbox™ license. For background information, see Optimization Theory Overview (Optimization Toolbox).

Here, you can optimize the trade schedule trade strategy. The optimization finds a local minimum for this expression. For ways to search for the global minimum, see Local vs. Global Optima (Optimization Toolbox). To optimize percentage of volume and trade time strategies, see Optimize Percentage of Volume Trading Strategy and Optimize Trade Time Trading Strategy.

To access the example code, enter edit KRGSingleStockOptimizationExample.m at the command line.

Retrieve Market-Impact Parameters

Retrieve the market-impact data from the Kissell Research Group FTP site. Connect to the FTP site using the ftp function with a user name and password. Navigate to the MI_Parameters folder and retrieve the market-impact data in the MI_Encrypted_Parameters.csv file. miData contains the encrypted market-impact date, code, and parameters.

f = ftp('','username','pwd');

miData = readtable('MI_Encrypted_Parameters.csv','delimiter', ...

Create a Kissell Research Group transaction cost analysis object k.

k = krg(miData);

Create Single Stock Data

The structure tradeData contains data for a single stock. Use a structure or table to define this data. The fields are:

  • Number of shares

  • Average daily volume

  • Volatility

  • Stock price

  • Alpha estimate

tradeData.Shares = 100000;
tradeData.ADV = 1000000;
tradeData.Volatility = 0.25;
tradeData.Price = 35;
tradeData.Alpha_bp = 50;

Define the number of trades and the volume per trade for the initial strategy. The fields VolumeProfile and TradeSchedule define the initial trade schedule trade strategy.

numIntervals = 26;
tradeData.VolumeProfile = ones(1,numIntervals) * ...
tradeData.TradeSchedule = ones(1,numIntervals) .* ...

Define Optimization Parameters

Define risk aversion level Lambda. Set Lambda from 0 to Inf.

Lambda = 1;

Define lower LB and upper UB bounds of shares traded per interval for optimization.

LB = zeros(1,numIntervals);
UB = ones(1,numIntervals) .* tradeData.Shares;    

Specify constraints Aeq and Beq to denote that shares traded in the trade schedule must match the total number of shares.

Aeq = ones(1,numIntervals);
Beq = tradeData.Shares;

Define the maximum number of function evaluations and iterations for optimization. Set 'MaxFunEvals' and 'MaxIter' to large values so that the optimization can iterate many times to find a local minimum.

options = optimoptions('fmincon','MaxFunEvals',100000,'MaxIter',100000);

Define the function handle fun for the objective function. To access the code for this function, enter edit krgSingleStockOptimizer.m.

fun = @(tradeschedule)krgSingleStockOptimizer(tradeschedule,k, ...

Minimize Trading Costs for Trade Strategy

Minimize the trading costs for the trade schedule trade strategy. fmincon finds the optimal value for the trade schedule trade strategy based on the lower and upper bound values. It does this by finding a local minimum for the trading cost.

[tradeData.TradeSchedule,totalcost,exitflag] = fmincon(fun, ...

To check whether fmincon found a local minimum, display the reason why the function stopped.

exitflag =


fmincon returns 1 when it finds a local minimum. For details, see exitflag (Optimization Toolbox).

Display the optimized trade strategy tradeData.TradeSchedule.

ans =

  Columns 1 through 5

      35563.33      18220.14      11688.59       8256.81       6057.39

Estimate Trading Costs for Optimized Strategy

Estimate trading costs tradeScheduleCosts using the optimized trade strategy.

mi = marketImpact(k,tradeData);
pa = priceAppreciation(k,tradeData);
tr = timingRisk(k,tradeData);
tradeScheduleCosts = [totalcost mi pa tr];

Display trading costs.

tradeScheduleCosts =

         97.32         47.66          6.75         42.91

The trading costs are:

  • Total cost

  • Market impact

  • Price appreciation

  • Timing risk

For details about the preceding calculations, contact the Kissell Research Group.


[1] Kissell, Robert. “Algorithmic Trading Strategies.” Ph.D. Thesis. Fordham University, May 2006.

[2] Kissell, Robert. The Science of Algorithmic Trading and Portfolio Management. Cambridge, MA: Elsevier/Academic Press, 2013.

[3] Glantz, Morton, and Robert Kissell. Multi-Asset Risk Modeling. Cambridge, MA: Elsevier/Academic Press, 2013.

[4] Kissell, Robert, and Morton Glantz. Optimal Trading Strategies. New York, NY: AMACOM, Inc., 2003.

See Also

(Optimization Toolbox) | (Optimization Toolbox) | | | |

Related Topics