awt_quant.data_fetch package

Submodules

awt_quant.data_fetch.macro module

FRED Macroeconomic Data Fetching and Visualization

This module provides functions to fetch macroeconomic time series data from the Federal Reserve Economic Data (FRED) API and visualize the results using Plotly. It supports retrieving both historical data and metadata for various economic indicators.

Functions:
  • get_fred_series(series_id, shorten=False): Fetches time series data from FRED.

  • get_fred_series_info(series_id, as_dict=True): Retrieves metadata for a FRED series.

  • get_macro(series_id, data=True, info=True, shorten=False): Fetches both time series and metadata for a FRED series.

  • get_bulk_macro(series_dict): Bulk fetches macroeconomic data for predefined indicators.

  • plot_macro_series(data, meta_data, dropna=False, y_axis_format=None): Plots macroeconomic time series data.

  • plot_macro_series_forecast(forecast_data, actual_data, meta_data, dropna=False, y_axis_format=None): Plots actual and forecasted macroeconomic data with confidence intervals.

  • fetch_and_plot(series_id, with_data=False): Fetches and plots a macroeconomic time series.

Usage:

df, meta = get_macro(“GDP”) fig = plot_macro_series(df, meta) fig.show()

awt_quant.data_fetch.macro.get_fred_series(series_id, shorten=False)[source]

Fetches time series data from FRED.

Parameters:
  • series_id (str) – The FRED series ID.

  • shorten (bool, optional) – If True, returns only the last 30 observations. Defaults to False.

Returns:

A dataframe containing the date and value columns.

Return type:

pd.DataFrame

awt_quant.data_fetch.macro.get_fred_series_info(series_id, as_dict=True)[source]

Retrieves metadata for a FRED series.

Parameters:
  • series_id (str) – The FRED series ID.

  • as_dict (bool, optional) – If True, returns metadata as a dictionary; otherwise, returns a DataFrame.

Returns:

Metadata about the series.

Return type:

dict or pd.DataFrame

awt_quant.data_fetch.macro.get_macro(series_id, data=True, info=True, shorten=False)[source]

Fetches both time series data and metadata for a given FRED series.

Parameters:
  • series_id (str) – The FRED series ID.

  • data (bool, optional) – Whether to fetch time series data. Defaults to True.

  • info (bool, optional) – Whether to fetch metadata. Defaults to True.

  • shorten (bool, optional) – If True, returns only the last 30 observations. Defaults to False.

Returns:

(pd.DataFrame, dict) or single return depending on arguments.

Return type:

tuple

awt_quant.data_fetch.macro.get_bulk_macro(series_dict={'Consumer Price Index (CPI)': 'CPIAUCSL', 'Federal Funds Rate': 'FEDFUNDS', 'Gross Domestic Product (GDP)': 'GDP', 'Retail Sales': 'RSXFS', 'Unemployment Rate': 'UNRATE'})[source]

Bulk fetch of major macroeconomic series data.

Parameters:

series_dict (dict, optional) – Dictionary of macroeconomic indicators and their FRED series IDs.

Returns:

Dictionary containing time series data and metadata for each indicator.

Return type:

dict

awt_quant.data_fetch.macro.plot_macro_series(data, meta_data, dropna=False, y_axis_format=None)[source]

Plots macroeconomic time series data.

Parameters:
  • data (pd.DataFrame) – The time series data.

  • meta_data (dict) – The metadata of the series.

  • dropna (bool, optional) – Whether to drop NaN values. Defaults to False.

  • y_axis_format (str, optional) – Y-axis tick format. Defaults to None.

Returns:

A Plotly figure object.

Return type:

plotly.graph_objects.Figure

awt_quant.data_fetch.yf_fetch module

Yahoo Finance Data Fetching

This module provides a function to fetch historical stock price data from Yahoo Finance. It preprocesses the data for use in stochastic differential equation models.

Functions:
  • download_data(ticker, start_date, end_date, train_test_split): Fetches and splits stock price data.

Usage:

train_data, test_data, meta_data = download_data(“AAPL”, “2022-01-01”, “2023-01-01”, train_test_split=0.8)

awt_quant.data_fetch.yf_fetch.download_data(ticker, start_date, end_date, train_test_split)[source]

Downloads stock price data from Yahoo Finance and processes it for training/testing.

Parameters:
  • ticker (str) – Stock ticker symbol.

  • start_date (str) – Start date in ‘YYYY-MM-DD’ format.

  • end_date (str) – End date in ‘YYYY-MM-DD’ format.

  • train_test_split (float) – Fraction of data to use for training (e.g., 0.8 for 80% training data).

Returns:

(train_data, test_data, meta_data)
  • train_data (pd.DataFrame): Training set containing stock close prices.

  • test_data (pd.DataFrame): Testing set containing stock close prices.

  • meta_data (dict): Dictionary with additional information (dates, S0, T, N).

Return type:

tuple

Module contents

Data Fetching Module

This module provides functions for retrieving financial and macroeconomic data from external sources such as Yahoo Finance.

Available Functions: - fetch_macro_data: Retrieves macroeconomic indicators. - fetch_yfinance_data: Fetches historical stock price data from Yahoo Finance.

awt_quant.data_fetch.get_macro(series_id, data=True, info=True, shorten=False)[source]

Fetches both time series data and metadata for a given FRED series.

Parameters:
  • series_id (str) – The FRED series ID.

  • data (bool, optional) – Whether to fetch time series data. Defaults to True.

  • info (bool, optional) – Whether to fetch metadata. Defaults to True.

  • shorten (bool, optional) – If True, returns only the last 30 observations. Defaults to False.

Returns:

(pd.DataFrame, dict) or single return depending on arguments.

Return type:

tuple

awt_quant.data_fetch.plot_macro_series(data, meta_data, dropna=False, y_axis_format=None)[source]

Plots macroeconomic time series data.

Parameters:
  • data (pd.DataFrame) – The time series data.

  • meta_data (dict) – The metadata of the series.

  • dropna (bool, optional) – Whether to drop NaN values. Defaults to False.

  • y_axis_format (str, optional) – Y-axis tick format. Defaults to None.

Returns:

A Plotly figure object.

Return type:

plotly.graph_objects.Figure

awt_quant.data_fetch.get_bulk_macro(series_dict={'Consumer Price Index (CPI)': 'CPIAUCSL', 'Federal Funds Rate': 'FEDFUNDS', 'Gross Domestic Product (GDP)': 'GDP', 'Retail Sales': 'RSXFS', 'Unemployment Rate': 'UNRATE'})[source]

Bulk fetch of major macroeconomic series data.

Parameters:

series_dict (dict, optional) – Dictionary of macroeconomic indicators and their FRED series IDs.

Returns:

Dictionary containing time series data and metadata for each indicator.

Return type:

dict

awt_quant.data_fetch.get_fred_series_info(series_id, as_dict=True)[source]

Retrieves metadata for a FRED series.

Parameters:
  • series_id (str) – The FRED series ID.

  • as_dict (bool, optional) – If True, returns metadata as a dictionary; otherwise, returns a DataFrame.

Returns:

Metadata about the series.

Return type:

dict or pd.DataFrame

awt_quant.data_fetch.get_fred_series(series_id, shorten=False)[source]

Fetches time series data from FRED.

Parameters:
  • series_id (str) – The FRED series ID.

  • shorten (bool, optional) – If True, returns only the last 30 observations. Defaults to False.

Returns:

A dataframe containing the date and value columns.

Return type:

pd.DataFrame

awt_quant.data_fetch.download_data(ticker, start_date, end_date, train_test_split)[source]

Downloads stock price data from Yahoo Finance and processes it for training/testing.

Parameters:
  • ticker (str) – Stock ticker symbol.

  • start_date (str) – Start date in ‘YYYY-MM-DD’ format.

  • end_date (str) – End date in ‘YYYY-MM-DD’ format.

  • train_test_split (float) – Fraction of data to use for training (e.g., 0.8 for 80% training data).

Returns:

(train_data, test_data, meta_data)
  • train_data (pd.DataFrame): Training set containing stock close prices.

  • test_data (pd.DataFrame): Testing set containing stock close prices.

  • meta_data (dict): Dictionary with additional information (dates, S0, T, N).

Return type:

tuple