Bloomberg BLPAPI如何获得DV01的债券?

时间:2015-08-18 20:14:57

标签: c# bloomberg

我对BBG API很新,而且缺乏文档。我一直试图弄清楚如何获得DV01PV01一个债券,但我总是在我尝试的字段上出错。我错过了什么吗?下面的示例代码是我从blapi C#样本修改的。

private void run(string[] args)
{
    string serverHost = "localhost";
    int serverPort = 8194;

    SessionOptions sessionOptions = new SessionOptions();
    sessionOptions.ServerHost = serverHost;
    sessionOptions.ServerPort = serverPort;

    System.Console.WriteLine("Connecting to " + serverHost + ":" + serverPort);
    Session session = new Session(sessionOptions);
    bool sessionStarted = session.Start();
    if (!sessionStarted)
    {
        System.Console.WriteLine("Failed to start session.");
        return;
    }
    if (!session.OpenService("//blp/refdata"))
    {
        System.Console.Error.WriteLine("Failed to open //blp/refdata");
        return;
    }
    Service refDataService = session.GetService("//blp/refdata");

    Request request = refDataService.CreateRequest("ReferenceDataRequest");
    Element securities = request.GetElement("securities");

    //IBM Bond BBG004J4QNM9

    securities.AppendValue("BBG004J4QNM9");

    Element fields = request.GetElement("fields");
    fields.AppendValue("DS002");
    fields.AppendValue("MARKET_SECTOR_DES");
    fields.AppendValue("SECURITY_TYP2");
    fields.AppendValue("SECURITY_TYP");
    fields.AppendValue("ID_EXCH_SYMBOL");
    fields.AppendValue("PX_LAST");

    //None of these are returned
    fields.AppendValue("PV01_BID_CURRENCY_1");
    fields.AppendValue("PV01_MID_CURRENCY_1");
    fields.AppendValue("DV01");
    fields.AppendValue("HEDGE_RATIO_10Y_TSY");

    Console.WriteLine("Sending Request: " + request);
    session.SendRequest(request, null);

    while (true)
    {
        Event eventObj = session.NextEvent();
        foreach (Message msg in eventObj.GetMessages())
        {
            Console.WriteLine(msg.AsElement);
        }
        if (eventObj.Type == Event.EventType.RESPONSE)
        {                   
            break;
        }
    }
}

0 个答案:

没有答案