19
USING FINANCIAL MARKET DATA APIS IN EXCEL Stephane Dubois CEO & Founder, xignite [email protected] @sdubois

Using Financial Market Data APIs in Microsoft Excel

Embed Size (px)

DESCRIPTION

Provides practical advice and multiple methods on how to pull and manipulate financial data in Microsoft Excel from financial market data APIs.

Citation preview

Page 1: Using Financial Market Data APIs in Microsoft Excel

USING FINANCIAL MARKET DATA APIS IN EXCEL

Stephane DuboisCEO & Founder, xignite

[email protected]@sdubois

Page 2: Using Financial Market Data APIs in Microsoft Excel

AGENDA

• Excel and APIs: A Little History

• From Basic to Cool: Options for Pulling Data Into Excel• Opening a CSV or XML API URL

• Using Data From Web

• Using WebService()

Open a CSV or XML

API URL

Use Data From Web

Use WebService()

Audience

If you have no clue on how to pull data from APIs via Excel, this presentation is for your. But even if you are an advanced user, you may learn a thing or two.

Page 3: Using Financial Market Data APIs in Microsoft Excel

• With 1 billion copies sold, Excel is arguably the most successful business tool in history.

• More of our economy runs on Excel than we would dare to admit.

• Yes it’s not cloud. And yes it’s not shared. But it’s quite flexible.

• It used to be based on 100% manual data entry but with API support, it is no longer the case.

• Excel added APIs in three steps:

• XML support started with 2003

• Data From Web was added in 2007

• WebService() was added in 2013

EXCEL AND APIS: A LITTLE HISTORY

1985

First Spreadsheet with a GUI

1987

First Windows version

1990

Added Toolbar, Drawing, Charts…

1992

Better Mouse, Filling and Shortcuts

1993

Multi-Sheet Workbooks, VBA

1995

32 Bit. Faster and more Stable.

1997

Assistant, Validations and New VBA

1999

Improved Clipboard and Self-Repair

2001

Formula Auditing, Crash Recovery

2003

XML and List Ranges

2007

Ribbon Menu and xlsx

2010

Conditional format, Sparklines, etc.

2013

PowerView, Flashfill and more

Added XML Support

Added Data From Web

Added WebService()

Page 4: Using Financial Market Data APIs in Microsoft Excel

OPEN A CSV FILE

• This is the most basic way to get data in Excel.

• This is akin to opening a regular CSV file.

• It’s kinda lame really.

• Excel opens CSV files natively.

• Most APIs support a CSV output*.

• All you need to do is open the URL in Excel and your are done.

• This works best for APIs that are time series like historical data or large files like master data sets.

* If they don’t, well it probably means they suck.

Did You Know?

Comma-Separated Values is a data

format that pre-dates personal computers by

more than a decade: the IBM Fortran compiler under

OS/360 supported them in 1967.

List-directed ("free form") input/output

was defined in FORTRAN 77 (the 77

means 1977).

List-directed input used commas and/or

spaces for delimiters, so unquoted character

strings could not contain commas or

spaces.

Wikipedia

Page 5: Using Financial Market Data APIs in Microsoft Excel

• Let’s use Xignite’s Global Historical Equity service as an example.

https://www.xignite.com/product/XigniteGlobalHistorical/api/GetGlobalHistoricalQuotesRange/

• And let’s pull a year of adjusted stock prices for GOOG by entering the right criteria.

• Then click the CSV tab option

• Check Download File

• And click on the colorful URL

• Your browser will download the file for you automatically.

OPEN A CSV API URL WITH XIGNITE APIS

Page 6: Using Financial Market Data APIs in Microsoft Excel

• You then click on the download link to open the file.

• You can delete the columns of data you don’t want and otherwise manipulatethe data as you wish.

• But there are a lot of things you cannot do with this approach:

• You can’t refresh the data automatically

• You can’t mix data from one API with data from another API.

• You can’t format the data set and then update it.

