back start next


[start] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28] [29] [30] [31] [32] [33] [34] [35] [36] [37] [38] [39] [40] [41] [42] [43] [44] [45] [46] [47] [48] [49] [50] [51] [52] [53] [54] [55] [56] [57] [ 58 ] [59] [60] [61] [62] [63] [64] [65] [66] [67] [68] [69] [70] [71]


58

APPLYING YOUR NUMERICAL FILTER TO STOCK PRICES

There is no shortcut to applying this type of filter to stock price data as in the case of a moving average, ach output data point must be obtained in the same way.

The final step is the calculation of the weights themselves. Only one-half of these and the unique central one must be computed, since the weighting function will be symmetrical about the middle weight.

Compute the first weiglit as follows:

• Look up the cosine of lirXs in your trigonometric tables.

• Subtract from this the cosine of 2v\n -

• Divide the difference by *.

• Make a note of the resulting quantity, identifying it as "A."

• Now look up the cosine of liihx

• Subtract from this the cosine of 2v\ i.

• Divide this difference by 2rr*Xs.

• Make a note of the resulting quantity, identifying it as B."

• Form the difference, A-B.

• Tabulate this as your first weight.

Compute the second weight exactly the same way as the first except for the following differences:

• Multiply 211X3, 2 4, 2nXj, and 2- - , by two before you look up the cosines.

• Multiply 21 and 2n\s by 2* or 2 X 2 before you use them as divisors.

Compute the third weight exactly the same way as the first except for the following differences:

• Multiply 2tr\3,27 4, 2 2, and 2nX by three before you look up the cosines.

• Multiply 27 X« and 2n Xs by 3 or 3 X 3 before you use them as divisors.

Continue in this manner until you are ready for the central weight. Compute it as follows:

• Form the sum, Xj + X4.

• Subtract from this the sum, Xi + Xi-

• The result is the value of the unique central weight.

The next weight after the central weight is identical to the weight just before it.

The second weight after the central one is identical to the second weight before it.

Continue tabulating the remaining weights until you have all ?2. of them written down. Now sum all of the weights youve tabulated and divide the result . Subtract this quantity from each of the previously calculated weights to get new values for each.

The design of your filter is now complete.



namely by summing the products of each weight with the associated stock prices. Proceed as follows:

Tabulate your stock prices in chronological order on a continuous, long strip of paper. Be sure to use the data spacing for which you designed your filter.

Tabulate your filter weights (in the order in ich they were derived) on another long thin strip of paper.

Starting at the beginning of your price data, lay the filter weight strip alongside so that the first filter weight is opposite the first price datum. Mark your filter strip at the center. This mari; will coincide with the price datum to which the first filter output applies.

Now multiply each stock price by the associated (opposite) filter weight to getTt sums. Add these all together. The result is the filter output associated with the central price datum.

Now sUde your filter strip one data space forward. The center of the strip picks out the next price datum to which the filter output applies. Repeat the multiplications and summing process to get the second filter output number.

Repeat the process until you run out of prices. You will note that you have no filter output corresponding to the last ~ stock price data. This is normal, and represents the one-half span lag of the filter. "

Now you may plot both the stock prices and the filter outputs on a single chart in order to see visually what the filter has done for you.

Figure IX-4 is an excellent example of what can be accomplished. In this case. Items 1 through 6 on the chart are the outputs of six different band-pass filters, so designed that their response curves overiapped. As noted in Chapter Nine, over three million computations were required to design and apply the filters which produced this chart. However, the insight gained by the effort into the nature of price motion fully vindicated the work involved. Who knows what you may accomplish as you start to design and use these interesting spectral analysis tools for yourself!

TAKE ADVANTAGE OF CURVE FITTING

Once you obtain results from spectral analysis, you must be able to derive conclusions from them if they are to be useful. One of the most effective techniques to help you here is the process known as curve fitting. You wiU find in the index cross-references to the bibliography as well as to the text of this book that will enable you to pursue the subject as far as you like. As in the case of filters, just enough will be provided here to get you on your way.

Suppose you have designed and applied a numerical filter to stock price data. After plotting the results, you tabulate and plot the resulting periods of the sine-wave output. On your plot of this you notice that period (or frequency) as a function of time oscillates back and forth between narrow bounds, but generally trends either up or down. You would like to establish a straight-line "fit" of this frequency data in such a way that the equation of the resulting straight Une is known. Further, you would like to use some logical criteria to do this based upon the data itself, rather than depend upon sketching such a Une in by hand. The technique you want is called fitting to the data a least-square-error straight line.



FIT YOUR DATA WITH A STRAIGHT LINE

The equation of any straight line is of the form:

F = A +B(t)

"P" is the variable you would plot vertically on a graph, and "t" is the variable you would plot horizontally.

and "B" are constants for a given line. In fact, when known, these describe a particular straight line as uniquely as the quantities period, amplitude, and phase describe a particular sme wave.

Your present problem is to find values of "A " and "S" for a straight hne which comes as close as poble to fitting all of the points on your frequency vs. time plot. For consistency we can rewrite the line equation using the symbols assigned to frequency and time earlier in the chapter:

oj = A+ Bit)

As revnitten, is the angular frequency you are measuring. (Remember that you can measure "period" from the filter output, then convert this to angular frequency.)

The quantity "t" now represents time from any arbitrary "time zero" (usually taken at the start of your data).

To start, arrange your data in two vertical columns, one for the measured firequendes, and the other for the times associated with them as measured from the chosen time zero. It is a good idea right here to make your time units compatible: i.e., if you use radians per year to describe frequency, use fractions of years to describe time, etc.

Now looking across the tabulation, the data appears in pairs-an angular frequency associated with a time in each case. Count the number of such pairs and label the result as "N."

You must now do the following things with this data and jot down the results:

1. Add up all the "w*s" and label the result "C."

2. Add up all the "ts" and label result "D."

3. Square all the "ts" (multiply each one by itself), and add up these values. Label the sum "E."

4. Multiply each "w" by the associated "t" and add up all the products. Label the result "F."

5. Square the sum of aU the "ts" found in Step 2. Label the result "G."

You have now written down six numbers: N, the number of pairs of data points you have, and the numbers labeled C, D, E, F, and G,

The next step is to compute the numerical values of the equation constants desired, A and B. To do this, proceed as foUows:

1. Multiply D by F and subtract the result from the product of and E.

2. Multiply N and together and subtract G from the product. Dhride this result into the result of Step 1.

3. The number you get is the value of the constant "A" that you seek.

4. Now, multiply by D and subtract the result from the product of N and F.

5. Divide the result of Step 4 by the number you used as a divisor in Step 2.

6. The number you get is the value of the constant "B" that you seek.



[start] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28] [29] [30] [31] [32] [33] [34] [35] [36] [37] [38] [39] [40] [41] [42] [43] [44] [45] [46] [47] [48] [49] [50] [51] [52] [53] [54] [55] [56] [57] [ 58 ] [59] [60] [61] [62] [63] [64] [65] [66] [67] [68] [69] [70] [71]