From MATLAB to Python
3 views (last 30 days)
Show older comments
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 Comments
Rik
on 13 Aug 2020
What part don't you understand? How the subindexing works? What the diff function does? What the .* syntax means?
Answers (1)
Matt J
on 13 Aug 2020
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
0 Comments
See Also
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!