Stocks & Commodities V. : (-5): Predictig Market Data Usig The Kalma Filter, Pt by R. Martielli & N. Rhoads The Future Ad The Filter Predictig Market Data Usig The Kalma Filter Ca the Kalma filter be used to predict future price movemet? I this secod part of this series we aswer this questio. P by Rick Martielli ad Neil Rhoads reviously, we discussed the Kalma filter ad the alpha idicator. This time, we study the accumulatio of profit/loss through the fortue chart. We also backtest the filter ad aalyze the results. The profit/loss o day k may be writte as Part P k = A W k (y k /y k- ) where the quatity i paretheses is the relative price-chage, or retur, o day k, A is the trade amout i dollars, ad W k = if α k > C, W k = - if α k < -C ad W k = zero otherwise (W for wager). Note that W k = correspods to o trade o day k ad so P k = zero as well. Further, ote that A is the same for every trade. For the Ford data, C was foud to be.3, ad Figure shows its P k values, where the trade amout A was set to $. (zero values are ot show). The red poit at November,, represets the trade havig the largest KEN SMITH
MICROSOFT EXCEL Stocks & Commodities V. : (-5): Predictig Market Data Usig The Kalma Filter, Pt by R. Martielli & N. Rhoads Profit/Loss.5..3.. -. -. -.3 -. -.5 7/3/ /3/ /3/9 /3/9 Figure : profit/loss. Here you see the P k values for the Ford data from Figure i Part : T =., C =.3, A =. The red poit at // represets the trade havig the largest profit. profit. The reaso for the large profit ca be see i Figure, Part, where the red poit i Figure correspods to poit i Figure. The predictio of. was owhere ear the actual at.7, but it was i the correct directio, up from.7, resultig i a.3 profit. The fortue sequece is the accumulatio of the P k s:. 3.5 3..5..5..5. Data ad Predictios 3 5 7 9 3 5 Figure : data ad predictios. Here you see the Kalma predictios for a portio of the data from // /9/9 (gree) together with the data. The red poit i Figure correspods to poit i Figure, Part. the scheme was able to capture every price chage i the data that is, correctly predict directio each tradig day. Assumig A=, the sum S = y / y k k k = F = P k = Its last value, F N, is called the last-day fortue (Ldf) ad represets the amout of profit/loss realized at the ed of the simulatio. A graph of F versus day, correspodig to the P k data i Figure, is show i Figure 3. The Ldf is.37 o trades, or about.% average profit per trade. This is, of course, a idealized fortue i which there are o trade commissios, ad trades ca be trasacted at the prescribed buy/sell prices (o slippage). It is used here primarily to evaluate the Kalma filter s ability to predict the directio a stock price will take. The fortue plot is oe idicator of that ability, ad so is the profit ratio, defied as the ratio of umber of profitable trades to total trades. I the Ford simulatio that we discussed i Part, it was.59. The profit ratio ca be roughly visualized as the ratio of umber of poits above the zero lie to total poits. Efficiecy A third way to evaluate the filter is by its efficiecy. Suppose k of the absolute values of the returs represets the maximum amout of profit that ca be realized by day (usig this scheme) ad is called the available profit (AP) o day. The last value, S N, is the total AP i the data, ad the ratio F N /S N is take as the filter s efficiecy. For the Ford example, S N is 3.5 makig the efficiecy., or about %. Figure plots F, the evolutio of the fortue (gree lie) compared with S, the evolutio of the AP, providig a view of the filter s efficiecy over time. The available profit lie has a desirable property, called zero dowside volatility, which we would like to see i the fortue. Hece, we should choose the fortue lie that is earest the AP lie, where the distace D betwee the two lies is calculated as: = k k k = D (S F ) The value of C that miimizes D ca be take as optimal C, which is the method used with the Ford data. The other method, maximizig the Ldf, usually yields the same C.5.5 Fortue -.5 7/3/ /3/ /3/9 /3/9 FIGURE 3: FORTUNE CHART. Here you see the fortue chart for the Ford data i Figure, Part. It is a quadratic model where T =., C =.3, A =, LDF =.37. Fortue ad Available Profit - 7/3/ /3/ /3/9 /3/9 FIGURE : FORTUNE AND AVAILABLE PROFIT. Here you see a compariso of the fortue chart (gree) with the Available Profit (AP) lie for the Ford data.
Stocks & Commodities V. : (-5): Predictig Market Data Usig The Kalma Filter, Pt by R. Martielli & N. Rhoads Symbol Ed Date Last AP T Optimal LDF Efficiecy Profit # Trades Dollar Price C Ratio Retur MECA /3/. 39.5.7..9.9%.9. BUTL 7/3/9. 3.9 3.3. 5.9.%.35.77 3 CTIC //9.5 3.3 -... 5.%.39 7. ANPI 7//9. 7.59... 3.3%.5 9 33.55 5 BJCT 7/3/9. 7. 3.. 5..7%.35 3.7 BPUR 7//9. 5. 3.3..5 9.%.93 5.35 7 TKO 7/9/9. 3.7 3.5.3.53.9%.3 5.3 BBGI 7//9.3.3..3 3.7.%.59 7.3 9 CENX //9.....3.9%.3 3.39 RAE 7/9/9.75.3 3..3.3 9.%.55 3. MDH 7/9/9. 9.5.. 5.53.3%.555 3. ACAS 7/9/9 3.35 9.7...77 9.%.5 9 9.3 3 HEB 7/9/9.3. 3.9.3.59.%.. CLZR //9.3..9..79 9.%.7.9 5 NG 7/9/9 3.9....97.9%.53. GAN 7/9/9.. 3.3..5.%.5.93 7 PSTI //9.3 7....33 7.9%.5.39 BASI 7//9.5.97...9 5.%.7 7 3. 9 PAL 7/9/9.5.93.5..37 7.%.57 7. BCRX 7/3/9 3.....3.%.53.37 TIV 7/9/9.99.53...3 7.9%.9 7 5.9 BANR 7//9.93.3.9.3.5 9.3%.579 95. 3 ABG 7/9/9.99.7.7...9%. 3 3.99 FRG 7/9/9 3. 5.7.5..3.%.55.5 5 CNXT //9.35.... 5.%.55 3.7 BPFH 7/3/9. 3.9..7..9%.5 37 3.9 7 FAC //9. 3.7.5..3.%.5. BPOP 7/3/9. 3..5..9 3.9%.53 73.57 9 F 7/9/9 7. 3.5..3.37.%.59. 3 BELFA 7//9 3.39 3..9. 3.3 3.9%.5 5. 3 CACH //9.3.... 9.%.5 3. 3 PWR //9 5. 9.7...5.%.55.5 33 CMCO //9.3 9..5..9.%.539.95 3 CAKE //9 7.9 9...9.9 5.3%.55 33. 35 GE //9 3.3.3.7..77.%. 57.5 3 CALM //9.7 7.5...9.5%.53 7.7 FIGURE 5: RESULTS OF SIMULATION OF 3 LARGE AP STOCKS. The results for the Ford data are show. The last colum is the average profit/loss i dollars, or dollar retur, based o a trade amout of $,. value, but ot always. Give a choice, we take the largest C value because although the Ldf may be smaller, the fortue lie is smoother. Use that alpha sequece to fid the optimal cutoff C 5 Use the optimal cutoff C to calculate the fortue chart. Backtestig the filter The filter was tested o oe year of daily opes for a large group of selected stocks (all data obtaied from Yahoo Fiace). The simulatios ivolved two optimizatios: The first optimizatio determies the best Kalma trackig parameter ad the secod fids the best alpha cutoff. The simulatio proceeds i five steps: Track oe year of data multiple times to fid the optimal trackig parameter T Track the data oce more usig optimal T 3 Use the resultig Kalma predictios ad their stadard deviatios to fid the alpha sequece α k While we chose the Ford data more or less at radom, the items used i the simulatios were carefully selected to have the largest available profit. We scaed opeig prices for approximately 5, stocks for their oe-year available profit ad may of the stocks havig APs greater tha seve were tracked with the quadratic filter. Oe reaso for choosig opes is that they usually have the largest AP of the four daily prices. A represetative sample of the results is show i Figure 5 sorted by AP. We have icluded the results for the Ford data ad highlighted them. The last colum is the average profit/loss i dollars, or dollar retur, based o a trade amout A = $,. To get a better feel for the ature of these results, we plotted key features separately, startig with the sorted APs i Figure.
Stocks & Commodities V. : (-5): Predictig Market Data Usig The Kalma Filter, Pt by R. Martielli & N. Rhoads AP LDF 5 3 7 3 9 5 3 3 7 3 9 5 3 3 FIGURE : SORTED AVAILABLE PROFITS. Here you see the sorted APs for the 3 items i the table i Figure 5. FIGURE 7: LAST DAY FORTUNE. Here you see the LDFs correspodig to the AP s i Figure. % 5 3 Efficiecy 7 3 9 5 3 3..... Profit Ratio 7 3 9 5 3 3 FIGURE : FILTER EFFICIENCY. Here you see the filter efficiecies correspodig to the AP s i Figure. FIGURE 9: THE FILTER S PROFIT RATIO. Here you see the profit ratios for the 3 test items ad their average lie (red). Figures ad 7 show that filter efficiecy is essetially ucorrelated with AP (actual correlatio is.7). The obvious similarity betwee Figures 7 ad is artificial, because Ldf values are the product of AP ad efficiecy. The average Ldf is.±.9, a fairly wide rage, ad the average efficiecy is.%±9.5%, a slightly arrower rage tha the Ldfs, but both are still depedet o the data. Available profit is a property of the data oly ad is idepedet of the filter. Oly the filter s profit ratio (Figure 9) seems to be (early) idepedet of the data beig tracked; its average is.5±.7. The highest efficiecy is for o. i the table (Basi) at a icredible 5%, with a accompayig Ldf of.9. Data ad fortue for Basi are show i Figures A ad B. Basi has the highest optimal T at., implyig the quadratic model is well-suited to this data. Basi also has the smallest optimal C at., meaig every possible trade is executed. The least efficiet is Pwr at.% with a Ldf of.5, show i Figures A ad B. Its optimal T ad C values, AP, ad profit ratio values are all ear average, suggestig that somethig iheret i this data may be resposible for the filter s relatively poor performace. The stock havig the fewest trades ad best dollar retur is Heb at about $ per trade o trades, show i Figures A ad B. Its fortue chart differs from the others i that there are relatively log periods of time where o trades occur. This is due to the large optimal C value at.3, the largest i the table. Fortue results like Heb are attractive for their miimal dowward movemet. Tcic has the smallest trackig parameter at T =., meaig model oise is about double-data oise, suggestig aother model should be cosidered. Forecastig price movemets The goal here was to determie if a Kalma filter could be exploited to predict the directio of stock price movemets. Based o the Ldfs of the selected stocks i the table, the implemetatio described here is effective i some cases (for example, Basi). The filter s effectiveess is traced to two primary factors: the ature of the data amely, its available profit ad amout of correlatio ad the efficiecy of the filter, which is determied by the filter s model i combiatio with a particular dataset. Oly the profit ratio appears to be (early) idepedet of the data. Selectig oly the top performers from the table would lead to a highly profitable portfolio. Ufortuately, the simulatio preseted here could ever be implemeted i the real world because it requires all of the data o day to determie the optimal C ad T values resposible for the filter s performace. However, applicatio of this scheme to a shorter time period, say the previous quarter or two, should yield the best values for tomorrow s predictio. A simulatio of this scheme must wait for aother article. Rick Martielli ad Neil Rhoads are with Haiku Laboratories. They may be cotacted at ifo@haikulabs.com.
Stocks & Commodities V. : (-5): Predictig Market Data Usig The Kalma Filter, Pt by R. Martielli & N. Rhoads BASI. 5.. 3.... 7// // //9 //9 BASI - 7// // //9 //9 A FIGURE A ad B: DATA AND FORTUNE FOR BASI ENDING JULY, 9. BASI has the highest optimal T at., implyig the quadratic model is well-suited to this data. It also has the smallest optimal C at zero, meaig every possible trade is executed. The AP=7., LDF=.9, profit ratio.7, 7 trades, ad is about $3 per trade. B 3 PWR // 9// // 3//9 PWR.... -. // 9// // 3//9 A FIGURE A ad B: DATA AND FORTUNE FOR PWR ENDING JUNE, 9. The least efficiet is PWR, optimal T=., optimal C=., AP=9.7, LDF=.5, profit ratio.5, trades ad $.5 per trade. Its optimal T ad C values, AP ad profit ratio values are all ear average, suggestig somethig iheret i this data is resposible for the filter s relatively poor performace. B 5 HEB HEB 3.5.5 7/3/ /3/ /3/9 /3/9 7/3/ /3/ /3/9 /3/9 A B FIGURE A ad B: DATA AND FORTUNE FOR HEB ENDING 7/9/9. The stock havig the fewest trades ad best dollar retur is HEB at about $ per trade. Optimal T=3.9, optimal C=.3, AP=.9, LDF=.59, profit ratio., ad is trades ad $. per trade. Suggested readig Martielli, Rick, ad Neil Rhoads []. Predictig Market Data Usig The Kalma Filter, part, Techical Aalysis of Stocks & Commodities, Volume : Jauary. Martielli, Rick []. Haressig The (Mis)Behavior Of Markets, Techical Aalysis of Stocks & Commodities, Volume : Jue. []. Liear Estimatio Ad The Kalma Filter, www. haikulabs.com/liest.htm. S&C