Click here to Skip to main content
15,890,438 members
Articles / Web Development / HTML

Development of Custom Studies for Bloomberg Terminal

Rate me:
Please Sign up or sign in to vote.
4.60/5 (3 votes)
19 Feb 2015CPOL8 min read 35.9K   207   7   17
Development of custom studies for Bloomberg terminal

Preview of custom study on Bloomberg Terminal

Introduction

Bloomberg L.P. provides financial software tools such as an analytics and equity trading platform, data services and news to financial companies and organizations through its Bloomberg Professional Service [1]. Bloomberg Terminal provides a number of API standards allowing extensions of its original capabilities. These include Bloomberg Study SDK and Bloomberg Application Portal SDK.

There is very little public information available on these SDK. I develop custom studies for Bloomberg Terminal using Bloomberg Study SDK for several years and would like to provide a quick start introduction to this technology as well as to give some deeper insights into little known caveats of development on Bloomberg platform.

Installation

To work with Bloomberg Study SDK you must have an active Bloomberg Professional Service account accessed via local Bloomberg installation - the shortcut on your desktop, not via Bloomberg Anywhere. You must have a valid license for using Bloomberg Study SDK on Bloomberg Professional Service before you can proceed.

As of the moment of writing this paper, Bloomberg Study SDK supports Microsoft Visual Studio 2013 and 2012. Express editions do not qualify.

Custom Study Manager Install SDK

To download and Install the SDK follow these steps:

  1. Make sure you have valid SDK license
  2. Type Bloomberg command: CSDK
  3. Use menu: SDK > Custom Study SDK
  4. Select latest SDK version from the table
  5. Click “Install” against the selected package in SDK table
  6. Wait for setup to complete

By default, the SDK is installed in the C:\Program Files\Bloomberg\SmartClient\Study SDK on your PC.

Bloomberg Toolbox

To verify installation open Visual Studio. You will see Bloomberg Study SDK toolbox on Visual Studio toolbar.

Toolbar offers the following features (ordered by button position on toolbar):

  1. Preview study in Bloomberg
  2. Debug study in Bloomberg
  3. Attach to study
  4. Detach from study
  5. Study settings
  6. Publish study
  7. Profile study

Next sections explain the use of these functions in more detail.

Create New Bloomberg Study ID

Creation of a new custom study is two-step process. Part of it is done in Bloomberg Terminal and another part in Visual Studio.

First, let us consider the first part: creation of new study ID on Bloomberg Terminal. To create new study follow these steps:

  1. Type “STDY” on Bloomberg command line to open Customs Study Manager
  2. Menu: “Create Study”

    Custom Study Manager Menu SDK

  3. Choose “CS.NET” study type

    Image 5

  4. Enter study name. For instance: “CodeProject Sample”
  5. Create a unique study identifier. For instance: “CODEPROJECT_SAMPLE.1”. There is a convention that study ID is named in capital letters with a version number appended at the end. Study ID should not contain whitespaces.

    Image 6

  6. The name and ID should be unique among all names and IDs of studies in Bloomberg network. If the name is not unique, error will appear. This might be confusing because you may not have access to third party studies causing conflicts and you may never be able watching them in the list of custom studies.
  7. Add Study Administrator
    a. Administrative groups: “Add”
    b. Add Role: Type your user name
    c. Check box “Administrator” set checked

    Image 7

  8. Confirm all entered information.
  9. You will see confirmation on new study created

Image 8

After completion of these steps you have new study ID on Bloomberg Terminal.

Create New Bloomberg Study Code

To create a new study project:

  1. Start Visual Studio.
  2. Select File > New > Project. The New Project dialog appears.
  3. Select Visual C# Project Types list.
  4. Select “Bloomberg Custom Study” under “My Templates” in the Templates pane.
  5. Enter a name for your project in the Name, e.g. "CodeProject", field and click OK.
  6. Add to or edit the generated skeleton code as needed.

Image 9

Note: apart from “Bloomberg Custom Study” project type, one can create other types of Bloomberg projects listed in dialog. These projects differ with the scope of API available and original code template used on creation. We recommend using “Bloomberg Custom Study” as a default, unless you have reasons for other choice and know for sure what you are doing.

Coding Your First Study

Bloomberg Custom Study after completion provides you with ready to run sample study code.

Wizard creates a new study project according to selected project name, for instance: "CodeProject". Created project contains just one editable code file named equally to project name: “CodeProject.cs”. This file contains namespace and partial class also named equally to the project name:

