Re: Newbie Question

*To*: mathgroup at smc.vnet.net*Subject*: [mg32731] Re: [mg32686] Newbie Question*From*: Tomas Garza <tgarza01 at prodigy.net.mx>*Date*: Thu, 7 Feb 2002 05:10:37 -0500 (EST)*References*: <200202060841.DAA02223@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

I think it's a very good idea to throw Fortran away and get started with Mathematica. Your problem may be solved in a number of ways using powerful techniques in Mathematica. I herein propose one which illustrates - I hope - the type of things that may be done. It is not the most elementary way, but I think it's fast (as always, someone will turn up with something better, but that's the way it goes in this MathGroup). The function perctDiffs defined below will take a list of any dimensions and calculate the percent differences between the n-th and the (n-m)-th elements for each column. I only hope (since you said you were using financial time series) that you have no zero elements; otherwise you'd have to slightly modify the routine to avoid divisions by zero. In[1]:= perctDiffs[lst_List, m_Integer] := Module[{n, ker}, ker[n_Integer] := Prepend[Append[Table[0, {n - 1}], 1], -1]; ker[0] = {-1, 1}; (ListCorrelate[ker[m], #1]/Drop[#1, -m] & ) /@ Transpose[lst]] I don't know what sort of lists you have (10^8 is really huge), but I tried the function on a list of six columns by one million rows of random numbers In[2]:= lst = Table[Random[], {1000000}, {6}]; In[3]:= Timing[perctDiffs[lst, 1]; ] Out[3]= {18.35 Second, Null} and obtained the result for adjacent pairs in just over 18 seconds (my PC runs at 800 MHz). It takes approximately the same time to calculate for different lags. Time doesn't seem to be linear with list size, but I guess this has to do with memory usage (?). Tomas Garza Mexico City ----- Original Message ----- From: "Brunsman, Kenneth J" <kbrunsman at ou.edu> To: mathgroup at smc.vnet.net Subject: [mg32731] [mg32686] Newbie Question > Hello Group, > > I can't believe that I am asking this question, but ... I'm tired of Fortran > and find the symbolic part of Mathematica extremely useful. > > I have a list with Dimensions = {10,000, 6} and I need to find the Percent > Difference between items in a column. > > I can parse out the column I need using Take [data [[All, Column #]]] --- no > big deal. So far, so good. > > Now here's the problem --- How do I get % Differences between any of 10,000 > items in that list? I need to take % Differences between adjacent pairs, > i.e. n and n-1, as well as items n and n-m where m can range from 1 to > 10,000. > > Further, I need to make sure that this code runs fast because I'm about to > run this on a data set of 10^8 data points (financial times series). I > could do this standing on my head in Fortran, but I'm bound and determined > to learn Mathematica if it takes the rest of my unnatural life. > > This is my first time attempting list processing and all I'm doing is > screwing up royally. > > Help is greatly appreciated. > > Thanks in advance, > Best to all, > > Ken Brunsman > > University of Oklahoma > Michael F. Price College of Business > Division of Management > 307 W. Brooks, Room 205 > Norman, OK 73019-4006 > > 405.325-5689 >

**References**:**Newbie Question***From:*"Brunsman, Kenneth J" <kbrunsman@ou.edu>