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

4 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

KnowYourProfit said...

The blog is very informative and user friendly created by the

webmaster,we would also like to share our experience on this

blog

As such we all had seen 5% correction in bse so this is the

right time for the investors to take positions for handsome

returns,no doubt everyday the market is giving opportunities to
make money provided you are taking timely entry and exit from

the positions

Regards

www.knowyourprofit.com

+91-9871142419

stock market tips said...

I read your post . it was amazing.Your thought process is wonderful.The way you tell about things is awesome. They are inspiring and helpful.Thanks for sharing your information and views.
Regards
stock market tips

lijia said...

Just want to say your article is as amazing. The clearness in your post is simply cool.
-------------
swing trading