C#
namespace CodeProject
{
 public partial class CodeProject
 { 

In addition, a supplementary designer file “CodeProject.Designer.cs” is created:

C#
namespace CodeProject
{
     // Auto-generated code as part of the Bloomberg Custom Study template. Please
     // do not change.
     [BlpCustomStudy(Id = "CodeProject", Description = "Custom Study")]
     public partial class CodeProject : CustomStudy
     {
         public CodeProject (IDictionary input)
         : base(input)
         {
            Initialize();
         }
     }
} 

Normally, you should never edit this file. However, it can be useful in debugging and understanding the interaction of the study with Bloomberg Terminal.

Lets return to the main study file “CodeProject.cs”. The code of generated sample study is self-explanatory and already contains detailed comments on its structure and steps necessary to modify and run it.

C#
/// <summary>
/// The Study class has three components:
/// 1) The study properties definitions - Sets up study properties that the end-user can modify.
/// 2) The Initialize() method - Sets up the study visuals (panels, lines, annotations, etc.).
/// 3) The Calculate() method - Calculates the study outputs used by the visuals.
/// </summary>

The class contains definitions of parameters for the study and a template to create more parameters of different types:

C#
#region Code Example
 // Please refer to the sample study projects provided with the Bloomberg Custom Study
// SDK for more detailed examples.

// This is where the properties of the study are defined.  These properties are
// displayed in the "Study Properties" dialog in the "Settings" tab for the end-user
// to modify.  The study property values can be used to change the way in which the
// study calculates its outputs.

// There are five study property classes:
// 1) StudyBooleanProperty - Provides the ability to turn a study feature on or off.
// 2) StudyIntegerProperty - Provides the selection of an integer value.
// 3) StudyDoubleProperty  - Provides the selection of a floating point value.
// 4) StudyPriceProperty   - Provides the selection of an input price type.
// 5) StudyEnumProperty<T> - Provides the selection of an enumerated value.

// For example, a moving average study that lets the end-user choose the
// input price and the period used by the moving average would create
// the following two study properties.

public StudyPriceProperty Price = new StudyPriceProperty(PriceType.Close);
public StudyIntegerProperty Period = new StudyIntegerProperty(11);
#endregion

Here is a default example of Initialize() method created by the wizard:

C#
/// <summary>
/// Initialize() sets up the study outputs and visuals that the study will use.
///
/// Initialize() is called once when the study is applied to the chart or
/// when the chart is reinitialized due to a chart property change such as
/// a symbol or time interval change.
///
/// This code is validated in the post build. Any inconsistency such as a typo
/// in any of the strings used to name or associate components will cause
/// the build to fail and an error will be displayed in the Visual Studio output
/// window.
/// </summary>
private void Initialize()
{
    #region Code Example
    // Please refer to the sample study projects provided with the Bloomberg Custom
    // Study SDK for more detailed examples.
    // The study outputs are lists of values used by the study visuals for drawing
    // lines, annotations, paint bars, trend lines, and other visuals on the chart.
    // The outputs are created in this method and are added to the Output object.
    // Outputs are given names which are used to associate them with visuals and to
    // specify which output to update in the Calculate() method.

    // The study visuals are given names and placed into chart panels.  The panel
    // that the study is applied to is called the parent panel.  A study can add
    // visuals to the parent panel or to new panels that it creates.

    // For example, the moving average study creates one output for the moving
    // average line called "AvgData". It creates a study line visual to display
    // the moving average line and associates the "AvgData" output with it.
    // Finally the study line visual is placed into the parent panel with the name
    // "Average".

    Output.Add("AvgData", new TimeSeries());
    StudyLine avgLine = new StudyLine("AvgData", Color.Lime);
    ParentPanel.Visuals.Add("Average", avgLine);
    #endregion
}

Here is a default example of Calculate() method created by the wizard:

C#
/// <summary>
/// Calculate() updates the outputs used by the study visuals.
///
/// Calculate() is called when the study is first applied to the chart
/// and periodically when the chart's data changes.
///
/// Uncaught exceptions in Calculate() will be displayed as a pop-up
/// error message.
/// </summary>
public override void Calculate()
{
    #region Code Example
    // Please refer to the sample study projects provided with the Bloomberg Custom
    // Study SDK for more detailed examples.

    // The Input object provides various series of doubles from the chart
    // which are available to use in the calculation.

    // The TimeSeries and Indicator classes havemany methods available for
    // calculating the study's output which can be combined to produce more
    // complex output series.

    // The Output object has the outputs used by the visuals which are
    // updated in the Calculate() method.  The output objects are added in the
    // Initialize() method and are only updated here.

    // For example, the moving average study, uses the "Price" property's value to
    // allow the end-user to select the input to use for the moving average.
    // It then uses the "Period" property's value to calculate the moving average on
    // the input, and updates the Output object associated with the moving average line.

    TimeSeries input = Input[Price.Value];
    Output.Update("AvgData", Indicator.SMAvg(input, Period.Value));
    #endregion
}

You must just uncomment few lines, as illustrated above, and then you can run your first study and see it on Bloomberg chart.

If you omit all comments, the complete study code appears incredibly simple:

C#
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Bloomberg.Study.API;
using Bloomberg.Study.CoreAPI;
using Bloomberg.Study.Util;
using Bloomberg.Study.TA;
using Bloomberg.Math;

namespace CodeProject
{
    public partial class CodeProject
    {
        public StudyPriceProperty Price = new StudyPriceProperty(PriceType.Close);
        public StudyIntegerProperty Period = new StudyIntegerProperty(11);

