Using Java to get Bloomberg fields over specific dates

岁酱吖の 提交于 2019-12-24 10:03:06

问题


I'm trying to pull in specific data fields from the Bloomberg Java API. I see from the developers guide that I can pull in some fields with:

Request request = refDataSvc.createRequest("ReferenceDataRequest");
request.getElement("securities").appendValue("AAPL US Equity");
request.getElement("securities").appendValue("IBM US Equity");

request.getElement("fields").appendValue("PX_LAST"); // Last Price
request.getElement("fields").appendValue("DS002"); // Description
request.getElement("fields").appendValue("VWAP_VOLUME");
session.sendRequest(request, new CorrelationID(1));

How can I make a call like this while getting some of the fields over a specific date range? For example, I would like to get the: last trade price, last trade volume, the opening price for August 27th, 2012, and the VWAP volume for August 26th between 9AM and 11AM.


回答1:


You need to create a "HistoricalDataRequest" request:

Request request = refDataSvc.createRequest("HistoricalDataRequest");

You can then specify the start date and end date:

DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyyMMdd");
request.set("startDate", startDate.toString(fmt));
request.set("endDate", endDate.toString(fmt));

In your case, startdate and enddate will be 27-Aug for the first request, and 26-Aug for the second.

However, I'm not sure how you can override fields (VWAP_START_TIME and VWAP_END_TIME) to restrict your VWAP to 9-11AM in a historical request, for reference data you would do smoething like the code below - it might work for historical requests too:

Element overridesElt = request.getElement("overrides");
Element override = overridesElt.appendElement();
override.setElement("fieldId", "VWAP_START_TIME");
override.setElement("value", "09:00:00");

override = overridesElt.appendElement();
override.setElement("fieldId", "VWAP_END_TIME");
override.setElement("value", "11:00:00");


来源:https://stackoverflow.com/questions/12161395/using-java-to-get-bloomberg-fields-over-specific-dates

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!