您的位置:首页 > 编程语言 > MATLAB

写论文第八天:MATLAB之leadlagFun函数

2016-05-06 07:35 453 查看
function sh = leadlagFun(x,data,scaling,cost)
% define leadlag to accept vectorized inputs and return only sharpe ratio
%返回多组短期、长期(分别为x11,x12,x21,x22,…)的指数移动均线的夏普指数
%%
% Copyright 2010, The MathWorks, Inc.
% All rights reserved.
[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;
%elseif x(i,1) > t || x(i,2) > t
%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
[~,~,sh(i)] = leadlag(data(tindex), x(i,1), x(i,2),sc,cost);
%返回多组短期、长期的指数移动均线
end
end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: