Jul 28, 2009

View stock market with heatmap

There is a heatmap tool which let you view the stock price change at a glance. It can be recreated with Mathematica in several lines of code.

Let’s pull the data by format {“symbol”, price change}

stockdata={#,(FinancialData[#]/FinancialData[#,"Close"]-1)*100 }& /@FinancialData["^DJI","Members"];

Then we need to represent the price change by color: Green means up, Red mean down, and the deeper the color, the bigger the change.

max = Max[Abs[stockdata[[All, 2]]]]; (* max change *)

GraphicsGrid[Partition[Graphics[{If[#[[2]]>=0.0,Blend[{White,Green},Rescale[#[[2]], {0,max}]], Blend[{Red,White}, Rescale[#[[2]],{-max,0}]]], Rectangle[], Black,Text[Style[#[[1]]<>"\n"<>ToString[NumberForm[#[[2]],{3,2}]]<>"%", Medium,Bold], {0.5,0.5}]}] &/@ stockdata, 6 ]]

The key function is if the price change is >0, then rescale the change in range (0, max) and get it’s color in Blend[{White, Green}]; if the price change is <0, then rescale the change in range (-max, 0) and use Blend[{Red, White}] to get the right color.

HeatMap1

In the ascending order:

HeatMap2

We can try other representations, too. For example, we can use the size of disk to represent the change.

HeatMap3

8 comments:

vJD said...

Hey, this is really great - thank you for providing us with the code.

Is there an equally easy way of creating seasonal charts like in

http://www.seasonalcharts.com/

Cheers,
Holger

Ram Katariya said...

Join Epic Research and get free Stock tips, live market news, updates, recommendations and many more to hike your profits.

Esha Agrawal said...
This comment has been removed by a blog administrator.
Beststockstips12 said...

Thanks for this great post.
Short Term Investment Tips

Best Database provider said...

This is very great post and i am inspired with your content.
Best Datawebster Services

Best database provider said...

Thanks for sharing this with us. I found it informative and interesting. Looking forward for more updates.
School info database

Best call center services said...

Thank you so much for sharing a great article. Keep up the great work!
call center for technical support

Karlito said...

Thanks for this info! If you wouldn't mind, how would you recommend creating historic heat map images? For example, I'd love to learn how to create a daily heat map for 20 particular stock symbols (at the close) over the last year (so about 253 images in total). Is this possible and how would you do it? Thanks!