it is difficult to use the results of these programs unlessyou can interpret the answer. Spreadsheet programs simply require that you indicate thetwo columns that represent the independent and dependent variables. If you simply wantto have time as the independent variable, you can create a column of sequential numbers:1, 2, 3, and so forth. The spreadsheet program will give you a table of statistics includingthe slope, y-intercept, and correlation coefficient (discussed in the next section), and alevel of confidence. Look for a Regression Dialog Box in your spreadsheet program and fol-low the instructions. It is often found under Tools |Numeric Tools| Regression.
Programming Tools
More specific tools are available in strategy testing software, although all of it is restrictedto linear regression. You should expect to find functions that will find the following:
 
TABLE 3-3 Least-Squares Relationship for Corn and Soybeans: | 956~1982
Soybeans ~ x 1,00 2.00 3.00 4.00 5.00- 6.00 7.00Corn y 61 95 1.29 1.63 1.97 231 2.6542 REGRESSION ANALYSIS
 
 
FIGURE 3-3 Scatter diagram of corn, soybean pairs with linear regression solution.
 
Corn price ($/bushel)
 
1.00 2.00 3.00 4.00 5.00 6.00 7.00Soybean price ($/bushe!)
 
Linear regression slope—returns the slope of the straight line given the data series (e.g.,the closing prices) and the period over which the line will be drawn (e.g., 20 days).Linear regression angle—the same as the slope function but the answer is expressedin degrees.
Linear regression value—calculates the slope of the regression line then projects thatline into the future, returning the value of the future point. This requires the user tospecify the data series, the period over which the line will be calculated, and the num-ber of periods into the future. Projecting the value can also be done by finding theslope, s, and performing the following calculation: .
Projected price = starting price + s x (calculation period + projection period)
where the starting price is at the beginning of the calculation period.
LINEAR CORRELATION _
Solving the least-squares equation for the best fit does not mean that the answer can beused. There is always a solution to the least squares method, but there might not be a validlinear relationship between the two sets of data. You may think that two data items affectone another, such as the amount of disposable income and the purchase of television sets,but that might not be the case. The /inear correlation, which uses a value called the coef-ficient of determination r”, or the correlation coefficient, expresses the relationship of thedata on a scale from +1 (perfect positive correlation), to 0 (no relationship between thedata), to —1 (perfect negative correlation), as shown in Figure 3-4.
The correlation coefficient is derived from the deviation, or variation, in the data. Itis isbased on the relationship
Total deviation = explained deviation + unexplained deviation
where total deviation is >, (y,— )), the sum of the individual differences from the average;explained deviation is © (j;—), the sum of the differences between the pointson the fitted line and the average,unexplained deviation is ¥, (),—), the sum of the remaining forecast error terms.Changing this into a ratio gives . -p2=1~ Unexplained deviation _ LO - IP~ total deviation xi ys Di)?LINEAR CORRELATION 4B
 
FIGURE 3-4 Degrees of correlation. (a) Perfect positive linear correlation (r? = 1). (b) Some-what positive linear correlation (r? = .5). (<) and (d) No correlation (r? = 0). (e) Perfect negativelinear correlation (r? = -1).
Price series 2Price serias 2
  
Price series 1 Price series 1(a) (b)
Price series 2Price series 2
  
Price series 1° Price series 1(co) (@)
Price series 2
 
Price series 1(e)
 
The value r? can also be determined using sums already calculated in Table 3-2, by apply-ing the following formula:
NS ay-DxS9)
ee-(E-]fvzr-(2)]
This is easy to calculate; it requires only one sum in addition to the solution of the least-squares problem. The results 7? are interpreted as follows: _
 
reat] A perfect positive linear correlation. The data points are along a straightline going upward to the right (Figure 3-4a).
+1>r?>0 The scattered points become more uniformly distributed about a positiveapproximation line as the value of r? becomes closer to +1 (Figure 3-46).
r=0 No linear correlation exists (Figures 3-4c, 3-4d).
-1<r?<0 The scattered points become more uniformly distributed about a negativeapproximation line as the value of r? becomes closer to —1.
r=-l A perfect negative linear correlation, the line going downward to the right(Figure 3-4e),“4 REGRESSION ANALYSIS
 
