Home : J-Integra for COM : HOWTO : Using J-Integra to Access Historical Time-Series Data from Bloomberg®
Q183198 - HOWTO: Using J-Integra to Access Historical Time-Series Data from Bloomberg®

Using J-Integra to Access Historical Time-Series Data from Bloomberg®

The following example demonstrates how to access Bloomberg® time-series data from your Java application via J-Integra. Before running this example, make sure you have completed the configuration steps outlined in our documentation:

Accessing Bloomberg® from Java

Copy and paste the code below (and reference the Java proxies for Bloomberg®) to get started with the example.

For a third-party solution leveraging J-Integra, please see Optura®'s Virtual Investment Analytics (VIA) automation platform. Additional information can also be found here.

import blpdatax.BlpData;
import blpdatax._BlpDataEventsAdapter;

public class HistoricalDataExample {
    //Bloomberg PERIODICITY constants
    final static int bbDaily = 1;
    final static int bbWeekly = 6;
    final static int bbMonthly = 7;
    final static int bbQuarterly = 8;
    final static int bbSemiAnnually = 5;
    final static int bbYearly = 9;
    final static int bbActualDaily = 1342177281;
    final static int bbActualWeekly = 1342177286;
    final static int bbActualMonthly = 1342177287;
    final static int bbActualQuarterly = 1342177288;
    final static int bbActualSemiAnnually = 1342177285;
    final static int bbActualAnnually = 1342177289;
    final static int bbCalendarDaily = 1610612737;
    final static int bbCalendarWeekly = 1610612742;
    final static int bbCalendarMonthly = 1610612743;
    final static int bbCalendarQuarterly = 1610612744;
    final static int bbCalendarSemiAnnually = 1610612741;
    final static int bbCalendarAnnually = 1610612745;
    final static int bbFiscalQuarterly = 1879048200;
    final static int bbFiscalSemiAnnually = 1879048197;
    final static int bbFiscalAnnually = 1879048201;
    //Bloomberg NON_TRADING_DAY constants
    final static int Omit = 0;
    final static int Week = 64;
    final static int AllCalendar = 128;
    //Bloomberg FILLER constants
    final static int BloombergHandles = 0;
    final static int PreviousDays = 256;
    final static int ShowNoNumber = 51;
    //Bloomberg FIRE_EVENT types
    final static int ByField = 0;
    final static int ByRequest = 1;
    final static int BySecurity = 2;
    // list of securities we wish to get historical data for
    static Object[] security = {"MSFT US Equity", "IBM US Equity"};
    // fields we are interested in
    static Object[] fields = {"Px_Open", "Px_High", "Px_Low", "Px_Last"};
    public static void main(String[] args) {
        try{
            //Uncomment this line if running J-Integra in native mode
            //i.e. Java and Bloomberg are running in the same machine
            //System.setProperty("JINTEGRA_NATIVE_MODE", "");
            // Uncomment this line if running J-Integra in DCOM mode
            // i.e. Java and Bloomberg are in different machines
            // DCOM authentication: Make sure NT Domain, NT User, NT Password are valid credentials.
            //com.linar.jintegra.AuthInfo.setDefault("NT DOMAIN", "NT USER", "NT PASSWORD");
            // Create the Bloomberg object
            // Specify host name or IP address of Bloomberg machine as parameter if
            // running in DCOM mode, e.g.:
            // BlpData blp = new BlpData("123.456.789.0");
            BlpData bloomberg = new BlpData();
            // add data listener
            DataListener2 dataListener = new DataListener2();
            bloomberg.add_BlpDataEventsListener(dataListener);
            // set some configuration modes
            bloomberg.setSubscriptionMode(BySecurity);
            bloomberg.setAutoRelease(false);
            // set properties related to historical data
            bloomberg.setPeriodicity(bbDaily);
            bloomberg.setDisplayNonTradingDays(Week);
            bloomberg.setNonTradingDayValue(PreviousDays);
            //set the period of the data (i.e. start and end dates)
            java.util.Date end = new java.util.Date();  // this gives the current system date
            // make the start date a year ago from today
            java.util.Date start = new java.util.Date(end.getTime() - 365*24*60*60*1000L);
            // package the parameters
            Object[] params = {security, new Integer(0), fields, start, end, null, null, null};
            // invoke the request via late binding
            bloomberg.invokeMethodByName("GetHistoricalData", params);
            // flush out the request
            bloomberg.flush();
            // This is to stop the program from terminating prematurely.
            // If not enough time is given, the program may terminate
            // before it receives data back from Bloomberg.
            Thread.sleep(10000);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            com.linar.jintegra.Cleaner.releaseAll();
        }
    }
}
class DataListener2 extends _BlpDataEventsAdapter {
    // this event is called once the request is flushed out
    public void data (blpdatax._BlpDataEventsDataEvent theEvent) throws java.io.IOException, com.linar.jintegra.AutomationException {
        System.out.println("\n *** DATA EVENT CALLED *** " );
        // obtain the security name
        Object[] securityArray = (Object[]) theEvent.getSecurity();
        System.out.println("Security: " + securityArray[0]);
        // print out the fields
        System.out.println("\t\t\t Date \t\t\t\t" +
                HistoricalDataExample.fields[0] + "\t" +
                HistoricalDataExample.fields[1] + "\t" +
                HistoricalDataExample.fields[2] + "\t" +
                HistoricalDataExample.fields[3]);
        // display the historical data
        Object[][] twoDimenArray = (Object[][]) theEvent.getData();
        for(int i=0; i<twoDimenArray.length; i++){
            for(int j=0; j<twoDimenArray[i].length; j++){
                System.out.print(twoDimenArray[i][j] + "\t");
            }
            System.out.println("");
        }
    }
    
    public void status (blpdatax._BlpDataEventsStatusEvent theEvent) throws java.io.IOException, com.linar.jintegra.AutomationException {
        System.out.println("*** STATUS EVENT CALLED *** " );
    }
}
Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.
Created on 7/11/2006.
Last Modified on 5/4/2010.
Last Modified by J-Integra KB Admin.
Article has been viewed 11811 times.
Rated 6 out of 10 based on 4 votes.
Print Article
Email Article