Financial Time Series    

Examples

To illustrate some the technical analysis functions, we will make use of the IBM stock price data contained in the supplied file ibm9599.dat. First create a financial time series object from the data using ascii2fts.

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)

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 three-month period between October 1, 1995 to December 31, 1995. At the same time fill any missing values due to holidays within the time period specified.

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.

Plot the MACD lines and the High-Low plot of the IBM stock prices in two separate plots in one window.

Figure 1-4 shows the result.

Figure 1-4: MACD and IBM Stock Prices

William's %R

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:

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 William's %R indicator for IBM along with the price range using these commands.

Figure 1-5 shows the results. The top plot has the William's %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.

Figure 1-5: William's %R and IBM Stock Prices

Relative Strength Index (RSI)

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 along with the price range using these commands.

Figure 1-6 shows the resulting figure.

Figure 1-6: Relative Strength Index (RSI) and IBM Stock Prices

On-Balance Volume (OBV)

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 along with the price range using these commands.

Figure 1-7 shows the result.

Figure 1-7: On-Balance Volume (OBV) and IBM Stock Prices


 Technical Analysis Demonstration Program