Applying the formuld to the corn-soybean data and using the sums from Table 3-2 givesPe (27(202.35) — (106.46) (43.38)? \~ [27(512.95) — (106.46)?] [27 (82.27) — (43.38)"]
_ (5463.45 — 4618,23)?© (13849.65 ~ 1333.73) (2221.29 — 1881.82)
_ 714396.84~ (2515.92)(339.47)= 83.6The results show a strong relationship between the prices of soybeans and corn. Thevalue of r? may also be considered as having accounted for 83.6% of the price relationshipbetween the two products. .
Computer Programs to Find Correlations
Just as with a linear regression, both spreadsheets and trading strategy software have func-tions to return the correlation coefficient with no calculations on your part. Spreadsheetsinclude the correlation as part of the statistics given when the regression tool is used. Ifonly the correlation is needed, for example, to create a correlation matrix, then you can’use the function @corre](coll,col2), which calculates only the correlation coefficient forthe two series in columns 1 and 2, *
The same facility exists in trading strategy software, in which you can use a functionthat specifies the independent series, dependent series, and the time period over whichthe regression will be calculated. For example, you might specify the correlation, R2, oftwo series, datal and data2, over the past 45 days as:
R2 = @correlation(close of datal, close of data2, 45)
Correlation Adjustments When Using a Time Series
Because most price analyses involve the use of two time series, precautions should betaken to avoid a dominant trend that can distort the results. A long-term upward or down-ward trend will overshadow the smaller movements around the trend and exaggerate thecorrelation. The following methods may be used to correct the problem:
1. The deviations from the trend (j; ~ 9) may be correlated.2. The first differences [(},—; -1), (¥i— Js-1) May be correlated.3. The two series may be adjusted for trend.
The simplest method is number 2, which is also very effective. You should expect any com-mercial software to detrend the data before calculating the correlation coefficient; how-ever, it is always a good habit to check it. -
Forecasting Using Regression
A distinct advantage of regression analysis is that it allows the analyst to forecast pricemovement. In the case of the linear regression, the forecast wil! simply be an extension ofthe line. Later in this book, there will be other non/inear solutions that are used to predictmore complex patterns,
The regression forecast is the basis for the probabilistic model, Instead of the corn-soybean relationship, regress the price of soybeans against time using the linear least-Squares method on the data in Table 3-2. The result is
Y= 987 + .221xNONLINEAR APPROXIMATIONS FOR TWO VARIABLES 45
where y is the price of soybeans for the year x. Because the solution substituted the valueof 1 for 1956 and 27 for 1982, the average farm income per bushel of soybeans is forecastas 7.32 in 1985 (x = 30) and 8.38 in 1990 (@ = 35).
Confidence Bands
Regression analysis includes its own measure of accuracy called confidence bands. It isbased on a probability distribution of the errors in the fitted equation and the size of thedata sample. Looking at Figure 3-3, the straight line cannot touch all the points, but itsgoodness of fit may be measured by using the standard deviation of the errors to deter-mine the variance over the total number of data points N. If the actual data points are y;and their corresponding value on the fitted line y,, then
_ (ze?S= VN
where
 
=iReferring to the table of normal distribution (Appendix 1), the 95% level is equivalent to1.96 standard deviations. Then, a confidence band of 95%, placed around the forecast line,is written
95% upper band =, + 1.960
95% lower band = y;— 1.966
Figure 3-5a shows the soybean forecast with a 95% confidence band. The points that areoutside the band are of particular interest and can be interpreted in either of two ways.
1. They are not representative of normal price behavior and are expected to correctthe levels within the bands,
2. The model was not performed on representative or adequate data and should bereestimated.
Figure 3-5 also indicates that the forecast loses accuracy as it is further projected; theforecast is based on the size of the sample used to find the regression coefficients, The moredata included in the original solution, the longer the forecast will maintain its accuracy.
NONLINEAR APPROXIMATIONS FOR TWO VARIABLES
Data points that cannot be related linearly may be approximated using a curve. The gen-eral polynomial form that approximates any curve is
VY = Ay + AX + A,X? +0 + yx”
The first two terms on the right side of the equal sign form the first-order equation for astraight line, By adding the next term @,x?, the shape of the resulting line changes to a par-abolic curve, one with a single, smooth change of direction. The third teem ax? adds aninflection to the pattern. For most price forecasting, the second-order equation, also calledcurvilinear, is sufficient (Figure 3-6). The corn and soybean prices from Table 3-1 will beused to give examples of this and other nonlinear approximations.
The curvilinear form
yrat bet ox
must be solved for the coefficients a, 6, and c using the simultaneous equations46 REGRESSION ANALYSIS
 
nl
FIGURE 3-5 Confidence bands. (a) Soybeans with 95% confidence band. (b), Out-of-sampleforecasts lose confidence.
 
  
“Outliers” ee.
    
Linearregression
95% confidence
 
 
“Confidence band
 
 
Natb> xtcey x2=> y -a> xtb> ted 2 => xya> +b> +e y xt=> xyThe calculations from Table 3-2, including the additional sums for x3, x‘, and x”y, can besubstituted into the preceding equations. The system of simultaneous linear equations canbe solved by the process of matrix elimination,” a technique that should not be performedwithout the help of a computer. An alternate solution can be obtained by continuing withthe already familiar least-squares method.
SECOND-ORDER LEAST SQUARES - _
The concepts of least squares can be extended to the curvilinear (second-order) equationby minimizing the sum of the errors*
s=> (1-4 — bx, - 0x? P
i
? See Appendix 3 for examples of matrix solutions.> RR. Ruckdeschel, BASIC Scientific Subroutines. Vol. 1. (Byte/McGraw-Hill, Peterborough, NH, 1981).SECOND-ORDER LEAST SQUARES 47Se
SS
FIGURE 3-6 Curvilinear (parabolas).
 
Curvilinear (Second Order)
(a, ¢, x> 0) (x> 0)yrat bx+ cx? y=xe
 
First, it is necessary to separate the various intermediate sums before expressing the solu-tion for 4, b, and c.
is a2
Nm
Sey = 5S ew n-P) -
Nim
23 o- -yy
Nin
~ SS; ety (1 —&) x} -
Na
52h 5 (1 - J) @i - %)
Nn
The constant values can then be found by substitution into the following equations
— SepSe2 ~ SyzSextSaxSutet — (Suxt)? -_ SaxSy32 — Six?SaySaxSa2xt — (Sex?)a= —bx%- cx’The procedure is identical to the linear least-squares solution. Fortunately, there are simplecomputer programs that have already been written to solve these problems. Using a methodsimilar to the program found in Appendix 2, the result is
y =.310 + 323% + 002%?48 REGRESSION ANALYSIS
 