        private void Initialize()
        {
            Output.Add("AvgData", new TimeSeries());
            StudyLine avgLine = new StudyLine("AvgData", Color.Lime);
            ParentPanel.Visuals.Add("Average", avgLine);
        }

        public override void Calculate()
        {
            TimeSeries input = Input[Price.Value];
            Output.Update("AvgData", Indicator.SMAvg(input, Period.Value));
        }
    }
}

Now let us see how it looks like when run on Bloomberg Terminal.

Preview a Study on Bloomberg Terminal

To preview a Custom Study do the following steps:

  1. Compile your custom study.
  2. Click the Study Settings icon on the Study Tools toolbar.
  3. The Project Settings dialog opens.
  4. Select the study project from the Project list.
  5. Enter the single-security G chart # on which to preview the study.

    Image 10

  6. Click Save.
  7. Click the Preview Study in Bloomberg icon on the Study Tools toolbar.
  8. The G chart is launched in a Bloomberg panel with the study previewed.
  9. Right-click on the chart and select Preview Study > Settings to launch the Study
  10. Properties popup for the previewed study.
  11. Modify the settings of the previewed study.
  12. Select the Display tab to modify the visual properties of the previewed study.
  13. Click Update to refresh the chart with the new properties of the previewed study.

Publishing a Study

When publishing a new study you should us new custom study profile created above:

  1. Click the Publish Study icon on the Study Tools toolbar to launch the Publishing Wizard.
  2. Click Next to go to the Publish Study page of the wizard.
  3. Select the study project to publish from the Project list.

    Image 11
     
  4. Select the same study ID created in the previous section to use as the publishing target.
  5. Click Next to go to the Study Dependencies page of the wizard.

    Image 12
     
  6. Click Next to go to the Additional Resources page of the wizard.
  7. Click Next to go to the Version Summary page of the wizard.
  8. Enter a version Label for the custom study, if necessary.
  9. Enter Comments for the custom study, if necessary, and review the Summary.

    Image 13
     
  10. Click Next to publish the custom study.
  11. Click OK to close the publishing wizard. The study should appear on STDY<GO> in approximately 10 minutes.

Using a Published Custom Study

To use a published custom study, add it to a single-security G chart:

  1. Create a new single-security chart or open an existing one.
  2. Select Edit > Data Series & Studies to launch the Properties popup to the Data Series & Studies panel.
  3. Expand the User Defined Studies node on the left.

    Image 14
     
  4. Expand the My Studies node.
  5. Click the custom study’s name to add it to the right side of the panel.
  6. Enter 1<GO> or click Update to refresh the chart with the custom study.

    Image 15

To edit properties of a custom study on a G chart:

  1. Right-click on the chart and select Custom Study Name > Settings to launch the Study Properties popup.
  2. Modify the settings of the custom study.
  3. Select the Display tab to modify the visual properties of the custom study.
  4. Click Update to refresh the chart with the new properties of the custom study.

Publishing a New Version of an Existing Study

  1. In Visual Studio, open the custom study project to be updated.
  2. Modify the code.
  3. Preview the new version of the custom study, following the steps in “Previewing a Custom Study.”
  4. Click the Publish Study icon on the Study Tools toolbar to launch the Publishing Wizard.
  5. Click Next to go to the Publish Study page of the wizard.
  6. Select the study project to publish from the Project list.
  7. Select the same study ID used in the previous version as publishing target.
  8. Click Next to go to the Study Dependencies page of the wizard.
  9. Click Next to go to the Additional Resources page of the wizard.
  10. Click Next to go to the Version Summary page of the wizard.
  11. Enter a version Label for the new version of the custom study, if necessary.
  12. Enter Comments for the custom study, if necessary, and review the Summary.
  13. Click Next to publish the custom study.
  14. Click OK to close the publishing wizard. The new version will be available in approximately 10 minutes.
  15. Reopen a G chart containing this custom study, or add it to a new G chart by following the steps in “Using a Custom Study.”

Advanced Study Programming

This paper is getting too long already to cover all aspects of study programming in Bloomberg Terminal. In the next article we will cover advanced programming topics, such as:

