finagg.yfinance.feat package
Module contents
Features from Yahoo! Finance sources.
- finagg.yfinance.feat.daily
The most popular way for accessing
finagg.yfinance.feat.Daily
.
- finagg.yfinance.feat.prices
The most popular way for accessing
finagg.yfinance.feat.Prices
.
- class finagg.yfinance.feat.Daily[source]
Bases:
object
Methods for gathering daily stock data features from Yahoo! finance.
The module variable
finagg.yfinance.feat.daily
is an instance of this feature set implementation and is the most popular interface for calling feature methods.Examples
It doesn’t matter which data source you use to gather features. They all return equivalent dataframes.
>>> df1 = finagg.yfinance.feat.daily.from_api("AAPL").head(5) >>> df2 = finagg.yfinance.feat.daily.from_raw("AAPL").head(5) >>> df3 = finagg.yfinance.feat.daily.from_refined("AAPL").head(5) >>> pd.testing.assert_frame_equal(df1, df2, rtol=1e-4) >>> pd.testing.assert_frame_equal(df1, df3, rtol=1e-4)
- classmethod from_api(ticker: str, /, *, start: None | str = None, end: None | str = None) DataFrame [source]
Get daily features directly from
finagg.yfinance.api.get()
.- Parameters:
ticker – Company ticker.
start – The start date of the stock history. Defaults to the first recorded date.
end – The end date of the stock history. Defaults to the last recorded date.
- Returns:
Daily stock price dataframe sorted by date.
Examples
>>> finagg.yfinance.feat.daily.from_api("AAPL").head(5) LOG_CHANGE(open) LOG_CHANGE(high) LOG_CHANGE(low) LOG_CHANGE(close) ... date ... 1980-12-15 -0.049005 -0.053343 -0.053581 -0.053581 ... 1980-12-16 -0.075870 -0.075870 -0.076231 -0.076231 ... 1980-12-17 0.019512 0.024331 0.024450 0.024450 ... 1980-12-18 0.028580 0.028445 0.028580 0.028580 ... 1980-12-19 0.059239 0.058970 0.059239 0.059239 ...
- classmethod from_raw(ticker: str, /, *, start: None | str = None, end: None | str = None, engine: None | Engine = None) DataFrame [source]
Get daily features from local SQL tables.
- Parameters:
ticker – Company ticker.
start – The start date of the stock history. Defaults to the first recorded date.
end – The end date of the stock history. Defaults to the last recorded date.
engine – Raw store database engine. Defaults to the engine at
finagg.backend.engine
.
- Returns:
Daily stock price dataframe sorted by date.
- Raises:
NoResultFound – If there are no rows for
ticker
in the raw SQL table.
Examples
>>> finagg.yfinance.feat.daily.from_raw("AAPL").head(5) LOG_CHANGE(open) LOG_CHANGE(high) LOG_CHANGE(low) LOG_CHANGE(close) ... date ... 1980-12-15 -0.049005 -0.053343 -0.053581 -0.053581 ... 1980-12-16 -0.075870 -0.075870 -0.076231 -0.076231 ... 1980-12-17 0.019512 0.024331 0.024450 0.024450 ... 1980-12-18 0.028580 0.028445 0.028580 0.028580 ... 1980-12-19 0.059239 0.058970 0.059239 0.059239 ...
- classmethod from_refined(ticker: str, /, *, start: None | str = None, end: None | str = None, engine: None | Engine = None) DataFrame [source]
Get features from the feature-dedicated local SQL tables.
This is the preferred method for accessing features for offline analysis (assuming data in the local SQL tables is installed and is up-to-date).
- Parameters:
ticker – Company ticker.
start – The start date of the observation period. Defaults to the first recorded date.
end – The end date of the observation period. Defaults to the last recorded date.
engine – Feature store database engine. Defaults to the engine at
finagg.backend.engine
.
- Returns:
Daily stock price dataframe sorted by date.
- Raises:
NoResultFound – If there are no rows for
ticker
in the refined SQL table.
Examples
>>> finagg.yfinance.feat.daily.from_refined("AAPL").head(5) LOG_CHANGE(open) LOG_CHANGE(high) LOG_CHANGE(low) LOG_CHANGE(close) ... date ... 1980-12-15 -0.049005 -0.053343 -0.053581 -0.053581 ... 1980-12-16 -0.075870 -0.075870 -0.076231 -0.076231 ... 1980-12-17 0.019512 0.024331 0.024450 0.024450 ... 1980-12-18 0.028580 0.028445 0.028580 0.028580 ... 1980-12-19 0.059239 0.058970 0.059239 0.059239 ...
- classmethod get_candidate_ticker_set(lb: int = 1, *, start: None | str = None, end: None | str = None, engine: None | Engine = None) set[str] [source]
Get all unique tickers in the raw SQL table that MAY BE ELIGIBLE to be in the feature’s refined SQL table.
- Parameters:
lb – Minimum number of rows required to include a ticker in the returned set.
start – The start date of the observation period to include when searching for tickers. Defaults to the first recorded date.
end – The end date of the observation period to include when searching for tickers. Defaults to the last recorded date.
engine – Feature store database engine. Defaults to the engine at
finagg.backend.engine
.
- Returns:
All unique tickers that may be valid for creating daily features that also have at least
lb
rows used for constructing the features.
Examples
>>> "AAPL" in finagg.yfinance.feat.daily.get_candidate_ticker_set() True
- classmethod get_ticker_set(lb: int = 1, *, start: None | str = None, end: None | str = None, engine: None | Engine = None) set[str] [source]
Get all unique tickers in the feature’s SQL table.
- Parameters:
lb – Minimum number of rows required to include a ticker in the returned set.
start – The start date of the observation period to include when searching for tickers. Defaults to the first recorded date.
end – The end date of the observation period to include when searching for tickers. Defaults to the last recorded date.
engine – Feature store database engine. Defaults to the engine at
finagg.backend.engine
.
- Returns:
All unique tickers that contain all the columns for creating daily features that also have at least
lb
rows.
Examples
>>> "AAPL" in finagg.yfinance.feat.daily.get_ticker_set() True
- classmethod install(tickers: None | set[str] = None, *, processes: int = 3, engine: None | Engine = None, recreate_tables: bool = False) int [source]
Install data associated with
tickers
by pulling data from the raw SQL tables, transforming them into daily features, and then writing to the refined daily SQL table.Tables associated with this method are created if they don’t already exist.
- Parameters:
tickers – Set of tickers to install features for. Defaults to all the tickers from
finagg.indices.api.get_ticker_set()
.processes – Number of background processes to run in parallel when processing
tickers
.engine – Feature store database engine. Defaults to the engine at
finagg.backend.engine
.recreate_tables – Whether to drop and recreate tables, wiping all previously installed data.
- Returns:
Number of rows written to the feature’s refined SQL table.
- classmethod to_refined(ticker: str, df: DataFrame, /, *, engine: None | Engine = None) int [source]
Write the given dataframe to the refined feature table while using the ticker
ticker
.- Parameters:
ticker – Company ticker.
df – Dataframe to store as rows in a local SQL table.
engine – Feature store database engine. Defaults to the engine at
finagg.backend.engine
.
- Returns:
Number of rows written to the SQL table.
- classmethod update(tickers: None | set[str] = None, *, processes: int = 3, engine: None | Engine = None) int [source]
Update data associated with
tickers
by pulling data from the raw SQL tables, transforming them into daily features, and then writing to the refined daily SQL table.- Parameters:
tickers – Set of tickers to install features for. Defaults to all the tickers from
finagg.yfinance.feat.Daily.get_ticker_set()
.processes – Number of background processes to run in parallel when processing
tickers
.engine – Feature store database engine. Defaults to the engine at
finagg.backend.engine
.
- Returns:
Number of rows written to the feature’s refined SQL table.
- Raises:
NoSuchTableError – If the table associated with this feature set update does not exist.
- class finagg.yfinance.feat.Prices[source]
Bases:
object
Get a single company’s daily stock history as-is from raw Yahoo! Finance data.
The module variable
finagg.yfinance.feat.prices
is an instance of this feature set implementation and is the most popular interface for calling feature methods.- classmethod from_raw(ticker: str, /, *, start: None | str = None, end: None | str = None, engine: None | Engine = None) DataFrame [source]
Get a single company’s daily stock history as-is from raw Yahoo! Finance SQL tables.
- Parameters:
ticker – Company ticker.
start – The start date of the observation period. Defaults to the first recorded date.
end – The end date of the observation period. Defaults to the last recorded date.
engine – Feature store database engine. Defaults to the engine at
finagg.backend.engine
.
- Returns:
A dataframe containing the company’s daily stock history across the specified period.
- Raises:
NoResultFound – If there are no rows for
ticker
in the raw SQL table.
Examples
>>> finagg.yfinance.feat.prices.from_raw("AAPL").head(5) open high low close volume date 1980-12-12 0.0997 0.1002 0.0997 0.0997 4.6903e+08 1980-12-15 0.0950 0.0950 0.0945 0.0945 1.7588e+08 1980-12-16 0.0880 0.0880 0.0876 0.0876 1.0573e+08 1980-12-17 0.0897 0.0902 0.0897 0.0897 8.6442e+07 1980-12-18 0.0924 0.0928 0.0924 0.0924 7.3450e+07
- classmethod get_ticker_set(lb: int = 1, *, start: None | str = None, end: None | str = None, engine: None | Engine = None) set[str] [source]
Get all unique ticker symbols in the raw SQL tables that have at least
lb
rows.This method is convenient for accessing the tickers that have raw SQL data associated with them so the data associated with those tickers can be further refined. A common pattern is to use this method and other
get_ticker_set
methods (such as those found infinagg.yfinance.feat
) to determine which tickers are missing data from other tables or features.- Parameters:
lb – Lower bound number of rows that a company must have for its ticker to be included in the set returned by this method.
start – The start date of the observation period to include when searching for tickers. Defaults to the first recorded date.
end – The end date of the observation period to include when searching for tickers. Defaults to the last recorded date.
engine – Feature store database engine. Defaults to the engine at
finagg.backend.engine
.
Examples
>>> "AAPL" in finagg.yfinance.feat.prices.get_ticker_set() True
- classmethod install(tickers: None | set[str] = None, *, processes: int = 3, engine: None | Engine = None, recreate_tables: bool = False) int [source]
Install data associated with
tickers
by pulling data from the API, and then writing the data to the raw prices SQL table.Tables associated with this method are created if they don’t already exist.
- Parameters:
tickers – Set of tickers to install features for. Defaults to all the tickers from
finagg.indices.api.get_ticker_set()
.processes – Number of background processes to use when installing data.
engine – Feature store database engine. Defaults to the engine at
finagg.backend.engine
.recreate_tables – Whether to drop and recreate tables, wiping all previously installed data.
- Returns:
Number of rows written to the feature’s raw SQL table.
- classmethod to_raw(df: DataFrame, /, *, engine: None | Engine = None) int [source]
Write the given dataframe to the raw feature table.
- Parameters:
df – Dataframe to store as rows in a local SQL table
engine – Feature store database engine. Defaults to the engine at
finagg.backend.engine
.
- Returns:
Number of rows written to the SQL table.
- classmethod update(tickers: None | set[str] = None, *, processes: int = 3, engine: None | Engine = None) int [source]
Update data associated with
tickers
by pulling data from the API, and then writing the data to the raw prices SQL table.- Parameters:
tickers – Set of tickers to install features for. Defaults to all the tickers from
finagg.yfinance.feat.Prices.get_ticker_set()
.processes – Number of background processes to use when installing data.
engine – Feature store database engine. Defaults to the engine at
finagg.backend.engine
.
- Returns:
Number of rows written to the feature’s raw SQL table.
- Raises:
NoSuchTableError – If the table associated with this feature set update does not exist.