Table 3-4 shows the relationship using selected values of x. Notice that this relationship isessentially linear due to the small second-order coefficient. It is not necessary to solve boththe linear and curvilinear models, because the second-order equation can be used in thelinear form when this situation occurs.
Transforming Nonlinear to Linear
‘Two curves that are often used to forecast prices are logarithmic (power) and exponentialrelationships (see Figure 3-7). The exponential, curving up, is used to scale price data thatbecome more volatile at higher levels. Each of these forms can be solved with unique equa-tions; however, both can be easily transformed into linear relationships and solved usingthe method of least squares. This will allow you to fool the computer into solving a non-linear problem using a linear regression tool.
 
 
Logarithmic ExponentialGeneral form y=ax’ y=ae™Transformed Iny=Ina+binx Iny=In a+ bxLinear form ysatbx y=a+bxwhere y=Iny _ wherey=Inya=Ina a=Inax=Inx
 
The significant difference in the transformations is that the value of x is not scaled for theexponential. Taking the original data and performing the appropriate natural log func-tions, In results in the linear form that can be solved using least squares. Selected resultsfrom the computer program in Appendix 2 are shown in Table 3-5.
EVALUATION OF 2-VARIABLE TECHNIQUES
Of the three curve-fitting techniques, the curvilinear and exponential results are very similar,both curving upward and passing through the main cluster of data points at about the sameincline. The log approximation curves downward after passing through the main group ofdata points at about the same place as the other approximations. To evaluate objectivelywhether any of the nonlinear methods are a better fit than the linear approximation, find thestandard deviation of the errors, which gives a statistical measurement of how close the fit-ted line comes to the original data points. The results show that the curvilinear is best; thelogarithmic, which curves downward, is noticeably the worst (see Figure 3-8).
In the case of the corn-soybean relationship, the model with the smallest variancemakes the most sense. Prices will usually remain within the range tested, and the realities ofthe production-price relationship support the selection of the linear (or curvilinear) values.
The use of regression analysis for forecasting the price of soybeans alone has a differ-ent conclusion. Although 27 years were used, the last 10 showed a noticeable increase insoybearr prices. This rising pattern is best fit by the curvilinear and exponential models.However, forecasts using these formulas show pricés continuing to rise at an increasingrate. Had inflation maintained its double-digit rate, these forecasts would still lead to unre-alistically high prices. The logarithmic model, which leveled off after the rise, turned out to
 
