{"id":839,"date":"2022-08-30T15:08:02","date_gmt":"2022-08-30T15:08:02","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/yahoo-option-data-with-r-but-has-error-better-examples-in-python-or-c-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:08:02","modified_gmt":"2022-08-30T15:08:02","slug":"yahoo-option-data-with-r-but-has-error-better-examples-in-python-or-c-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/yahoo-option-data-with-r-but-has-error-better-examples-in-python-or-c-collection-of-common-programming-errors\/","title":{"rendered":"Yahoo Option Data with R but has error? Better examples in Python or C#?-Collection of common programming errors"},"content":{"rendered":"<p>Have you heard of the YQL Console and datatables.org? It provides access to a lot of Yahoo (and other) data tables using REST requests returning XML or JSON objects. There is a nice options table you can easily access using Python&#8217;s urllib. Consider the following example:<\/p>\n<pre><code>&gt;&gt;&gt; import urllib2\n&gt;&gt;&gt; import json\n&gt;&gt;&gt; url='http:\/\/query.yahooapis.com\/v1\/public\/yql?q=SELECT%20*%20FROM%20yahoo.finance.options%20WHERE%20symbol%3D\\\"goog\\\"%20AND%20expiration%3D\\\"2011-08\\\"&amp;format=json&amp;env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&amp;callback='\n&gt;&gt;&gt; req = urllib2.Request(url)\n&gt;&gt;&gt; response = urllib2.urlopen(req)\n&gt;&gt;&gt; result = json.loads(response.read())\n<\/code><\/pre>\n<p>result is an json object containing all options for GOOG with a 2011-08 expiration. If you look closely in the url, you&#8217;ll see the symbol for Google and the expiration date. This can be easily modified programmatically.<\/p>\n<pre><code>&gt;&gt;&gt; result['query']['results']['optionsChain']['option'][0]\n{u'strikePrice': u'400', u'lastPrice': u'110.10', u'vol': u'1', u'type': u'C', u'symbol': u'GOOG110820C00400000', u'openInt': u'9', u'ask': u'90.5', u'changeDir': None, u'bid': u'87', u'change': u'0'}\n&gt;&gt;&gt; result['query']['results']['optionsChain']['option'][10]\n{u'strikePrice': u'490', u'lastPrice': u'21.20', u'vol': u'350', u'type': u'C', u'symbol': u'GOOG110820C00490000', u'openInt': u'56', u'ask': u'21.3', u'changeDir': u'Down', u'bid': u'20.8', u'change': u'-6.9'}\n<\/code><\/pre>\n<p>Note you can also return the results in XML.<\/p>\n<p>Google &#8220;yql consol&#8221;, click on the first link. On the right side, click the link that says &#8220;Show Community Tables&#8221;. Scroll down to Yahoo. Click on yahoo.finance.options. You should be able to figure out the rest \ud83d\ude42<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 22:48:23. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Have you heard of the YQL Console and datatables.org? It provides access to a lot of Yahoo (and other) data tables using REST requests returning XML or JSON objects. There is a nice options table you can easily access using Python&#8217;s urllib. Consider the following example: &gt;&gt;&gt; import urllib2 &gt;&gt;&gt; import json &gt;&gt;&gt; url=&#8217;http:\/\/query.yahooapis.com\/v1\/public\/yql?q=SELECT%20*%20FROM%20yahoo.finance.options%20WHERE%20symbol%3D\\&#8221;goog\\&#8221;%20AND%20expiration%3D\\&#8221;2011-08\\&#8221;&amp;format=json&amp;env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&amp;callback=&#8217; &gt;&gt;&gt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-839","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/839","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=839"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/839\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=839"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=839"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=839"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}