Skip to content

Commit e27b90d

Browse files
authored
Merge pull request #2113 from ericpien/docs
Add Sphinx Documentation
2 parents c012cea + deafc88 commit e27b90d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1613
-500
lines changed

.DS_Store

6 KB
Binary file not shown.

.github/workflows/deploy_doc.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Build and Deploy Sphinx Docs
2+
3+
on:
4+
push:
5+
branches:
6+
- dev-documented
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Check out the repository
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: '3.x'
20+
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install -r requirements.txt
25+
pip install Sphinx==8.0.2 pydata-sphinx-theme==0.15.4 Jinja2==3.1.4 sphinx-copybutton==0.5.2
26+
27+
- name: Build Sphinx documentation
28+
run: |
29+
sphinx-build -b html doc/source doc/_build/html -v
30+
31+
- name: List generated HTML files
32+
run: |
33+
ls -l -R doc/_build/html
34+
35+
- name: Deploy to GitHub Pages
36+
uses: peaceiris/actions-gh-pages@v4
37+
with:
38+
github_token: ${{ secrets.GITHUB_TOKEN }}
39+
publish_branch: documentation
40+
publish_dir: doc/_build/html
41+
destination_dir: docs
42+
enable_jekyll: false

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,10 @@ test.ipynb
1818
env/
1919
venv/
2020
ENV/
21+
22+
# Documentation
23+
/doc/build/
24+
/doc/_build/
25+
/doc/source/reference/api
26+
!yfinance.css
27+
!/doc/source/development/assets/branches.png

README.md

Lines changed: 10 additions & 295 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,16 @@ Yahoo! finance API is intended for personal use only.**
3535

