Tuesday, November 23, 2010

Drawing Sparklines with Recorded Future data and Google Chart API

Over at our Google Code site, we have been busy adding content and new examples of how to use the Recorded Future API in custom applications and trading environments.

We often get asked about embedding graphical news analytics data into web applications, so one recent code example is an effort to show how one might do that.

Of course, we already offer the "Embed" feature along with any of our visualizations in the Web User Interface, which allows for easy copy-and-paste of HTML code to include particular timeline or network views in any website. However, sometimes our customers want more control over which data is displayed, how big the embedded object is, etc. For these types of tasks, we turn to our Web Services API.

The code provides a function (generate_sentiment_sparkline) that takes in a ticker, date range, and API token, and returns a PNG image that offers an overview of average sentiment surrounding the ticker in question over the specified time period. At a high level, it works as follows:
  1. Perform a lookup to find the Recorded Future Entity ID for the input ticker.
  2. Perform a query to get two daily sentiment series for the ticker over the specified date range.
  3. Perform some smoothing on that raw data.
  4. Call out to the Google Chart API to generate a chart image (in PNG) for later display.

Here's an example of what the output looks like for Apple over the last 6 months. It is important to note that the visual properties of this chart are completely customizable, and this example is meant to show how to draw two barebones sparklines of media sentiment data:

We won't dig too much into the content of the chart here, but you can see very quickly some interesting visual trends in use of emotive language around Apple over the last few weeks. Of course, we can dig into the data more with our favorite analytic tools, but the ability to quickly generate images like this is potentially very powerful to our users who are interested in monitoring changes in media sentiment around a set of companies.

No comments:

Post a Comment