Problem with a function
1 view (last 30 days)
Show older comments
Julian Wzorek
on 11 Nov 2020
Commented: Julian Wzorek
on 11 Nov 2020
Hi, I would like to creat a function that calculate fn. I would like to assign 1 to s when x>v and 0 otherwise.
[fn]=lillietest1(daily_logreturns);
function [fn] = lillietest1(x)
n=lenght(x);
x=sort(x);
for i=1:n
v(i)=i/n;
if x(i)>=v(i)
s(i)=1;
else
s(i)=0;
end
end
fn=sum(s)/n;
end
0 Comments
Accepted Answer
Alan Stevens
on 11 Nov 2020
I don't have your daily log returns vector, so I can't check your result. You are the only person who can decide if the function makes sense!!
5 Comments
Alan Stevens
on 11 Nov 2020
Edited: Alan Stevens
on 11 Nov 2020
I've just done that and the value of 0 is correct for daily_logreturns, as you can see by the graph plotted by the modified code below. However, if you look at daily_prices instead, the value returned is 0.7305.
load daily_logreturns
[fn,c]=lillietest1(daily_logreturns);
% [fn,c]=lillietest1(daily_prices);
disp(fn)
plot(c(:,1),c(:,2),c(:,1),c(:,1))
xlabel('x'),ylabel('v'),grid
legend('v vs x','x vs x')
function [fn,c] = lillietest1(x)
n=length(x);
x=sort(x);
s = zeros(n,1);
v = zeros(n,1);
for i=1:n
v(i)=i/n;
if x(i)>=v(i)
s(i)=1;
else
s(i)=0;
end
end
fn=sum(s)/n;
c = [x v];
end
More Answers (1)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!