speice.io/assets/js/d085497a.50bafadb.js

1 line
18 KiB
JavaScript
Raw Normal View History

"use strict";(self.webpackChunkspeice_io=self.webpackChunkspeice_io||[]).push([["8704"],{82372:function(e,t,n){n.r(t),n.d(t,{assets:function(){return l},contentTitle:function(){return o},default:function(){return u},frontMatter:function(){return s},metadata:function(){return a},toc:function(){return d}});var a=n(82231),r=n(85893),i=n(50065);let s={slug:"2015/12/testing-cramer",title:"Testing Cramer",date:new Date("2015-12-26T12:00:00.000Z"),authors:["bspeice"],tags:[]},o=void 0,l={authorsImageUrls:[void 0]},d=[{value:"Downloading Futures data from Seeking Alpha",id:"downloading-futures-data-from-seeking-alpha",level:2},{value:"Fetching the Returns data",id:"fetching-the-returns-data",level:2},{value:"Running the Comparison",id:"running-the-comparison",level:2},{value:"The next step - Predicting the close",id:"the-next-step---predicting-the-close",level:2},{value:"Final sentiments",id:"final-sentiments",level:2}];function c(e){let t={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["Pursuant to attending a graduate school studying Financial Engineering, I've been a fan of the ",(0,r.jsx)(t.a,{href:"http://www.cnbc.com/mad-money/",children:"Mad Money"})," TV show featuring the bombastic Jim Cramer. One of the things that he's said is that you shouldn't use the futures to predict where the stock market is going to go. But he says it often enough, I've begun to wonder - who is he trying to convince?"]}),"\n",(0,r.jsx)(t.p,{children:"It makes sense that because futures on things like the S&P 500 are traded continuously, they would price in market information before the stock market opens. So is Cramer right to be convinced that strategies based on the futures are a poor idea? I wanted to test it out."}),"\n",(0,r.jsxs)(t.p,{children:["The first question is where to get the future's data. I've been part of ",(0,r.jsx)(t.a,{href:"http://seekingalpha.com/",children:"Seeking Alpha"})," for a bit, and they publish the ",(0,r.jsx)(t.a,{href:"http://seekingalpha.com/author/wall-street-breakfast?s=wall-street-breakfast",children:"Wall Street Breakfast"})," newsletter which contains daily future's returns as of 6:20 AM EST. I'd be interested in using that data to see if we can actually make some money."]}),"\n",(0,r.jsx)(t.p,{children:"First though, let's get the data:"}),"\n",(0,r.jsx)(t.h2,{id:"downloading-futures-data-from-seeking-alpha",children:"Downloading Futures data from Seeking Alpha"}),"\n",(0,r.jsx)(t.p,{children:"We're going to define two HTML parsing classes - one to get the article URL's from a page, and one to get the actual data from each article."}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-python",children:'class ArticleListParser(HTMLParser):\n """Given a web page with articles on it, parse out the article links"""\n \n articles = []\n \n def handle_starttag(self, tag, attrs):\n #if tag == \'div\' and ("id", "author_articles_wrapper") in attrs:\n # self.fetch_links = True\n if tag == \'a\' and (\'class\', \'dashboard_article_link\') in attrs:\n href = list(filter(lambda x: x[0] == \'href\', attrs))[0][1]\n self.articles.append(href)\n \nbase_url = "http://seekingalpha.com/author/wall-street-breakfast/articles"\narticle_page_urls = [base_url] + [base_url + \'/{}\'.format(i) for i in range(2, 20)]\n\nglobal_articles = []\nfor page in article_page_urls:\n # We need to switch the user agent, as SA blocks the standard requests agent\n articles_html = requests.get(page,\n headers={"User-Agent": "Wget/1.13.4"})\n parser = ArticleListParser()\n parser.feed(articles_html.text)\n global_articles += (parser.articles)\n'})}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-python",children:"class ArticleReturnParser(HTMLParser):\n \"Given an article, parse out the futures returns in it\"\n \n record_font_tags = False\n in_font_tag = False\n counte