Documentation Center

  • Trial Software
  • Product Updates

Charting Financial Data

Introduction

The following toolbox financial charting functions plot financial data and produce presentation-quality figures quickly and easily.

bolling

Bollinger band chart

bollinger

Time series Bollinger band

candle

Candlestick chart

candle

Time series candle plot

pointfig

Point and figure chart

highlow

High, low, open, close chart

highlow

Time series High-Low plot

movavg

Leading and lagging moving averages chart

These functions work with standard MATLAB® functions that draw axes, control appearance, and add labels and titles. The toolbox also provides a comprehensive set of charting functions that work with financial time series objects, see Chart Technical Indicators.

Here are two plotting examples: a high-low-close chart of sample IBM® stock price data, and a Bollinger band chart of the same data. These examples load data from an external file (ibm.dat), then call the functions using subsets of the data. The MATLAB variable ibm , which is created by loading ibm.dat, is a six-column matrix where each row is a trading day's data and where columns 2, 3, and 4 contain the high, low, and closing prices, respectively.

    Note   The data in ibm.dat is fictional and for illustrative use only.

High-Low-Close Chart Example

First load the data and set up matrix dimensions. load and size are standard MATLAB functions.

load ibm.dat;
[ro, co] = size(ibm);

Open a figure window for the chart. Use the Financial Toolbox™ highlow function to plot high, low, and close prices for the last 50 trading days in the data file.

figure;
highlow(ibm(ro-50:ro,2),ibm(ro-50:ro,3),ibm(ro-50:ro,4),[],'b');

Add labels and title, and set axes with standard MATLAB functions. Use the Financial Toolbox dateaxis function to provide dates for the x-axis ticks.

xlabel('');
ylabel('Price ($)');
title('International Business Machines, 941231 - 950219');
axis([0 50 -inf inf]);
dateaxis('x',6,'31-Dec-1994')

MATLAB produces a figure like this. The plotted data and axes you see may differ. Viewed online, the high-low-close bars are blue.

Bollinger Chart Example

The bolling function in Financial Toolbox software produces a Bollinger band chart using all the closing prices in the same IBM stock price matrix. A Bollinger band chart plots actual data along with three other bands of data. The upper band is two standard deviations above a moving average; the lower band is two standard deviations below that moving average; and the middle band is the moving average itself. This example uses a 15-day moving average.

Assuming the previous IBM data is still loaded, execute the function.

bolling(ibm(:,4), 15, 0);

Specify the axes, labels, and titles. Again, use dateaxis to add the x-axis dates.

axis([0 ro min(ibm(:,4)) max(ibm(:,4))]);
ylabel('Price ($)');
title(['International Business Machines']);
dateaxis('x', 6,'31-Dec-1994')

For help using MATLAB plotting functions, see Create 2-D Graph and Customize Lines in the MATLAB documentation. See the MATLAB documentation for details on the axis, title, xlabel, and ylabel functions.

Was this topic helpful?