From MATLAB to Python
显示 更早的评论
Hi, Im new to coding and matlab but i have some basics in Python. I'm trying to learn MATLAB using resources i found online. there is this code that i found but am not sure some of it. below is the code and the understanding i have:
%create indicator and return lead & lag values
[lead,lag] = movavg(fitting30mAUDCAD.close,5,20,"e");
%create a variable the size of close and put all "0"
s = zeros(size(fitting30mAUDCAD.close));
%criteria to sell
s (lead<=lag) = -1;
%criteria to buy
s (lead>lag) = 1;
%what does this mean?
r = [0;s(1:end-1).*diff(fitting30mAUDCAD.close)];
w = cumsum(r);
2 个评论
Rik
2020-8-13
What part don't you understand? How the subindexing works? What the diff function does? What the .* syntax means?
回答(1 个)
Matt J
2020-8-13
Below is a illustration of what i think this code means
It's not clear which column corresponds to which variable in your code. However, if I assume 3rd column is r,
>> r(1:9,1)=-0.2; r(1)=0
r =
0
-0.2000
-0.2000
-0.2000
-0.2000
-0.2000
-0.2000
-0.2000
-0.2000
then the w that gets computed should be,
>> w=cumsum(r)
w =
0
-0.2000
-0.4000
-0.6000
-0.8000
-1.0000
-1.2000
-1.4000
-1.6000
类别
在 帮助中心 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!