Documentation Center |
On this page… |
---|
To illustrate some the technical analysis functions, this section uses the IBM^{®} stock price data contained in the supplied file ibm9599.dat. First create a financial time series object from the data using ascii2fts:
ibm = ascii2fts('ibm9599.dat', 1, 3, 2);
The time series data contains the open, close, high, and low prices, as well as the volume traded on each day. The time series dates start on January 3, 1995, and end on April 1, 1999, with some values missing for weekday holidays; weekend dates are not included.
Moving Average Convergence/Divergence (MACD) is an oscillator function used by technical analysts to spot overbought and oversold conditions. Look at the portion of the time series covering the 3-month period between October 1, 1995 and December 31, 1995. At the same time fill any missing values due to holidays within the time period specified:
part_ibm = fillts(ibm('10/01/95::12/31/95'));
Now calculate the MACD, which when plotted produces two lines; the first line is the MACD line itself and the second is the nine-period moving average line:
macd_ibm = macd(part_ibm);
Note When you call macd without giving it a second input argument to specify a particular data series name, it searches for a closing price series named Close (in all combinations of letter cases). |
Plot the MACD lines and the High-Low plot of the IBM stock prices in two separate plots in one window.
subplot(2, 1, 1); plot(macd_ibm); title('MACD of IBM Close Stock Prices, 10/01/95-12/31/95'); datetick('x', 'mm/dd/yy'); subplot(2, 1, 2); highlow(part_ibm); title('IBM Stock Prices, 10/01/95-12/31/95'); datetick('x', 'mm/dd/yy')
The following figure shows the result.
Williams %R is an indicator that measures overbought and oversold levels. The function willpctr is from the stochastics category. All the technical analysis functions can accept a different name for a required data series. If, for example, a function needs the high, low, and closing price series but your time series object does not have the data series names exactly as High, Low, and Close, you can specify the correct names as follows.
wpr = willpctr(tsobj, 14, 'HighName', 'Hi', 'LowName', 'Lo',... 'CloseName', 'Closing')
The function willpctr now assumes that your high price series is named Hi, low price series is named Lo, and closing price series is named Closing.
Since the time series object part_ibm has its data series names identical to the required names, name adjustments are not needed. The input argument to the function is only the name of the time series object itself.
Calculate and plot the Williams %R indicator for IBM stock along with the price range using these commands:
wpctr_ibm = willpctr(part_ibm); subplot(2, 1, 1); plot(wpctr_ibm); title('Williams %R of IBM stock, 10/01/95-12/31/95'); datetick('x', 'mm/dd/yy'); hold on; plot(wpctr_ibm.dates, -80*ones(1, length(wpctr_ibm)),... 'color', [0.5 0 0], 'linewidth', 2) plot(wpctr_ibm.dates, -20*ones(1, length(wpctr_ibm)),... 'color', [0 0.5 0], 'linewidth', 2) subplot(2, 1, 2); highlow(part_ibm); title('IBM Stock Prices, 10/01/95-12/31/95'); datetick('x', 'mm/dd/yy');
The next figure shows the results. The top plot has the Williams %R line plus two lines at -20% and -80%. The bottom plot is the High-Low plot of the IBM stock price for the corresponding time period.
The Relative Strength Index (RSI) is a momentum indicator that measures an equity's price relative to itself and its past performance. The function name is rsindex.
The rsindex function needs a series that contains the closing price of a stock. The default period length for the RSI calculation is 14 periods. This length can be changed by providing a second input argument to the function. Similar to the previous commands, if your closing price series is not named Close, you can provide the correct name.
Calculate and plot the RSI for IBM stock along with the price range using these commands:
rsi_ibm = rsindex(part_ibm); subplot(2, 1, 1); plot(rsi_ibm); title('RSI of IBM stock, 10/01/95-12/31/95'); datetick('x', 'mm/dd/yy'); hold on; plot(rsi_ibm.dates, 30*ones(1, length(wpctr_ibm)),... 'color', [0.5 0 0], 'linewidth', 2) plot(rsi_ibm.dates, 70*ones(1, length(wpctr_ibm)),... 'color',[0 0.5 0], 'linewidth', 2) subplot(2, 1, 2); highlow(part_ibm); title('IBM Stock Prices, 10/01/95-12/31/95'); datetick('x', 'mm/dd/yy');
The next figure shows the result.
On-Balance Volume (OBV) relates volume to price change. The function onbalvol requires you to have the closing price (Close) series as well as the volume traded (Volume) series.
Calculate and plot the OBV for IBM stock along with the price range using these commands:
obv_ibm = onbalvol(part_ibm); subplot(2, 1, 1); plot(obv_ibm); title('On-Balance Volume of IBM Stock, 10/01/95-12/31/95'); datetick('x', 'mm/dd/yy'); subplot(2, 1, 2); highlow(part_ibm); title('IBM Stock Prices, 10/01/95-12/31/95'); datetick('x', 'mm/dd/yy');
The next figure shows the result.