Constructing Stock Data Charts
David Park, djmpark@comcast.net http://home.comcast.net/~djmpark/Mathematica.html
In[1]:=
Needs@"Presentations`Master`"D
Through its online FinancialData sources Mathematica provides a wide range of stock data. Useful graphical representation of this data requires custom graphics. In this notebook I show how to construct a conventional price and volume chart with tooltips.
Price-Volume Financial Chart
Often it is necessary to write custom routines to proceed conveniently with our work. Mathematica is not so much a tool for doing mathematics, but a meta-tool for making the tools to do mathematics. In this case we want to generate a data set where each record contains the date for the period and a sequence of property values of a stock for that date. The FinancialData command will retrieve only a single property value at a time. The following routine retrieves multiple values.
In[2]:=
Out[6]=
882008, 882008, 882008, 882008, 882008, 882008, 882008,
ClearAll@GetFinancialDataD; GetFinancialData::usage = "GetFinancialData@name, 8property1,property2...<,iteratorD will generate a data set where each record will contain 8datelist, propertyvalues..<. The iterator is the standard 8start,end, period< used in FinancialData. This is basically a method of retrieving a number of property values at once."; SyntaxInformation@GetFinancialDataD = 8"ArgumentsPattern" → 8_, 8_, __<, _<<; GetFinancialData@name_String, 8first_String, rest__String<, iterator_ListD := Module@8work, other<, work = Transpose @ FinancialData@name, first, iteratorD; other = FinancialData@name, , iterator, "Value"D & ê@ 8rest<; Transpose@Join@work, otherDD D H∗ Test ∗L GetFinancialData@"^DJI", 8"Open", "Close", "Price", "Volume"<, 8"Oct 1 2008,", "Nov 15 2008", "Week"