  • Detailed class structure of study SDK
  • Advanced study calculation logic
  • Study updates on real time charts
  • Studies with multiple assemblies
  • Partial trust environment
  • Sharing study with your colleagues

Post your comments and ask for more topics to cover!

Disclaimer

The product names used in this document are for identification purposes only. All trademarks and registered trademarks are the property of their respective owners. The following trademarks may or may not be marked in this document:

Bloomberg Terminal is a trademark or registered trademark of Bloomberg L.P. in United States and/or other countries.

Other company, product, and service names may be trademarks, registered trademarks, or service marks of other owners.

References

http://www.bloomberg.com/
http://www.bloomberg.com/professional/

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer CaseAgile LLC
United States United States
A proven experience in business process migration among all major platforms and environments. Reengineering, Analysis and Redocumentation with SAP® Solution Manager, Oracle® BPA Suite, Software AG (IDS Scheer) ARIS® Platform, Fujitsu Interstage BPM Suite (i-Flow), TIBCO® Business Studio, Casewise® Corporate Modeler Suite, IBM Rational Method Composer and WebSphere® Business Modeler, Metastorm® ProVision, Microsoft® SharePoint® and Visio®, UDDI Webservice Repositories, Sparx® Enterprise Architect, HP Universal CMDB with XML, XPDL, XMI, eEPC, BPMN, UML.

Comments and Discussions

 
QuestionInteresting but ... what exactly can you do with BBG Study SDK? Pin
nanonerd23-Feb-15 19:10
nanonerd23-Feb-15 19:10 
AnswerRe: Interesting but ... what exactly can you do with BBG Study SDK? Pin
Boris Zinchenko23-Feb-15 20:04
Boris Zinchenko23-Feb-15 20:04 
GeneralRe: Interesting but ... what exactly can you do with BBG Study SDK? Pin
nanonerd24-Feb-15 20:39
nanonerd24-Feb-15 20:39 
GeneralRe: Interesting but ... what exactly can you do with BBG Study SDK? Pin
Boris Zinchenko25-Feb-15 0:40
Boris Zinchenko25-Feb-15 0:40 
GeneralRe: Interesting but ... what exactly can you do with BBG Study SDK? Pin
nanonerd24-Feb-15 20:45
nanonerd24-Feb-15 20:45 
GeneralRe: Interesting but ... what exactly can you do with BBG Study SDK? Pin
Boris Zinchenko25-Feb-15 0:51
Boris Zinchenko25-Feb-15 0:51 
GeneralMy vote of 5 Pin
HappyDotNet23-Feb-15 10:59
professionalHappyDotNet23-Feb-15 10:59 
GeneralRe: My vote of 5 Pin
Boris Zinchenko23-Feb-15 18:54
Boris Zinchenko23-Feb-15 18:54 
QuestionExcellent Thank You! Question: Pin
HappyDotNet23-Feb-15 10:58
professionalHappyDotNet23-Feb-15 10:58 
AnswerRe: Excellent Thank You! Question: Pin
Boris Zinchenko23-Feb-15 19:01
Boris Zinchenko23-Feb-15 19:01 
GeneralRe: Excellent Thank You! Question: Pin
HappyDotNet25-Feb-15 9:27
professionalHappyDotNet25-Feb-15 9:27 
GeneralRe: Excellent Thank You! Question: Pin
Boris Zinchenko25-Feb-15 23:46
Boris Zinchenko25-Feb-15 23:46 
GeneralRe: Excellent Thank You! Question: Pin
HappyDotNet26-Feb-15 6:01
professionalHappyDotNet26-Feb-15 6:01 
Generalmy vote of 5 Pin
Southmountain20-Feb-15 4:56
Southmountain20-Feb-15 4:56 
GeneralRe: my vote of 5 Pin
Boris Zinchenko20-Feb-15 5:42
Boris Zinchenko20-Feb-15 5:42 
GeneralRe: my vote of 5 Pin
Southmountain20-Feb-15 9:26
Southmountain20-Feb-15 9:26 
GeneralRe: my vote of 5 Pin
Southmountain21-Feb-15 10:29
Southmountain21-Feb-15 10:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.