Downloading data from bloomberg with object oriented programming.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Guillaume
el 3 de Sept. de 2019
Editada: Guillaume
el 3 de Sept. de 2019
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).
Respuestas (0)
Ver también
Categorías
Más información sobre Downloads en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!