<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SAPessi &#187; Twitter</title>
	<atom:link href="http://sapessi.com/tag/twitter/feed/" rel="self" type="application/rss+xml" />
	<link>http://sapessi.com</link>
	<description>Perfection of means and confusion of aims...</description>
	<lastBuildDate>Wed, 10 Aug 2011 07:36:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>TweetSentiment &#8211; Twitter activity VS market activity</title>
		<link>http://sapessi.com/2009/11/tweetsentiment-twitter-activity-vs-market-activity/</link>
		<comments>http://sapessi.com/2009/11/tweetsentiment-twitter-activity-vs-market-activity/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 18:30:47 +0000</pubDate>
		<dc:creator>Stefano Buliani</dc:creator>
				<category><![CDATA[My Works]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[Finance]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Market]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[StockTwits]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://sapessi.com/?p=307</guid>
		<description><![CDATA[Perhaps I&#8217;m bored. Maybe I&#8217;m just too single. Anyway. A couple of days ago I was looking at StockTwits again and saw a considerable amount of activity. There and then I decided that it would have been pretty cool to check whether there was any correlation between the activity about a stock on Twitter and [...]<!-- Easy AdSense V2.82 -->
<!-- Post[count: 2] -->
<div class="ezAdsense adsense adsense-leadout" style="text-align:center;margin:12px;"><script type="text/javascript"><!--
google_ad_client = "pub-8456780651289352";
/* 468x60, created 11/24/09 */
google_ad_slot = "7140896000";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<!-- Easy AdSense V2.82 -->

]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Ftweetsentiment-twitter-activity-vs-market-activity%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Ftweetsentiment-twitter-activity-vs-market-activity%2F&amp;source=sapessi&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Perhaps I&#8217;m bored. Maybe I&#8217;m just too single.<br />
Anyway. A couple of days ago I was looking at <a href="http://stocktwits.com/" target="_blank">StockTwits</a> again and saw a considerable amount of activity. There and then I decided that it would have been pretty cool to check whether there was any correlation between the activity about a stock on Twitter and the actual trading volume on the market.</p>
<p>I set off to build a small system to do just that. A couple of <a href="http://groovy.codehaus.org/" target="_blank">groovy scripts</a> to collect the data and save it plus some JavaScript and HTML to display it.</p>
<p>So here I am a couple of days later talking about <a href="http://tweetsentiment.info" target="_blank">TweetSentiment</a>.</p>
<p>Collecting the data I needed was pretty trivial thanks to the fact that StockTwits asks all its members to tweet the symbols they are trading preceded by a dollar sign ($).<br />
My first task was to build a list of securities I was interested in. I decided to go to <a href="http://www.covestor.com" target="_blank">Covestor.com</a> and pick the most traded securities list.  Once that list was ready all I had to do was call the <a href="http://apiwiki.twitter.com/Twitter-Search-API-Method:-search" target="_blank">Twitter Search APIs</a> for each stock and store the results.<br />
Groovy made these tasks incredibly simple.</p>
<div class="codesnip-container" >
<div class="java codesnip" style="font-family:monospace;">def output <span class="sy0">=</span> <span class="kw1">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aurl+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">URL</span></a><span class="br0">&#40;</span><span class="st0">&quot;http://search.twitter.com/search.atom?q=${&quot;</span>\$<span class="st0">&quot;+curSecurity.symbol}&amp;amp;rpp=100&quot;</span><span class="br0">&#41;</span>.<span class="me1">getText</span><span class="br0">&#40;</span><span class="br0">&#41;</span></p>
<p>def parsedXml <span class="sy0">=</span> <span class="kw1">new</span> XmlParser<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">parseText</span><span class="br0">&#40;</span>output<span class="br0">&#41;</span></p>
<p>parsedXml.<span class="me1">entry</span>.<span class="me1">each</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> curEntry <span class="sy0">-&amp;</span>gt<span class="sy0">;</span><br />
&#8230;</div>
</div>
<p>I&#8217;m not doing much with the tweets. At the moment I just count them and look for &#8220;buy&#8221; and &#8220;sell&#8221;. I&#8217;m looking into smarter ways of analysing the text and look for positive/negative opinions. If you have any suggestion on this please do leave a comment.</p>
<p>Next in my TODO list was getting some market data. For that I&#8217;m using Yahoo finance asking for previous closing price and average volume for each security. Once again, piece of cake with Groovy. Same thing as before just different URL.<br />
Yahoo finance actually has quite a simple interface to let you grab the data. Check out this page on <a href="http://cliffngan.net/a/13" target="_blank">Cliff&#8217;s Notes</a>.</p>
<p>Now I had all the data I needed. Only thing left was to build some sort of interface to look at it. I wanted to display all of the data on a chart to be able to make sense of it as quickly as possible.<br />
My server (i.e. the machine running this blog) with its puny power could have never handled the traffic I get while generating charts. Therefore what I decided to do is to export all the data in text files (JSON format) and do all of the chart generation with JavaScript.</p>
<p>I browsed the web for a bit looking for charting components for <a href="http://jquery.com/" target="_blank">jQuery</a>. Couldn&#8217;t find anything I was happy with. Not functionality-wise but aesthetically. Or maybe I just felt like playing around with JS for some time &#8211; unfortunately as it often happens with JS I spent the best part of the last 2 days working on it.</p>
<p>I decided to use a library called <a href="http://raphaeljs.com/index.html" target="_blank">Raphaël</a>. This library makes working with vector graphics incredibly simple and the results just look amazing. I know that they are in the process of building a <a href="http://g.raphaeljs.com/" target="_blank">charting library on top of it</a> however&#8230; well I have no excuse now other than I wanted to work with JS.</p>
<p>What I did is build a very simple jQuery component called SAPchart. It only draws line charts but it&#8217;s quite simple and I think the results look pretty good.</p>
<p>You can download the <a href="http://sapessi.com/tweetsentiment/js/SAPchart.js" target="_blank">source here</a>. It requires jQuery, <a href="http://raphaeljs.com/index.html" target="_blank">Raphaël</a>, and <a href="http://sapessi.com/tweetsentiment/js/raphael.path.methods.js" target="_blank">raphael path methods</a>.</p>
<div class="codesnip-container" >
<div class="javascript codesnip" style="font-family:monospace;"><span class="co1">// Constructor. Possible options are:</span><br />
<span class="co1">// showGrid: true</span><br />
<span class="co1">// width: 800</span><br />
<span class="co1">// height: 250</span><br />
<span class="co1">// legendWidth: 200</span><br />
<span class="co1">// showLabels: true</span><br />
<span class="co1">// showDots: true</span><br />
$<span class="br0">&#40;</span><span class="st0">&quot;#holder&quot;</span><span class="br0">&#41;</span>.<span class="me1">SAPchart</span><span class="br0">&#40;</span><span class="br0">&#123;</span>legendWidth<span class="sy0">:</span> 800<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p><span class="co1">// Give the library a list of labels for the x axis</span><br />
$<span class="br0">&#40;</span><span class="st0">&quot;#holder&quot;</span><span class="br0">&#41;</span>.<span class="me1">setLabels</span><span class="br0">&#40;</span>theLabels<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p><span class="co1">// Add to the chart as many series as you want &#8211; provided the length of the series is</span><br />
<span class="co1">// the same of the labels (quite unsophisticated but serves its purpose)</span><br />
<span class="co1">// array of values, unique id of the series, legend name, additional options)</span><br />
$<span class="br0">&#40;</span><span class="st0">&quot;#holder&quot;</span><span class="br0">&#41;</span>.<span class="me1">addSeries</span><span class="br0">&#40;</span>theTweets<span class="sy0">,</span> <span class="st0">&quot;tweet&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Twitter Activity&quot;</span><span class="sy0">,</span> <span class="br0">&#123;</span> <span class="st0">&quot;color&quot;</span><span class="sy0">:</span> <span class="br0">&#91;</span>.6<span class="sy0">,</span> 1<span class="sy0">,</span> .75<span class="br0">&#93;</span> <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
$<span class="br0">&#40;</span><span class="st0">&quot;#holder&quot;</span><span class="br0">&#41;</span>.<span class="me1">addSeries</span><span class="br0">&#40;</span>theVolumes<span class="sy0">,</span> <span class="st0">&quot;volume&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Average Daily Volume&quot;</span><span class="sy0">,</span> <span class="br0">&#123;</span> <span class="st0">&quot;color&quot;</span><span class="sy0">:</span> <span class="br0">&#91;</span>.2<span class="sy0">,</span> 1<span class="sy0">,</span> .75<span class="br0">&#93;</span> <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p><span class="co1">// Draws the chart in your html element</span><br />
$<span class="br0">&#40;</span><span class="st0">&quot;#holder&quot;</span><span class="br0">&#41;</span>.<span class="me1">draw</span><span class="br0">&#40;</span><span class="br0">&#41;</span></p>
<p><span class="co1">// This will return an HTML table containing the legend of all the series you specified</span><br />
<span class="co1">// the boolean parameter tells me whether you want your legend to be horizontal (default vertical)</span><br />
$<span class="br0">&#40;</span><span class="st0">&quot;#holder&quot;</span><span class="br0">&#41;</span>.<span class="me1">getLegend</span><span class="br0">&#40;</span><span class="kw2">true</span><span class="br0">&#41;</span>.<span class="me1">appendTo</span><span class="br0">&#40;</span>$<span class="br0">&#40;</span><span class="st0">&quot;#legend&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>I&#8217;m now wondering whether I should keep working on it and improve it.</p>
<p>Anyway <a href="http://sapessi.com/tweetsentiment/" target="_blank">TweetSentiment is now available here</a>. I&#8217;m planning to keep it running and collecting data for a while. I&#8217;d say you need at least 3/4 months worth of data before you can make any useful observations.</p>
<!-- Easy AdSense V2.82 -->
<!-- Post[count: 3] -->
<div class="ezAdsense adsense adsense-leadout" style="text-align:center;margin:12px;"><script type="text/javascript"><!--
google_ad_client = "pub-8456780651289352";
/* 468x60, created 11/24/09 */
google_ad_slot = "7140896000";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<!-- Easy AdSense V2.82 -->

<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Ftweetsentiment-twitter-activity-vs-market-activity%2F&amp;submitHeadline=TweetSentiment+%26%238211%3B+Twitter+activity+VS+market+activity&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Ftweetsentiment-twitter-activity-vs-market-activity%2F&amp;title=TweetSentiment+%26%238211%3B+Twitter+activity+VS+market+activity" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Ftweetsentiment-twitter-activity-vs-market-activity%2F&amp;title=TweetSentiment+%26%238211%3B+Twitter+activity+VS+market+activity" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Ftweetsentiment-twitter-activity-vs-market-activity%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Ftweetsentiment-twitter-activity-vs-market-activity%2F&amp;title=TweetSentiment+%26%238211%3B+Twitter+activity+VS+market+activity" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Ftweetsentiment-twitter-activity-vs-market-activity%2F&amp;bm_description=TweetSentiment+%26%238211%3B+Twitter+activity+VS+market+activity" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Ftweetsentiment-twitter-activity-vs-market-activity%2F&amp;T=TweetSentiment+%26%238211%3B+Twitter+activity+VS+market+activity" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Ftweetsentiment-twitter-activity-vs-market-activity%2F&amp;title=TweetSentiment+%26%238211%3B+Twitter+activity+VS+market+activity" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Ftweetsentiment-twitter-activity-vs-market-activity%2F&amp;title=TweetSentiment+%26%238211%3B+Twitter+activity+VS+market+activity" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Ftweetsentiment-twitter-activity-vs-market-activity%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Ftweetsentiment-twitter-activity-vs-market-activity%2F" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+TweetSentiment+%26%238211%3B+Twitter+activity+VS+market+activity+@+http%3A%2F%2Fsapessi.com%2F2009%2F11%2Ftweetsentiment-twitter-activity-vs-market-activity%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fsapessi.com%2F2009%2F11%2Ftweetsentiment-twitter-activity-vs-market-activity%2F&amp;t=TweetSentiment+%26%238211%3B+Twitter+activity+VS+market+activity" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://sapessi.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://sapessi.com/2009/11/tweetsentiment-twitter-activity-vs-market-activity/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

