draw historical last price chart using bloomberg API

≯℡__Kan透↙ 提交于 2020-01-02 22:02:29

问题


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

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