Specifying input parameters when calling a python function from Matlab

조회 수: 4 (최근 30일)
Peter Winkler
Peter Winkler 2023년 7월 24일
댓글: Peter Winkler 2023년 7월 31일
I am using the Python Eikon Data API from the MATLAB environment to retrieve data.
The folloding code line works fine:
K>> [pylog,datarefinitiv]= evalc('py.eikon.get_data(''CDXHY5Y=MP'',''TR.MIDSPREAD.Date,TR.MIDSPREAD'')');
K>> datarefinitiv
datarefinitiv =
Python tuple with values:
( Instrument Date Mid Spread
0 CDXHY5Y=MP 2023-07-21T00:00:00Z 419.602, None)
Use string, double or cell function to convert to a MATLAB array.
However, I would like to retrieve the entire time series and not only the latest value. The corresponding code in Python looks like this:
df, err = ek.get_data(["CDXHY5Y=MP"],
["TR.MIDPRICE","TR.MIDPRICE.Date"],
{"SDate":"2023-06-01","EDate":"2023-07-24","Frq":"D"})
Could you please help how I could adapt my existing code line in order to add the additional specifications (start and end date, daily frequency) to retrieve the full set of data (i.e. how to specify the input parameters in curled brackets)?

답변 (1개)

Pratyush
Pratyush 2023년 7월 28일
I understand that you want to call your python function passing some arguments from the MATLAB side.
This modification in your code could help acheive your desired output:
[pylog, datarefinitiv] = evalc("py.eikon.get_data('CDXHY5Y=MP', 'TR.MIDSPREAD.Date,TR.MIDSPREAD', struct('SDate', '2023-06-01', 'EDate', '2023-07-24', 'Frq', 'D'))");
You can read more about passing parameters to python function from the following document: Pass MATLAB Data to Python - MATLAB & Simulink - MathWorks India
  댓글 수: 1
Peter Winkler
Peter Winkler 2023년 7월 31일
thank you very much for your support!
Modifying the code line as suggested worked perfectly!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by