3636
**yfinance** offers a threaded and Pythonic way to download market data from [Yahoo!Ⓡ finance](https://finance.yahoo.com).
3737

38-
→ Check out this [Blog post](https://aroussi.com/#post/python-yahoo-finance) for a detailed tutorial with code examples.
38+
## Main Features
39+
- `Ticker` module: Class for accessing single ticker data.
40+
- `Tickers` module: Class for handling multiple tickers.
41+
- `download` Efficiently download market data for multiple tickers.
42+
- `Sector` and `Industry` modules : Classes for accessing sector and industry information.
43+
- Market Screening: `EquityQuery` and `Screener` to build query and screen the market.
44+
- Caching and Smart Scraping
3945

40-
[Changelog »](https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst)
41-
42-
---
43-
44-
- [Installation](#installation)
45-
- [Quick start](#quick-start)
46-
- [Advanced](#logging)
47-
- [Wiki](https://github.com/ranaroussi/yfinance/wiki)
48-
- [Contribute](#developers-want-to-contribute)
49-
50-
---
46+
## Documentation
47+
The official documentation is available on [ranaroussi.github.io/yfinance](https://ranaroussi.github.io/yfinance/index.html)
5148

5249
## Installation
5350

@@ -67,292 +64,10 @@ $ pip install "yfinance[optional]"
6764

6865
[Required dependencies](./requirements.txt) , [all dependencies](./setup.py#L62).
6966

70-
---
71-
72-
## Quick Start
73-
74-
### The Ticker module
75-
76-
The `Ticker` module, which allows you to access ticker data in a more Pythonic way:
77-
78-
```python
79-
import yfinance as yf
80-
81-
msft = yf.Ticker("MSFT")
82-
83-
# get all stock info
84-
msft.info
85-
86-
# get historical market data
87-
hist = msft.history(period="1mo")
88-
89-
# show meta information about the history (requires history() to be called first)
90-
msft.history_metadata
91-
92-
# show actions (dividends, splits, capital gains)
93-
msft.actions
94-
msft.dividends
95-
msft.splits
96-
msft.capital_gains # only for mutual funds & etfs
97-
98-
# show share count
99-
msft.get_shares_full(start="2022-01-01", end=None)
100-
101-
# show financials:
102-
msft.calendar
103-
msft.sec_filings
104-
# - income statement
105-
msft.income_stmt
106-
msft.quarterly_income_stmt
107-
# - balance sheet
108-
msft.balance_sheet
109-
msft.quarterly_balance_sheet
110-
# - cash flow statement
111-
msft.cashflow
112-
msft.quarterly_cashflow
113-
# see `Ticker.get_income_stmt()` for more options
114-
115-
# show holders
116-
msft.major_holders
117-
msft.institutional_holders
118-
msft.mutualfund_holders
119-
msft.insider_transactions
120-
msft.insider_purchases
121-
msft.insider_roster_holders
122-
123-
msft.sustainability
124-
125-
# show recommendations
126-
msft.recommendations
127-
msft.recommendations_summary
128-
msft.upgrades_downgrades
129-
130-
# show analysts data
131-
msft.analyst_price_targets
132-
msft.earnings_estimate
133-
msft.revenue_estimate
134-
msft.earnings_history
135-
msft.eps_trend
136-
msft.eps_revisions
137-
msft.growth_estimates
138-
139-
# Show future and historic earnings dates, returns at most next 4 quarters and last 8 quarters by default.
140-
# Note: If more are needed use msft.get_earnings_dates(limit=XX) with increased limit argument.
141-
msft.earnings_dates
142-
143-
# show ISIN code - *experimental*
144-
# ISIN = International Securities Identification Number
145-
msft.isin
146-
147-
# show options expirations
148-
msft.options
149-
150-
# show news
151-
msft.news
152-
153-
# get option chain for specific expiration
154-
opt = msft.option_chain('YYYY-MM-DD')
155-
# data available via: opt.calls, opt.puts
156-
```
157-
158-
For tickers that are ETFs/Mutual Funds, `Ticker.funds_data` provides access to fund related data.
159-
160-
Funds' Top Holdings and other data with category average is returned as `pd.DataFrame`.
161-
162-
```python
163-
import yfinance as yf
164-
spy = yf.Ticker('SPY')
165-
data = spy.funds_data
166-
167-
# show fund description
168-
data.description
169-
170-
# show operational information
171-
data.fund_overview
172-
data.fund_operations
173-
174-
# show holdings related information
175-
data.asset_classes
176-
data.top_holdings
177-
data.equity_holdings
178-
data.bond_holdings
179-
data.bond_ratings
180-
data.sector_weightings
181-
```
182-
183-
If you want to use a proxy server for downloading data, use:
184-
185-
```python
186-
import yfinance as yf
187-
188-
msft = yf.Ticker("MSFT")
189-
190-
msft.history(..., proxy="PROXY_SERVER")
191-
msft.get_actions(proxy="PROXY_SERVER")
192-
msft.get_dividends(proxy="PROXY_SERVER")
193-
msft.get_splits(proxy="PROXY_SERVER")
194-
msft.get_capital_gains(proxy="PROXY_SERVER")
195-
msft.get_balance_sheet(proxy="PROXY_SERVER")
196-
msft.get_cashflow(proxy="PROXY_SERVER")
197-
msft.option_chain(..., proxy="PROXY_SERVER")
198-
...
199-
```
200-
201-
### Multiple tickers
202-
203-
To initialize multiple `Ticker` objects, use
204-
205-
```python
206-
import yfinance as yf
207-
208-
tickers = yf.Tickers('msft aapl goog')
209-
210-
# access each ticker using (example)
211-
tickers.tickers['MSFT'].info
212-
tickers.tickers['AAPL'].history(period="1mo")
213-
tickers.tickers['GOOG'].actions
214-
```
215-
216-
To download price history into one table:
217-
218-
```python
219-
import yfinance as yf
220-
data = yf.download("SPY AAPL", period="1mo")
221-
```
222-
223-
#### `yf.download()` and `Ticker.history()` have many options for configuring fetching and processing. [Review the Wiki](https://github.com/ranaroussi/yfinance/wiki) for more options and detail.
224-
225-
### Sector and Industry
226-
227-
The `Sector` and `Industry` modules allow you to access the US market information.
228-
229-
To initialize, use the relevant sector or industry key as below. (Complete mapping of the keys is available in `const.py`.)
230-
231-
```python
232-
import yfinance as yf
67+
The list of changes can be found in the [changelog](https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst)
23368

234-
tech = yf.Sector('technology')
235-
software = yf.Industry('software-infrastructure')
236-
237-
# Common information
238-
tech.key
239-
tech.name
240-
tech.symbol
241-
tech.ticker
242-
tech.overview
243-
tech.top_companies
244-
tech.research_reports
245-
246-
# Sector information
247-
tech.top_etfs
248-
tech.top_mutual_funds
249-
tech.industries
250-
251-
# Industry information
252-
software.sector_key
253-
software.sector_name
254-
software.top_performing_companies
255-
software.top_growth_companies
256-
```
257-
258-
The modules can be chained with Ticker as below.
259-
```python
260-
import yfinance as yf
261-
262-
# Ticker to Sector and Industry
263-
msft = yf.Ticker('MSFT')
264-
tech = yf.Sector(msft.info.get('sectorKey'))
265-
software = yf.Industry(msft.info.get('industryKey'))
266-
267-
# Sector and Industry to Ticker
268-
tech_ticker = tech.ticker
269-
tech_ticker.info
270-
software_ticker = software.ticker
271-
software_ticker.history()
272-
```
273-
274-
### Market Screener
275-
The `Screener` module allows you to screen the market based on specified queries.
276-
277-
#### Query Construction
278-
To create a query, you can use the `EquityQuery` class to construct your filters step by step. The queries support operators: `GT` (greater than), `LT` (less than), `BTWN` (between), `EQ` (equals), and logical operators `AND` and `OR` for combining multiple conditions.
279-
280-
#### Screener
281-
The `Screener` class is used to execute the queries and return the filtered results. You can set a custom body for the screener or use predefined configurations.
282-
283-
<!-- TODO: link to Github Pages for more including list of predefined bodies, supported fields, operands, and sample code -->
284-
285-
### Logging
286-
287-
`yfinance` now uses the `logging` module to handle messages, default behaviour is only print errors. If debugging, use `yf.enable_debug_mode()` to switch logging to debug with custom formatting.
288-
289-
### Smarter scraping
290-
291-
Install the `nospam` packages for smarter scraping using `pip` (see [Installation](#installation)). These packages help cache calls such that Yahoo is not spammed with requests.
292-
293-
To use a custom `requests` session, pass a `session=` argument to
294-
the Ticker constructor. This allows for caching calls to the API as well as a custom way to modify requests via the `User-agent` header.
295-
296-
```python
297-
import requests_cache
298-
session = requests_cache.CachedSession('yfinance.cache')
299-
session.headers['User-agent'] = 'my-program/1.0'
300-
ticker = yf.Ticker('msft', session=session)
301-
# The scraped response will be stored in the cache
302-
ticker.actions
303-
```
304-
305-
Combine `requests_cache` with rate-limiting to avoid triggering Yahoo's rate-limiter/blocker that can corrupt data.
306-
```python
307-
from requests import Session
308-
from requests_cache import CacheMixin, SQLiteCache
309-
from requests_ratelimiter import LimiterMixin, MemoryQueueBucket
310-
from pyrate_limiter import Duration, RequestRate, Limiter
311-
class CachedLimiterSession(CacheMixin, LimiterMixin, Session):
312-
pass
313-
314-
session = CachedLimiterSession(
315-
limiter=Limiter(RequestRate(2, Duration.SECOND*5)), # max 2 requests per 5 seconds
316-
bucket_class=MemoryQueueBucket,
317-
backend=SQLiteCache("yfinance.cache"),
318-
)
319-
```
320-
321-
### Managing Multi-Level Columns
322-
323-
The following answer on Stack Overflow is for [How to deal with
324-
multi-level column names downloaded with
325-
yfinance?](https://stackoverflow.com/questions/63107801)
326-
327-
- `yfinance` returns a `pandas.DataFrame` with multi-level column
328-
names, with a level for the ticker and a level for the stock price
329-
data
330-
- The answer discusses:
331-
- How to correctly read the the multi-level columns after
332-
saving the dataframe to a csv with `pandas.DataFrame.to_csv`
333-
- How to download single or multiple tickers into a single
334-
dataframe with single level column names and a ticker column
335-
336-
### Persistent cache store
337-
338-
To reduce Yahoo, yfinance store some data locally: timezones to localize dates, and cookie. Cache location is:
339-
340-
- Windows = C:/Users/\<USER\>/AppData/Local/py-yfinance
341-
- Linux = /home/\<USER\>/.cache/py-yfinance
342-
- MacOS = /Users/\<USER\>/Library/Caches/py-yfinance
343-
344-
You can direct cache to use a different location with `set_tz_cache_location()`:
345-
346-
```python
347-
import yfinance as yf
348-
yf.set_tz_cache_location("custom/cache/location")
349-
...
350-
```
351-
352-
---
35369

35470
## Developers: want to contribute?
355-
35671
`yfinance` relies on community to investigate bugs and contribute code. Developer guide: https://github.com/ranaroussi/yfinance/discussions/1084
35772

35873
---

doc/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = source
9+
BUILDDIR = build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

0 commit comments

Comments
 (0)