MathGroup Archive 2008

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

Search the Archive

Re: financial chart with volumes

  • To: mathgroup at
  • Subject: [mg93794] Re: financial chart with volumes
  • From: Andreas <aagas at>
  • Date: Wed, 26 Nov 2008 05:11:50 -0500 (EST)

I think this gets a bit closer to traditional financial charts.


financialChart[company_String, startDate_List] := 
  financialChart[company, startDate, Take[DateList[], 3]];

financialChart[company_String, startDate_List, endDate_List] := 
  Module[{dateForm1, dateForm2, open, high, highest, closing, low, 
    lowest, volume, maxVolume, minVolume, adjustedVolume}, 
   dateForm1 = {"MonthShort", "/", "DayShort"};
   dateForm2 = {"Day", " ", "MonthNameShort", " ", "YearShort"};
   high = FinancialData[company, "High", {startDate, endDate}];
   highest = Max[high[[All, 2]]];
   open = FinancialData[company, "Open", {startDate, endDate}];
   closing = FinancialData[company, {startDate, endDate}];
   low = FinancialData[company, "Low", {startDate, endDate}];
   lowest = Min[low[[All, 2]]];
   volume = FinancialData[company, "Volume", {startDate, endDate}];
   maxVolume = Max[volume[[All, 2]]];
   minVolume = Min[volume[[All, 2]]];
   adjustedVolume = {#[[1]], ((3*lowest - 
            highest) + (highest - lowest) #[[2]]/maxVolume)/2} & /@ 
   DateListPlot[{high, closing, low, adjustedVolume, open}, 
    Filling -> {1 -> {{3}, Black}, 
      4 -> {(3*lowest - highest)/2, {{Thick, Darker[Green, .6]}}}}, 
    GridLines -> Automatic, 
    PlotMarkers -> {"", Style["-  ", Red], "", "", 
      Style["  -", Green]}, 
    FrameLabel -> {None, "Price in Dollars ($)"}, 
    PlotLabel -> 
     FinancialData[company, "Symbol"] <> ", " <> 
      DateString[startDate, dateForm2] <> " - " <> 
      DateString[endDate, dateForm2], ImageSize -> 500]

financialChart["IBM", DatePlus[-50]]

I've just shifted the opening and closing PlotMarkers left and right respectively of the vertical range line. 

Now if someone cleverer than me can come up with a way to scale them proportionately to the number of intervals the chart displays, it would make the chart much more readable when it has hundreds or even thousands of intervals to display.

On another idea, can anyone come up with a way to generate Candlestick charts?  These charts, originating with Japanese traders, show a thin vertical line to indicate the range overlaid by a thicker line or rectangle (sometimes outlined) centered over the thin vertical, which ranges from the open to the high.  Typically such charts show this overlaid line or rectangle for a trading interval with an opening higher than the close as red and the reverse as green or blue.

With Candlestick charts, at a glance one can see  characteristics of a given time series, which typical o,h,l,c charts don't reveal as readily.

  • Prev by Date: Re: Primed Symbols in Mathematica
  • Next by Date: Re: Re: Mathematica 7.0 slow on OS X
  • Previous by thread: Re: financial chart with volumes
  • Next by thread: Re: financial chart with volumes