Download history stock prices automatically from yahoo finance in python

When you’re going to work with such time series in Python, pandas is indispensable. And here’s the good news: it comes with a historical data downloader for Yahoo: pandas.io.data.DataReader. from pandas.io.data import DataReader from datetime import datetime ibm = DataReader(‘IBM’, ‘yahoo’, datetime(2000, 1, 1), datetime(2012, 1, 1)) print(ibm[‘Adj Close’]) Here’s an example from the pandas … Read more

Yahoo Finance Historical data downloader url is not working

I recently wrote a simple python script to download the history of a single stock. Here an example how to invoke it: python get_quote_history.py –symbol=IBM –from=2017-01-01 –to=2017-05-25 -o IBM.csv This will download IBM historical prices from 2017-01-01 to 2017-05-25 and save them in IBM.csv file. import re import urllib2 import calendar import datetime import getopt … Read more

processing negative number in “accounting” format

If you create an “as.acntngFmt” method for the accounting format, you can read (or perhaps re-read with a text connection using colClasses(“acnt”). setClass(“acntngFmt”) # [1] “acntngFmt” setAs(“character”, “acntngFmt”, function(from) as.numeric( gsub(“\\)”, “”, gsub(“\\(“, “-“, from)))) Input <- “A, B, C (1.76), 1%, 3.50€ 2.00, 2%, 4.77€ 3.000, 3% , €5.68” DF <- read.csv(textConnection(Input), header = … Read more

Decimal vs Double Speed

Floating point arithmetic will almost always be significantly faster because it is supported directly by the hardware. So far almost no widely used hardware supports decimal arithmetic (although this is changing, see comments). Financial applications should always use decimal numbers, the number of horror stories stemming from using floating point in financial applications is endless, … Read more

Stock ticker symbol lookup API [closed]

You can use yahoo’s symbol lookup like so: http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=yahoo&callback=YAHOO.Finance.SymbolSuggest.ssCallback Where query is the company name. You’ll get something like this in return: YAHOO.Finance.SymbolSuggest.ssCallback( { “ResultSet”: { “Query”: “ya”, “Result”: [ { “symbol”: “YHOO”, “name”: “Yahoo! Inc.”, “exch”: “NMS”, “type”: “S”, “exchDisp”: “NASDAQ” }, { “symbol”: “AUY”, “name”: “Yamana Gold, Inc.”, “exch”: “NYQ”, “type”: “S”, “exchDisp”: … Read more