SimpleStockData is a simple library providing an API to access basic stock prices based on Yahoo Finances.
Go to file
2024-01-19 20:32:13 +01:00
examples Fixed bad issue with the short program description in the license notices description 2024-01-19 20:32:13 +01:00
LICENSE.md Changed license from Unlicense to GPLv3. New minor release coming. 2024-01-19 20:23:52 +01:00
README.md Removed confusing note in README.md about how to select a specific period of time 2024-01-19 20:27:29 +01:00
SimpleStockData.py Fixed bad issue with the short program description in the license notices description 2024-01-19 20:32:13 +01:00

SimpleStockData

SimpleStockData is a wrapper around the yfinance library providing very easy, high-level access to the yahoo finance data. It does NOT WRAP all features of yfinance, as this would obviously make the whole thing unnecessary. It only provides very basic functionality, which is:

  1. Grap the history of a specific stock
  2. Select a specific period of time
  3. Directly convert the data to another currency¹
  4. CLI and library accessibility

That's pretty much all. And all this just very convenient.


¹ for example, the given stocks are in different currencies, and you want all of your stocks be written to your diagram in the same currency

*** IMPORTANT LEGAL DISCLAIMER ***

Yahoo!, Y!Finance, and Yahoo! finance are registered trademarks of Yahoo, Inc.

SimpleStockData is not affiliated, endorsed, or vetted by Yahoo, Inc. It's an open-source tool that uses Yahoo's publicly available APIs, and is intended for research and educational purposes.

You should refer to Yahoo!'s terms of use (here, here and here) for details on your rights to use the actual data downloaded. Remember - the Yahoo! finance API is intended for personal use only.

[see also]

1. Installation

1.1 Requirements

Python >= 2.7, 3.4+
Pandas >= 1.3.0
Numpy >= 1.16.5
requests >= 2.31
lxml >= 4.9.1
appdirs >= 1.4.4
pytz >=2022.5
frozendict >= 2.3.4
beautifulsoup4 >= 4.11.1
html5lib >= 1.1
peewee >= 3.16.2

Requirements from yfinance [see also]

1.2 Installing these

To get started using the library, the pip packages named in 1.1 have to be installed. To do this, type in the following:

pip3 install numpy pandas yfinance requests lxml

2. Usage

2.1 If used as a Module in Python (via import):

If used as a module, all you have to do to access every share you own is typing this:

from SimpleStockData import SSD
ssd1 = SSD(["EXAMPLE", "ANOTHER TICKER", "..."], "2011-11-11", "2022-02-22", "USD", "Close")
ssd2 = SSD(["EXAMPLE", "ANOTHER TICKER", "..."], "2011-11-11", "2022-02-22", "USD")  # also working
ssd3 = SSD(ticker_list = ["EXAMPLE", "ANOTHER TICKER", "..."], period_start="2011-11-11", 
           period_end="2022-02-22", to_currency="USD", ohcl="Close")  # again working

where...

  • ["EXAMPLE", "ANOTHER TICKER", "..."] is a list of Ticker names (from Yahoo! finance)
  • 2011-11-11 is the start date when accessing price history
  • 2022-02-22 is the end date when accessing price history
  • USD is the currency to convert to, later, when dumping history
  • Close is optional. It specifies which price should be taken per day.
    Valid values are: High, Low, Open, Close

Then you can access the history of the stock just by calling the methods get_info(index, [key] and get_history(index, [interval="1d"], [convert=True].

It's just that easy.


For more details, look into the examples folder at this project's root.

2.2 If used as a CLI:

TODO; also mention the strange but working GBp thing

This feature is currently in progress and will soon be available.

3. Thanks to

  • yfinance - the library used in the background to get stock prices and exchange rates from Yahoo Finance.

  • Pandas - the powerful Python data analysis toolkit

  • Numpy - used in combination with pandas for precise calculations

4. License (Unlicense)

SimpleStockData is licensed under GPLv3, a copy of it can be found in LICENSE.md.