From MATLAB to Python

3 visualizaciones (últimos 30 días)
andy quek
andy quek el 13 de Ag. de 2020
Respondida: Matt J el 13 de Ag. de 2020
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 comentarios
Rik
Rik el 13 de Ag. de 2020
What part don't you understand? How the subindexing works? What the diff function does? What the .* syntax means?
andy quek
andy quek el 13 de Ag. de 2020
Editada: andy quek el 13 de Ag. de 2020
Hi Rik, so my understanding of return is: sell price - buy price = return which is same as return = earnings - costs.
from what i understand
s(1:end-1) = the array of "1" and "-1"
diff(fitting30mAUDCAD.close) = difference in closing price
Below is a illustration of what i think this code means
Therefore i cant really process how return is derived
Example:
time price signal differce in closing code return
00:00:00 1 -1 0 0
01:00:00 1.2 0 -0.2 0
02:00:00 1.4 0 -0.2 0
03:00:00 1.6 0 -0.2 0
04:00:00 1.8 0 -0.2 0
05:00:00 2 0 -0.2 0
06:00:00 2.2 0 -0.2 0
07:00:00 2.4 0 -0.2 0
08:00:00 2.6 1 -0.2 -0.2
return -0.2
Return is actually -1.6 instead of -0.2.
Part i mention is from 11 mins - 11.40 mins

Iniciar sesión para comentar.

Respuestas (1)

Matt J
Matt J el 13 de Ag. de 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

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by