TABLE 3-4 Curvilinear Values for Corn and Soybeans ~
Soybeans x 1.00 2.00 3.00 4.00 5.00 6.00 7.00Corn y 63 96 1.29 1.63 1.97 231 2.66
 EVALUATION OF TWO-VARIABLE TECHNIQUES 49
 
a
FIGURE 3-7 Logarithmic and exponential.
 
Logarithmic (Power)(4, b, x, all > 0) (a, x>0, b<0)
 
      
-1<b<0b=-1
 
 
: y=axroriny=Ina+binx(a) (o)Exponential(b> 0) (b<0)y
 
 
 
 
x 0 db xy= ac™*orIn y=in a+ bx@ (a)
 
Source: Cuthbert Daniel and Fred S. Wood, Fitting Equations to Data: Computer Analysis of Multifactor Data, 2nded. (New York: John Wiley & Sons, 1980, pp. 20, 21). Reprinted with permission.
be the best for the actual situation. This shows that the problem of forecasting is morecomplex than this naive solution. The logarithmic model, which showed the worst statisti-cal results, provided the best forecast. Major factors that cause significant price shifts, suchas interest rates, inflation, and the value of the U.S. dollar, must be monitored carefully.The model must be reestimated whenever these factors change. The section “MultivariateApproximations” will discuss this in more detail.
Direct Relationships
The price at which a market trades is limited by the cost of production and dependentupon the prices of other markets that provide a substitute product. Arbitrage is based on
 
TABLE 3-5 Log and Exponential Values for Corn and Soybeans
Soybeans x 1.00 2.00 3.00 4.00 5.00 6.00 7.00Corn (log) y 54 94 130 1.64 1.96 2.26 2.56(exp) y 84 1.02 1.24 1.50 1.83 222 2.70
 50 REGRESSION ANALYSIS
 
 
FIGURE 3-8 Least-squares approximation for soybeans using linear, curvilinear, logarithmic,and exponential models, i
 
14.0012.00
Jf Exponential10.00 Z, Curvilinear
Soybean prices ($/bushel)
 
1956 1960 1965 1970 1975 1980 1985 1990Years 1956-1990 —
 
the ability to.substitute one product for another after transaction costs, which can includecarrying charges, shipping, inspection, and commissions. These relationships are carefullymonitored and arbitrage opportunities are quickly acted upon by traders. This processkeeps futures and cash prices together and prevents the price of gold in New York, Lon-don, and Hong Kong from drifting apart any further than the cost of buying gold in onelocation and delivering it to another. For interest rate markets, strips prevent the largepool of 3-month vehicles, notes, and bonds from offering widely different returns for thesame maturity. The Interbank market provides the same stability for foreign exchange mar-kets, while in agriculture the soybean crush and other processing margins do not stay out-ofline for long. The following nonfinancial markets have close relationships that can befound using regression analysis.
 
 
Products Related Reason -
All crops Relative income for farmers ~~
Grains - Protein substitution for feed
Livestock to feedgrains Feed, cost of production
Livestock Food substitution
Sugar and corn Sweetener substitution
Hogs and pork bellies _ Product dependency -
Silver, gold, and platinum Investor's inflation hedge
Interest rates and financials The stock market and foreign exchange are strongly influenced by changes
in interest rates.MULTIVARIATE APPROXIMATIONS 51
 
