“Ejecutar el código MATLAB en Python” Código de respuesta

Ejecutar el código MATLAB en Python

import matlab.engine
eng = matlab.engine.start_matlab()
eng.mscriptname(nargout=0)
Light Ladybird

Ejecutar el código MATLAB en Python


% 1 minute data on GLD-USO
load('inputData_ETF', 'tday', 'syms', 'cl');
idxG=find(strcmp('GLD', syms));
idxU=find(strcmp('USO', syms));

x=cl(:, idxG);
y=cl(:, idxU);

lookback=20; % Lookback set arbitrarily short
hedgeRatio=NaN(size(x, 1), 1);
for t=lookback:size(hedgeRatio, 1)
    regression_result=ols(y(t-lookback+1:t), [x(t-lookback+1:t) ones(lookback, 1)]);
    hedgeRatio(t)=regression_result.beta(1);
end

y2=[x y];

yport=sum([-hedgeRatio ones(size(hedgeRatio))].*y2, 2); % The net market value of the portfolio is same as the "spread"
hedgeRatio(1:lookback)=[]; % Removed because hedge ratio is indterminate
yport(1:lookback)=[]; 
y2(1:lookback, :)=[];
Green Team

Respuestas similares a “Ejecutar el código MATLAB en Python”

Preguntas similares a “Ejecutar el código MATLAB en Python”

Más respuestas relacionadas con “Ejecutar el código MATLAB en Python” en Python

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código