Scraping stock data from a specific market - python

I am currently working on a Python project that checks the Australian market for top gainers, and then buys them once the Canadian stock markets open. I know how to scrape stock data, but am unsure on how to scrape it from a specific market. I am currently using the yfinance library and have checked the documentation for any methods to scrape data from a specific market, but came up empty handed.

you can use the ticker method and specify the market code in the ticker argument.
import yfinance as yf
ticker = yf.Ticker("symbol.AX") # replace "symbol" with the actual ticker symbol
market_data = ticker.info
(.AX is the market code for the Australian stock exchange. Similarly, you can specify the market code for the Canadian stock exchange as .TO to get the stock data from that market.)

Related

Getting historical quarterly finances for a stock using Yahoo finance Python API or another source

I'm trying to get the historical quarterly finances for MSFT and AAPL. While I can get those for the current year by using the following code:
import yfinance as yf
msft = yf.Ticker("MSFT")
msft.quarterly_financials
But I'm not able to get the same for a given period.
Is there a way to get this data from yfinance? If not, is there any other source of data that can help me instead?

Pull historical secutities price from ISIN

How can one pull historical securities (stocks & ETF's) price data in python from just the exchange and ISIN?
All the methods I've seen to do this first map it to the American system of using a code for the exchange and a ticker symbol for the security. There are two problems with that, some securities don't have American ticker symbols and others have the ticker symbol, but there isn't always a code to specify the exchange.
Currently, I am pulling tables from websites such as
https://www.boerse-online.de/etf/boersenplaetze/ishares-uk-property-etf-IE00B1TXLS18
&
https://www.finanzen100.de/zertifikate/sonstige/sonstiges-zertifikat-auf-bloomberg-brent-crude-subindex-total-return-wkn-a1n49p_H1225544336_49507519/
and then looking up the exchange in the table. But there are some issues with this too.
I cannot concatenate a website with the ISIN to get the webpage of the security as the security name is also in the URL, and so I must manually get the URL for each security.
For different securities, sometimes the formatting is different on the same website, so I must have different code for different securities.
Neither website has all exchanges for all securities, so I must manually find the security online first.
These websites don't give historical data as a table, only current price and some additional information.
As ISIN's are the internationally recognized way to identify a security and using it and the exchange seems to be the most obvious, simplest and, in many cases, the only way to specify a security on a particular exchange, I was surprised I couldn't find tools to do this.

US date for Australian data downloaded from Yahoo using pandas web data reader

If i download historical data for Australian stock market using the Pandas web data reader, it shows yesterdays date (this is most probably due to it being the day before (in the US) due to time zone differences.
If i view this data on the Yahoo website is shows the correct Australian Date, The website must convert the date.
import pandas_datareader.data as web
import pandas as pd
yahoo_data = web.DataReader("^AXMJ", 'yahoo')
yahoo_data.tail()
The last date is shown as
2017-11-16
But if you look at the website
https://au.finance.yahoo.com/quote/%5EAXMJ/history?p=%5EAXMJ
the last date is 2017-11-17 which is the real last date.
What is the best way to convert the date? I know i can just shift the dates forward but i think there must be a more elegant way.

Learning to use pandas datareader to plot Yahoo share price but it does not seem right

I'm learning with a O'Reilly course - Introduction to Pandas for Developers.
I plotted a chart using the Yahoo stock price. I have to modify the code given because it's out of date.
Here is the jupyter notebook:
https://nbviewer.jupyter.org/github/jeremy886/pydata-notes/blob/master/ipython-notebooks/Time_Series.ipynb
Please skip to the bottom for the chart.
I compared my chart with the author's and the history prices from Google and found mine is different from the others. (I think the author's is different from the Google's too).
Price Info from Google: https://www.google.com.tw/search?q=yahoo+price&ie=utf-8&oe=utf-8&client=firefox-b&gfe_rd=cr&ei=vHJkWNPuKvOm8weq5qrQBw
At a glance, the pandas_datareader source seems not correct. For example, most of CLOSE prices I got are about $10. Like $12 for yesterday but the price from Google is about $38.
I wonder what is the problem?
Is the pandas_datareader not trustworthy anymore
Or there is some kind of adjustments I don't understand
Or there is a bug in mine/author's code
Thanks and Happy New Year.
You are calling data.DataReader('F', 'yahoo', start, end).
From the source:
def DataReader(name, data_source=None, start=None, end=None,
retry_count=3, pause=0.001, session=None, access_key=None):
"""
Imports data from a number of online sources.
Currently supports Yahoo! Finance, Google Finance, St. Louis FED (FRED),
Kenneth French's data library, and the SEC's EDGAR Index.
Parameters
----------
name : str or list of strs
the name of the dataset. Some data sources (yahoo, google, fred) will
accept a list of names.
data_source: {str, None}
the data source ("yahoo", "yahoo-actions", "yahoo-dividends",
"google", "fred", "ff", or "edgar-index")
The first parameter is the name of the dataset you are interested in, in your case 'F' for Ford.
The data_source parameter is the site that you are sourcing the data from. In your case, 'yahoo'. This is not the same as the stock prices. If you look at Ford's stock price, you will see they compare well to yours.
When in doubt, read the docs. If the docs don't help, read the source - https://github.com/pydata/pandas-datareader

Python Pandas API for Yahoo finance - how to get the bid ask prices and other fields

I want to get the bid and ask price of a stock on Yahoo Finance using python 3.
For open and close prices, I use the pandas DataReader functionality.
Can this API be adjusted to read the bid, ask or any other characteristic of the stock?
from pandas_datareader import data as web
security = web.DataReader("AAPL", "yahoo", start=startDate, end=endDate)
No. The Yahoo API it uses only provides daily, trade-based bars. Finer information is usually licensed in a way that a public, free, legal API won't be providing it.

Categories

Resources