夏普比率编程

Denom = nanstd(Asset, 1);
zDenom = max(Asset) == min(Asset);
Ratio(zDenom) = NaN;
Ratio(~zDenom) = 1 ./ Denom(~zDenom);
Ratio = Ratio .* (nanmean(Asset) - C0 .* ones(1,n));

默认C0=0即无风险回报是0

夏普比率编程_第1张图片

国债的回报是3%,而您的预期回报是15%,您的投资的标准偏差是6%,那么用15%-3%,可以得出12%(代表您超出无风险投资的回报),再用12%/6%=2,代表投资者风险每增长1%,换来的是2%的多余收益。

 

sz = size(x)

dim = find(sz ~= 1, 1);

x0 = x - repmat(nanmean(x, dim), [4,1]);

均值方差

x0 = x - repmat(nanmean(x, dim), tile);
y = nansum(abs(x0).^2, dim) ./ denom;

 

求均值,1加x一行 2 加y一列

nanmean([1 2;2 3;3 4;4 5],2)

ans =

                       1.5
                       2.5
                       3.5
                       4.5

K>> nanmean([1 2;2 3;3 4;4 5],1)

ans =

                       2.5                       3.5

你可能感兴趣的:(夏普比率编程)