Code covered by the BSD License  

Highlights from
Automated Trading with MATLAB - 2012

image thumbnail

Automated Trading with MATLAB - 2012

by

 

31 Aug 2012 (Updated )

Files from the Automated Trading webinar showing X_Trader and QuickFIX/J integration.

leadlagFun(x,data,scaling,cost)
function sh = leadlagFun(x,data,scaling,cost)
% define leadlag to accept vectorized inputs and return only sharpe ratio
%%
% Copyright 2010-2012, The MathWorks, Inc.

[row,col] = size(x);
sh  = zeros(row,1);
t   = length(data);
x = round(x);

if ~exist('scaling','var')
    scaling = 1;
end
if ~exist('cost','var')
    cost = 0;
end

% run simulation
parfor i = 1:row
    
    if x(i,1) > x(i,2)
        sh(i) = NaN;
    else
        if col > 2
            tindex = 1:x(i,3):t;
            % Calculate scaling parameter for time sampling
            sc = sqrt(scaling^2 / x(i,3));
        else
            tindex = 1:t;
            sc = scaling;
        end
        if x(i,1)> length(tindex) || x(i,2) > length(tindex)
            sh(i) = NaN;
        end
        [~,~,sh(i)] = leadlag(data(tindex), x(i,1), x(i,2),sc,cost);
    end
end

Contact us