MULTIVARIATE APPROXIMATIONS
Regression analysis is most often used in complex economic models to find the combina-tion of two or more independent variables that best explain or forecast prices. A simpleapplication of annual production and distribution of soybeans will determine whetherthese factors are significant in determination of soybean prices. Because the demand forsoybeans and its products is complex, a high correlation should not be expected betweenthe data. However, there is no way of knowing how much impact other factors have on theprices over a long term.
Using the method of least squares, which was employed for a simple linear regression,the new equation is
YH=at+ bx, + Cx,
where y is the resulting price%, is the total production (supply)%, is the total distribution (demand)4@, b, and c are constants to be calculated
As in the linear approximation, the solution to this problem will be found by minimiz-ing the sum of the squares of the errors at each point
s=> O-dy
Substituting ¥ from the previous equation,
'
s=3 Or- @+ bx, + ox)?
=. The solution to the multivariate problem of two independent variables x, and x,requires the following three least-squares equations:
an+bSm +63 m =D ya> mtb Sx +65 x= > xya> mtb mnte> x3 =S xyThe procedure for solving the three simultaneous equations is the same as the curvi-
linear method of coefficient elimination. The sums are calculated in Table 3-6, then substi-tuted into the last three equations:
12.004 + 13.546b + 12.582c = 44.413.554 + 15.9806 + 14.75¢c = 53.28 -12.584 + 14.756 + 13.86c = 49.264
The coefficient matrix solution is*
13.55 15.98 14.74 53.2812.58 14.74 13.86 49.26
( 1.239 1.048 316
(33 13.55 12.58 332]
O- 6798 5451 3.1450 5451 6720 2.714,
* Matrix elimination is the necessary solution to the multivariate problem. Appendix 3 contains the computer pro-rams necessary to perform this operation,52 1 REGRESSION ANALYSIS
 
 
TABLE 3-6 Totals for Multivariate Solution
 
 
 
 
 
 
SoybeansSupply Demandx x xt x} XX xy xyy (Billions) (Billions) (Millions)
1964 I 2.67 -700 677 490 AS8 ATA 1.869 1.8081965 2 2.88 845 738 714 545 624 2.434 2.1251966 3 2.98 928 839 861 -704 779 2.765 2.5001967 4 2.93 976 874 953 764 853 2.860 2.5611968 5 2.69 1.107 -900 1.225 810 996 2.978 2.4211969 6 2.63 1.133 946 1.284 895 1.072 2.980 2.4881970 7 2.63 1.127 1.230 1.270 1.513 1.386 2.964 3.2351971 8 3.08 1.176 °. 1.258 1.383) (1.583 1.479 3.622 3.8751972 9 3.24 1.271 1.202 1.615 1.445 1,528 4.118 3.8941973 10 6.22 1.547 1,283 2.393 1.646 1.985 9.622 7.9801974 a} 6.12 1.215 1.435 1.476 2.059 1.744 7436 8.7821975 12 6.33 1.521 1.200 2.313 1.440 1.825 9.628 7.596= 44.40 13546 12.582 15.977 13.862 14.745 53.276 49.265
1.0 .1429 ~1.5240
0 1 .8018 4.6264
0 0 .2349 -1922
- f1 0 0 -16410 1 0 = 3.9703001 8183,
The results show a = -1.641, 6 = 3.9703, and c = .8183, so that the multiple linearapproximation of the price is
J =-1.641 + 3.9703x, + .81832x, , X
where x, is the production in billions of bushels and x, demand in billions of bushels. Thecoefficient of supply is the principal factor in the determination of price. Had either coefficient of x, or x, been small, it would have indicated a lack of significance. The selectionof which data to try when determining price components is not obvious and may result ina useless answer. In the example, supply-and-demand figures were chosen tq determineprice, but perhaps supply and inflation or demand and inflation would have been better.To find out which sets of data are best, each combination would have to be tested and theresults compared.
- Computer programs are available that perform multivariate analysis and allow a largenumber of items to be input as potentially relevant factors. This program is available in spe-cial mathematical applications packages. You should be warned that the calculation timeincreases quickly as more data relationships are included. Recently, neural networks areused to find solutions to complex problems of supply and demand. Neural nets have theadvantage of not being bound to a solution that fixes the relationships of each of the inputsto a constant value. That-is, the multivariate answer to the soybean problem says that theeffect of supply is always four times greater than the effect of demand; but the neural netsolution may say that, in most years when supply is not threatened by weather, the demandis the primary factor. Neural nets are discussed in Chapter 20.MULTIVARIATE APPROXIMATIONS 53
 
