问题
I want to draw historical last price charts using the Bloomberg Java API but I don't know which Bloomberg classes I should use.
回答1:
Assuming you are using the Bloomberg Java API, for historical data you need to use the "//blp/refdata"
service and send a "HistoricalDataRequest"
. Several examples are given in the Developer's guide, available on the project page.
Alternatively, you can use jBloomberg* which is simpler to use because it handles the messy details for you. To retrieve historical data, you can follow the example given in the javadoc:
BloombergSession session = new DefaultBloombergSession();
session.start();
RequestBuilder<HistoricalData> hrb = new HistoricalRequestBuilder("SPX Index",
"PX_LAST", DateTime.now().minusDays(7),
DateTime.now())
.fill(HistoricalRequestBuilder.Fill.NIL_VALUE)
.days(HistoricalRequestBuilder.Days.ALL_CALENDAR_DAYS);
HistoricalData result = session.submit(hrb).get();
Map<DateTime, TypedObject> data = result.forSecurity("SPX Index").forField("PX_LAST").get();
for (Map.Entry<DateTime, TypedObject> e : data.entrySet()) {
DateTime dt = e.getKey();
double price = e.getValue().asDouble();
System.out.println("[" + dt + "] " + price);
}
*Disclaimer: I am the author of jBloomberg
来源:https://stackoverflow.com/questions/18173350/draw-historical-last-price-chart-using-bloomberg-api