• In short, this is pretty lame.

OPEN A CSV API URL WITH XIGNITE APIS

Page 7: Using Financial Market Data APIs in Microsoft Excel

OPEN AN XML API URL

• You can kick things up a notch by pulling the data in XML.

• There are two great advantages of doing so:

This means you get built-in formatting, filtering and sorting.

The data comes up as

an Excel Table.

You can refresh it automatically from within Excel and if the source data changed, so will yours.

The data is automagically bound to the

API.

Page 8: Using Financial Market Data APIs in Microsoft Excel

• Let’s see how we can do this with an Xignite API.

• This time we will use an API that updates continuously, intraday bar data which you can find here:

http://www.xignite.com/product/global-stock-quote-data/api/GetBars/

• We will pull and update intra-day bars as they become available.

• Start by copying the URL of the call*.

OPEN AN XML API URL WITH XIGNITE APIS

* You also need to append your authentication token to the URL in the form of &_token=<yourtoken>.

Page 9: Using Financial Market Data APIs in Microsoft Excel

• Then you can use that API URL and call it from Excel:

• To open the API from Excel you need to:

• Click the File Open menu options.

• Click Other Web Locations and Browse.

• Paste the fully qualified REST URL of your API call in the File Name field.

• Click Open.

• Before opening the file, Excel will throw this little pop-up box at you.

• Choose As an XML table(which is the default)

• Click OK.

OPEN AN XML API URL WITH XIGNITE APIS

Page 10: Using Financial Market Data APIs in Microsoft Excel

• What you get here is quite a bit more interesting than the CSV file.

• The data comes up as a Table.

• This means you get built-in formatting, filtering and sorting and all kinds of other goodies.

• You can also easily delete the columns you don’t want and rename those you want to keep.

• But the best part is that the data is automatically bound to the API.

• You can refresh it automatically.

• Just right click on a cell on the table and chose XML and Refresh XML Data.

• You can even drag and drop the columns you want using XML Source.

OPEN AN XML API URL WITH XIGNITE APIS

Page 11: Using Financial Market Data APIs in Microsoft Excel

• Warning: Code Alert! If coding gives you jitters, skip to the next page!

• And if you care to make this more interesting and are not afraid of a little VBA*, 3 lines of code will suffice to let you dynamically change the parameters of your API and refresh the data:

• Simply create input fields on your worksheet and use them to re-build the URL of your API. For instance, here we are just changing the Symbol.

• Add those 2 lines of code** to link your table to the new URL and refresh it.

• So you can pick any symbol, click the button and pull the data for that symbol.

OPEN AN XML API URL WITH XIGNITE APIS

* Here we assume you know what VBA is, how to pop the developer tab, insert a button, and edit a macro.

** Note that you get the name of your table by right-clicking the table and clicking XML and XML Map Properties

Page 12: Using Financial Market Data APIs in Microsoft Excel

• So using XML is quite cool. But there are limitations. Merely that since you are opening a single URL, you can only integrate data from one source.

• What if you wanted to mix and match things on a worksheet?

• This is where Data From Web comes in.

• Data From Web works just like opening an XML API but you can do it as many times as you want in a spreadsheet.

• First Click From Web on the Data menu.

• Enter the complete URL of your API request (with authentication) in the Address field.

• Click Import.

USING DATA FROM WEB

Page 13: Using Financial Market Data APIs in Microsoft Excel

• By doing Data From Web multiple times, deleting the columns you do not want, and formatting the results, you can create some cool spreadsheets.

• For example the worksheet on the right pulls data from our News, Economic Calendar, Earnings Calendar and IPO Calendar APIs and combines them in a single page.

• It took about 10 minutes to build it. And it updates dynamically.

• To learn more about our available APIs, check here:

https://www.xignite.com/Products/

USING DATA FROM WEB WITH XIGNITE

Page 14: Using Financial Market Data APIs in Microsoft Excel

• So now let’s take it home.

