Downloading data from bloomberg with object oriented programming.

조회 수: 1 (최근 30일)
BdS
BdS 2019년 9월 2일
편집: Guillaume 2019년 9월 3일
Hi
I would like to download Portfolio data from Bloomberg.
Unfortunatelly, I get an error message:
%%%%%%%
Undefined function 'getPortMembers' for input arguments of type 'blp'.
Error in getPortRawData (line 12)
obj=getPortMembers(c,PortID);
%%%%%%%%%%
May be it has to do with the object c... which represents the bloomberg connection with matlab:
Which is not compatible with OOP?
Would you please confirm?
classdef getPortRawData
properties
Dates
%PortWeights
PortMembers
end
methods
function obj=getPortRawData(c,PortID,inputs)
obj=dateSequence(obj,inputs);
obj=getPortMembers(c,PortID);
%obj=getPortWeights(c,PortID);
end
% 1)
function obj=dateSequence(obj,inputs)
% Generate sequence of dates without weekends
t1=datetime(inputs.startdate);
t2=datetime(inputs.enddate);
tempDates=transpose(t1:t2);
% weekdays indicator
w_days=~isweekend(tempDates);
obj.Dates=tempDates(w_days);
end
% 2)
function obj=getPortMembers(obj,c,PortID)
% Define input parameters
portField={'PORTFOLIO_MWEIGHT'};
override={'REFERENCE_DATE'};
nDates=size(obj.Dates);
%start downloading raw portfolio data
for r=1:nDates
rawPortData{r}=portfolio(c,PortID,portField,override,datestr(obj.Dates(r,1),'yyyymmdd'));
% simplify data storage structure and delete first row
rawPortData{r}=rawPortData{r,1}.PORTFOLIO_MWEIGHT{1,1};
% find unique portfolio members
if rr==1
obj.PortMembers=rawPortData{r}(:,1);
else
obj.PortMembers=union(obj.PortMembers,rawPortData{r}(:,1),'sorted');
end
end
end
end
end
  댓글 수: 3
BdS
BdS 2019년 9월 3일
It worked! Thank you!
Guillaume
Guillaume 2019년 9월 3일
편집: Guillaume 2019년 9월 3일
obj = getPortMenbers(obj, c, PortID);
would have worked as well. But yes, as Robert said, you have to pass the object to the object method.
And as Robert said you should change your
nDates=size(obj.Dates);
to
nDates=size(obj.Dates, 1);
because that's what your code is doing, even if it's not explicit. As many people do not know how the colon operator behaves when used on a vector (it uses the first element only), it's better to be explicit. That's assuming that you meant the number of rows in obj.Dates and not something else (like the number of elements regardless of the shape of Dates).

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Downloads에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by