问题
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