• Most people don’t know that Excel has a WebService() function*.

• It’s quite a powerful little tool.

• It simply pulls the results of an API call in a cell.

• It takes the URL of the REST call as its only input parameter.

• It throws the whole result in the cell so if the output is XML or JSON, it’s actually not so cool:

• This is an XML call result.

• This is a JSON call result.

• Not much you can do with that!

• So you need to get smart using it.

USING WEBSERVICE()

Page 15: Using Financial Market Data APIs in Microsoft Excel

• One way you can get smart using WebService() is by using it with another powerful function: FilterXML()

• FilterXML() lets you call an XML API returning many different fields, filter the field you want and throw it into a cell.

• In this case we will call our real-time Forex API which you can find here:

https://www.xignite.com/forex

• The API returns many fields like Bid, Mid and Ask.

• Here, we can pull the EURUSD Mid quote only by:• Calling WebService() and passing the URL of the API

• Filtering the result by adding “//Bid” as a filter.

• The result is simply thrown into a cell.

• And it recalculates as the sheet recalculates!

USING WEBSERVICE() WITH XIGNITE APIS

Page 16: Using Financial Market Data APIs in Microsoft Excel

• But Xignite APIs make things even simpler!

• You can call any of our APIs using the WebService() function directly.

• All you need to do is pass the proper API URL and you can return a single value in a single cell.

• We call this XigniteOne: One Function, One Cell, One Parameter, One Value.

• Here is an example of such an API call. It works the same for all our APIs:

USING WEBSERVICE() WITH XIGNITE APIS

http://globalquotes.xignite.com/xGlobalQuotes.csv/GetGlobalDelayedQuote?

IdentifierType=Symbol&Identifier=AAPL&_token=mytoken

&_fields=Last&_noheader=y&_notrailer=y

Use a CSV

Extension

The one field you want

to get in your cell.

These two system

parameters.

Using this URL with

WebService()

simply fills out the

cell with value!

Page 17: Using Financial Market Data APIs in Microsoft Excel

• That’s it! Now you can see that WebService() and Data From Web are incredibly powerful tools that let you truly combine the advantages of cloud APIs with the power of Excel.

• Let’s see a couple example of what can be done using those features.

• First, look at the screens on the right. The top is Yahoo!Finance. The bottom is Excel on Xignite APIs. Both update real-time. Can you tell the difference?

USING WEBSERVICE() WITH XIGNITE APIS

Page 18: Using Financial Market Data APIs in Microsoft Excel

• As a final example, the sheet on the right updates and recolors in real-time as exchange rates for more than 150 countries fluctuate in comparison to the US dollar.

• It uses and integrates 6 types of API calls. And it’s all done in Excel using what we showed you and very limited VBA code.

• So sharpen your Excel skills and get started!

PUTTING IT ALL TOGETHER

Page 19: Using Financial Market Data APIs in Microsoft Excel

For additional information click on the links below.

APIS Used in this Presentationhttps://www.xignite.com/Products/ FULL CATALOGhttps://www.xignite.com/product/XigniteGlobalHistorical/ GLOBAL HISTORICAL EQUITY QUOTES APIhttps://www.xignite.com/product/global-stock-quote-data/ GLOBAL DELAYED EQUITY QUOTES APIhttps://www.xignite.com/product/forex/ REALTIME FOREX QUOTES APIhttps://www.xignite.com/product/gold-metal/ REALTIME PRECIOUS METAL PRICING APIhttps://www.xignite.com/product/company-financial-news/ GLOBAL NEWS APIhttps://www.xignite.com/product/XigniteCalendar/ GLOBAL ECONOMIC CALENDAR APIhttps://www.xignite.com/product/XigniteEarningsCalendar/ US EARNINGS CALENDAR APIhttps://www.xignite.com/product/us-stock-IPO-calendar/ US IPOs API

THANK YOU

Questions? Contact Me.

Stephane DuboisCEO & Founder, xignite

[email protected]@sdubois