Selecting Data for an S&P Model
The stock market is driven by a healthy economy and by lower interest rates. A good econ-omy means that there is high employment and consumers are actively buying homes,durable goods, and frivolous items. Low interest rates result in more corporate profitabil-ity, which is also influenced by controlled growth and low inflation, both delicate issuesorchestrated by the Central Bank.
To create a robust S&P model, whether using multiple regression or, as we will discusslater, neural networks, it is necessary to select the most meaningful data. The following wassuggested by Lincoln to be used for a 6-month S&P forecast:*
1. SGP prices—the closing prices of the Standard & Poor’s 500 cash index2. Corporate bonds/Treasury bonds—the BAA corporate bond yield divided by the30-year Treasury bond yield, normalized by subtracting the historical mean3. Annual change in the dollar—the 12-month change in the dollar, minus 1, whichmight be based on the Dollar Index traded on the New York Futures Exchange, ora comparable weighting of major currencies4, Annual change in Federal funds rate—the 12-month change i in the Fed funds rate,minus 1. Federal funds rate/discount rate—the Fed funds rate divided by the discount rate;normalized’ by subtracting the historical mean. Money supply—M1 money supply, not seasonally adjusted. Annual Consumer Price Index—the 12-month change inthe CPI, minus 1. Inflation/disinflation index—the annualized 1-month change in the CPI dividedby the 12-month change in the CPI, minus 1 |,. Leading economtc indicators—the 12-month change in the leading economic in-dicators, minus 1 .10. One-month versus 10-month oscillator for the S&P cash index—the difference be-tween the monthly average and the past 10 months, approximately 200 days11. Inflation-adjusted commercial loans—the inflation-adjusted 12-month growth incommercial loans
ONHA wa
\o
Lincoln used 20 years of monthly values to forecast the S&P price 6 months ahead.Some of this data is available on a weekly basis and might be adapted to a shorter timeframe; however, it is unreasonable to think that an accurate daily forecast is possible usingweekly or monthly data. It is also likely that the use of more frequent S&P price data isinconsistent with the monthly statistics and will introduce more noise and make the resultsless reliable.
One element that is missing from the 11 items listed is a volatility adjustment. Therehas been a 600% increase-in the S&P price over 20 years, and volatility is clearly muchhigher. A simple percentage relationship may not describe this change adequately, but maybe used until a better one is substituted. Therefore, those items that become more or lessvolatile as prices move higher and Jower must be corrected using a volatility-normalizingfactor. For example, if we consider the initial yolatility when the S&P was 100 at the begin-ning of the data as normal, then when the price is 800 we will divide the current volatilityby 8 to normalize, or even take the square root if the increase in volatility is nonlinear. Thistype of adjustment would apply to nearly all the items except money supply and the infla-tion/disinflation index. Don’t forget that, where applicable, yields must always be used, notprices.
5 Thomas H. Lincoln, “Time Series Forecasting: ARMAX,” echnical Analysis of Stocks and Commodities (Sep-tember 1991).54 REGRESSION ANALYSIS
 
Generalized MultivariateIn general, the relationship between independent variables