14

There are plenty of sources which provide the historical stock data but they only provide the OHLC fields along with volume and adjusted close. Also a couple of sources I found provide market cap data sets but they're restricted to US stocks. Yahoo Finance provides this data online but there's no option to download it ( or none I am aware of ).

  • Where can I download this data for stocks belonging to various top stock exchanges across countries by using their ticker name ?
  • Is there some way to download it via Yahoo Finance or Google Finance ?

I need data for the last decade or so and hence need some script or API which would do this.

IgorS
  • 5,474
  • 11
  • 31
  • 43
tejaskhot
  • 4,065
  • 7
  • 20
  • 18

3 Answers3

7

Quant SE is better place for questions related to getting financial data:

Shayan Shafiq
  • 1,012
  • 4
  • 12
  • 24
IgorS
  • 5,474
  • 11
  • 31
  • 43
3

As far as gathering data goes, you can check out Quandl (there's a tutorial on using it with R on DataCamp if you're interested).

In addition, Aswath Damodaran's site contains a lot of helpful datasets. Though they aren't updated that frequently, they may still be useful, especially as a benchmark for comparing your own output (from the scripts you will inevitably need to write to calculate the necessary metrics).

And, again, Quant SE is probably a better place to be looking...

Steve S
  • 131
  • 2
1

Something changed on this web site recently. The code directly below works for me.

import csv
import requests
from bs4 import BeautifulSoup

url_base = "https://finviz.com/quote.ashx?t=" tckr = ['MSFT','AAPL','AMZN','FB','GOOG']

i = 1

url_list = [(s, url_base + s) for s in tckr]

headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0'}

with open('C:\Users\ryans\OneDrive\Desktop\AAA.csv', 'w', newline='') as f_out: writer = csv.writer(f_out, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) for t, url in url_list: print(i) i = i + 1 print(t, url) print('Scrapping ticker {}...'.format(t)) soup = BeautifulSoup(requests.get(url, headers=headers).content, 'html.parser') writer.writerow([t]) for row in soup.select('.snapshot-table2 tr'): writer.writerow([td.text for td in row.select('td')])

I deleted the older, non-working, code.

ASH
  • 615
  • 3
  • 9