mirror of
https://github.com/bspeice/speice.io
synced 2024-11-14 22:18:10 -05:00
1 line
36 KiB
JavaScript
1 line
36 KiB
JavaScript
|
"use strict";(self.webpackChunkspeice_io=self.webpackChunkspeice_io||[]).push([["4718"],{5960:function(e,n,t){t.r(n),t.d(n,{assets:function(){return d},contentTitle:function(){return o},default:function(){return h},frontMatter:function(){return i},metadata:function(){return a},toc:function(){return l}});var a=t(173),r=t(5893),s=t(65);let i={slug:"2016/06/event-studies-and-earnings-releases",title:"Event studies and earnings releases",date:new Date("2016-06-08T12:00:00.000Z"),authors:["bspeice"],tags:[]},o=void 0,d={authorsImageUrls:[void 0]},l=[{value:"The Market Just Knew",id:"the-market-just-knew",level:2},{value:"Formulating the Question",id:"formulating-the-question",level:2},{value:"Event Studies",id:"event-studies",level:2},{value:"Event Type 1: Trending down over the past N days",id:"event-type-1-trending-down-over-the-past-n-days",level:2},{value:"Event Type 2: Trending up for N days",id:"event-type-2-trending-up-for-n-days",level:2},{value:"Conclusion and Summary",id:"conclusion-and-summary",level:2}];function c(e){let n={code:"code",em:"em",h1:"h1",h2:"h2",img:"img",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,s.a)(),...e.components},{Details:a}=n;return!a&&function(e,n){throw Error("Expected "+(n?"component":"object")+" `"+e+"` to be defined: you likely forgot to import, pass, or provide it.")}("Details",!0),(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.p,{children:"Or, being suspicious of market insiders."}),"\n",(0,r.jsx)(n.h2,{id:"the-market-just-knew",children:"The Market Just Knew"}),"\n",(0,r.jsx)(n.p,{children:"I recently saw two examples of stock charts that have kept me thinking for a while. And now that the semester is complete, I finally have enough time to really look at them and give them the treatment they deserve. The first is good old Apple:"}),"\n",(0,r.jsxs)(a,{children:[(0,r.jsx)("summary",{children:"Code"}),(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-python",children:"from secrets import QUANDL_KEY\nimport matplotlib.pyplot as plt\nfrom matplotlib.dates import date2num\nfrom matplotlib.finance import candlestick_ohlc\nfrom matplotlib.dates import DateFormatter, WeekdayLocator,\\\n DayLocator, MONDAY\nimport quandl\nfrom datetime import datetime\nimport pandas as pd\n%matplotlib inline\n\ndef fetch_ticker(ticker, start, end):\n # Quandl is currently giving me issues with returning\n # the entire dataset and not slicing server-side.\n # So instead, we'll do it client-side!\n q_format = '%Y-%m-%d'\n ticker_data = quandl.get('YAHOO/' + ticker,\n start_date=start.strftime(q_format),\n end_date=end.strftime(q_format),\n authtoken=QUANDL_KEY)\n return ticker_data\n\ndef ohlc_dataframe(data, ax=None):\n # Much of this code re-used from:\n # http://matplotlib.org/examples/pylab_examples/finance_demo.html\n if ax is None:\n f, ax = plt.subplots()\n \n vals = [(date2num(date), *(data.loc[date]))\n for date in data.index]\n candlestick_ohlc(ax, vals)\n \n mondays = WeekdayLocator(MONDAY)\n alldays = DayLocator()\n weekFormatter = DateFormatter('%b %d')\n ax.xaxis.set_major_locator(mondays)\n ax.xaxis.set_minor_locator(alldays)\n ax.xaxis.set_major_formatter(weekFormatter)\n return ax\n"})})]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-python",children:"AAPL = fetch_ticker('AAPL', datetime(2016, 3, 1), datetime(2016, 5, 1))\nax = ohlc_dataframe(AAPL)\nplt.vlines(date2num(datetime(2016, 4, 26, 12)),\n ax.get_ylim()[0], ax.get_ylim()[1],\n color='b',\n label='Earnings Release')\nplt.legend(loc=3)\nplt.title(\"Apple Price 3/1/2016 - 5/1/2016\");\n"})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.img,{alt:"png",src:t(8409).Z+"",width:"372",height:"266"})}),"\n",(0,r.jsx)(n.p,{children:"The second chart is from Facebook:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-python",children:"FB = fetch_ticker('FB', datetime(2016, 3, 1), dat
|