Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Lists and Loops

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113018] Re: Lists and Loops
  • From: "Nasser M. Abbasi" <nma at 12000.org>
  • Date: Mon, 11 Oct 2010 05:16:25 -0400 (EDT)
  • References: <i8s5e7$935$1@smc.vnet.net>
  • Reply-to: nma at 12000.org

On 10/10/2010 3:44 AM, Michaell Taylor wrote:
> I am new to Mathematica and am probably too stuck in other languages, but
> but having a hard time with a simple listing building looping structure.
>   The code below is supposed to cycle through a list of stock tickers.  For
> each ticker it builds a list of certain financial data elements and adds
> each element to a list.  When the list is complete (all financial elements
> obtained), the list is written to a Mysql database.  The internal looping
> structure seems to work fine.  That is, if I execute the internal loop for a
> single ticker, the results are added to the database as planned.
>
> However, the outer structure causes a problem in that the list continues to
> grow with each ticker.  The "mydata={}" line was meant to "reset" the list,
> but doesn't seem to be performing as expected.
>
>   tickers = {"VNO", "AMB"}
>
> fprop = {"Average50Day", "Average200Day"}
>
> Do[
>   mydata = {t}
>     Do[
>      mydata = Append[mydata, FinancialData[t, i]],
>      {i, fprop}]
>     Print[mydata]
>     SQLInsert[connt, "reit" , {"ticker", "first", "second"}, mydata]
>     {t, tickers}]
>
>
> My error, no doubt is obvious to some. Any guidance would be greatly
> appreciated.
>
>

OMG! , you are using loops in Mathematica  :)

If I understand what you want, how about this:

tickers = {"GE", "IBM", "GOOG"};
fprop = {"Average50Day", "Average200Day"};

Outer[FinancialData, tickers, fprop];
data = Join[Transpose[{tickers}], %, 2];

TableForm[data]

GE	15.8406	16.5046
IBM	130.134	128.736
GOOG	491.243	502.399


--Nasser



  • Prev by Date: Re: What is the ESC sequence for the "Matching Double Brakets"? From
  • Next by Date: Efficient Histogram Algorithm?
  • Previous by thread: Lists and Loops
  • Next by thread: Re: Lists and Loops