Retrieve Current and Historical Data UsingBloomberg桌面C ++接口
此示例显示了如何连接到彭博社®and retrieve current and historical Bloomberg market data. For details about Bloomberg connection requirements, seeData Server Connection RequirementsandInstalling Bloomberg and Configuring Connections.
Connect toBloomberg
Create the Bloomberg connection using the Bloomberg Desktop C++ interface.
c = bloomberg;
Validate the Bloomberg connection.
v = isconnection(c)
v = 1
v
returnstrue
显示,布隆伯格连接我s valid.
Retrieve Current Data
Format MATLAB®data display for currency.
formatbank
Retrieve closing and open prices for Microsoft®.
sec ='MSFT US Equity'; fields = {'LAST_PRICE';'OPEN'};% closing and open prices[d,sec] = getdata(c,sec,fields)
d = struct with fields: LAST_PRICE: 62.32 OPEN: 62.48 sec = cell 'MSFT US Equity'
d
contains the Bloomberg closing and open prices.sec
contains the Bloomberg security name for Microsoft.
Retrieve Historical Data
Retrieve monthly closing and open price data from January 1, 2012, through December 31, 2012, for Microsoft.
fromdate ='1/01/2012';% beginning of date range for historical datatodate ='12/31/2012';% ending of date range for historical dataperiod ='monthly';% retrieve monthly data[d,sec] = history(c,sec,fields,fromdate,todate,period)
d = 734899.00 29.53 26.55 734928.00 31.74 29.79 734959.00 32.26 31.93 734989.00 32.02 32.22 735020.00 29.19 32.05 735050.00 30.59 28.76 735081.00 29.47 30.62 735112.00 30.82 29.59 735142.00 29.76 30.45 735173.00 28.54 29.81 735203.00 26.61 28.84 735234.00 26.71 26.78 sec = cell 'MSFT US Equity'
d
contains the numeric representation of the date in the first column, closing price in the second column, and open price in the third column. Each row represents data for one month in the date range.sec
contains the Bloomberg security name for Microsoft.
Find Maximum Open Price in Date Range
Calculate the maximum open price for the year 2012.
openprices = d(:,3);% retrieve all open prices in date rangemax(openprices)% calculate maximum open price
ans = 32.22
CloseBloombergConnection
close(c)