time_series_transform.stock_transform package

Submodules

time_series_transform.stock_transform.base module

class time_series_transform.stock_transform.base.Portfolio(time_series_data, time_index, symbolIx, High='High', Low='Low', Close='Close', Open='Open', Volume='Volume')[source]

Bases: time_series_transform.transform_core_api.base.Time_Series_Data_Collection

classmethod from_time_series_collection(time_series_data_collection, High='High', Low='Low', Close='Close', Open='Open', Volume='Volume')[source]

from_time_series_collection making Portfolio object from Time_Series_Data_Collection

Parameters
  • time_series_data_collection (Time_Series_Data_Collection) – input data

  • High (str or int, optional) – the index or name for High, by default ‘High’

  • Low (str or int, optional) – the index or name for Low, by default ‘Low’

  • Close (str or int, optional) – the index or name for Close, by default ‘Close’

  • Open (str or int, optional) – the index or name for Open, by default ‘Open’

  • Volume (str or int, optional) – the index or name for Volume, by default ‘Volume’

Returns

Return type

Portfolio

get_technical_indicator(strategy, n_jobs=1, verbose=0, backend='loky', *args, **kwargs)[source]

get_technical_indicator making different technical indicator

pandas-ta implmentation https://github.com/twopirllc/pandas-ta

Parameters
  • strategy (Strategy) – pandas-ta strategy

  • n_jobs (int, optional) – number of processes (joblib), by default 1

  • verbose (int, optional) – log level (joblib), by default 0

  • backend (str, optional) – backend type (joblib), by default ‘loky’

Returns

Return type

self

class time_series_transform.stock_transform.base.Stock(data, time_index, symbol=None, High='High', Low='Low', Close='Close', Open='Open', Volume='Volume')[source]

Bases: time_series_transform.transform_core_api.base.Time_Series_Data

classmethod from_time_series_data(time_series_data, symbol=None, High='High', Low='Low', Close='Close', Open='Open', Volume='Volume')[source]

making Stock object from Time_Series_Data class

Parameters
  • time_series_data (Time_Series_Data) – input Data

  • symbol (str, option) – ticker name, by default None

  • High (str or int, optional) – the index or name for High, by default ‘High’

  • Low (str or int, optional) – the index or name for Low, by default ‘Low’

  • Close (str or int, optional) – the index or name for Close, by default ‘Close’

  • Open (str or int, optional) – the index or name for Open, by default ‘Open’

  • Volume (str or int, optional) – the index or name for Volume, by default ‘Volume’

Returns

Return type

Stock

get_technical_indicator(strategy)[source]

get_technical_indicator making different technical indicator

pandas-ta implmentation https://github.com/twopirllc/pandas-ta

Parameters

strategy (Strategy) – pandas-ta strategy

Returns

Return type

self

time_series_transform.stock_transform.stock_extractor module

class time_series_transform.stock_transform.stock_extractor.Portfolio_Extractor(symbolList, engine, *args, **kwargs)[source]

Bases: object

get_date(start_date, end_date, n_threads=8)[source]

get_portfolio_date extracts the list of stock by the date period

Parameters
  • start_date (str) – start of the data format: “%Y-%m-%d”, eg “2020-02-20”

  • end_date (str) – end of the data

  • n_threads (int) – number of thread of multi-thread processing

Returns

portfolio data of the given stock list

Return type

portfolio

get_intra_day(start_date, end_date, interval='1m', n_threads=8)[source]

get_intra_day extracts the intraday data of the list of stock data by the date period

Parameters
  • start_date (str) – start of the data format: “%Y-%m-%d”, eg “2020-02-20”

  • end_date (str) – end of the data

  • interval (str) – interval of the data Valid intervals: [1m, 2m, 5m, 15m, 30m, 60m, 90m, 1h]

  • n_threads (int) – number of thread of multi-thread processing

Returns

portfolio data of the given stock list

Return type

portfolio

get_period(period, n_threads=8)[source]

get_period extracts the list of stock by the given period

Parameters
  • period (str) – period of the data for example, 1d,5d,1mo,3mo,6mo,1y,2y,5y,10y,ytd,max

  • n_threads (int) – number of thread of multi-thread processing

Returns

portfolio data of the given stock list

Return type

portfolio

class time_series_transform.stock_transform.stock_extractor.Stock_Extractor(symbol, engine, *args, **kwargs)[source]

Bases: object

get_date(start_date, end_date)[source]

get_period extracts the stock data of the selected period

Parameters
  • start_date (str) – start of the data format: “%Y-%m-%d”, eg “2020-02-20”

  • end_date (str) – end of the data

Returns

The stock data of selected period

Return type

stock data

get_intra_day(start_date, end_date, interval='1m')[source]

get_intra_day extracts the intraday stock data of the selected period

Parameters
  • start_date (str) – start of the data format: “%Y-%m-%d”, eg “2020-02-20”

  • end_date (str) – end of the data

  • interval (str) – interval of the data Valid intervals: [1m, 2m, 5m, 15m, 30m, 60m, 90m, 1h]

Returns

The stock data of selected period

Return type

stock data

get_period(period)[source]

get_period extracts the stock data of the selected period

Parameters

period (str) – period of the data for example, 1d,5d,1mo,3mo,6mo,1y,2y,5y,10y,ytd,max

Returns

The stock data of selected period

Return type

stock data

time_series_transform.stock_transform.stock_transfromer module

class time_series_transform.stock_transform.stock_transfromer.Stock_Transformer(time_series_data, time_seriesIx, symbolIx, symbolName=None, High='High', Low='Low', Close='Close', Open='Open', Volume='Volume')[source]

Bases: time_series_transform.transform_core_api.time_series_transformer.Time_Series_Transformer

classmethod from_arrow_table(arrow_table, timeSeriesCol, symbolIx, symbolName=None, High='High', Low='Low', Close='Close', Open='Open', Volume='Volume')[source]

from_arrow_table [summary]

[extended_summary]

Parameters
  • arrow_table (arrow table) – input data

  • timeSeriesCol (str or numeric) – time series column name

  • symbolIx (str or numeric) – main category name

  • symbolName (str or numeric, option) – ticker name only used when single stock, by default None

  • High (str or int, optional) – the index or name for High, by default ‘High’

  • Low (str or int, optional) – the index or name for Low, by default ‘Low’

  • Close (str or int, optional) – the index or name for Close, by default ‘Close’

  • Open (str or int, optional) – the index or name for Open, by default ‘Open’

  • Volume (str or int, optional) – the index or name for Volume, by default ‘Volume’

Returns

Return type

Stock_Transformer

classmethod from_feather(feather_dir, timeSeriesCol, symbolIx, symbolName=None, columns=None, High='High', Low='Low', Close='Close', Open='Open', Volume='Volume')[source]

from_feather import data from feather

Parameters
  • feather_dir (str) – directory of feather file

  • timeSeriesCol (str or numeric) – time series column name

  • symbolIx (str or numeric) – main category name

  • symbolName (str or numeric, option) – ticker name only used when single stock, by default None

  • columns (str or numeric, optional) – target columns (apache arrow implmentation), by default None

  • High (str or int, optional) – the index or name for High, by default ‘High’

  • Low (str or int, optional) – the index or name for Low, by default ‘Low’

  • Close (str or int, optional) – the index or name for Close, by default ‘Close’

  • Open (str or int, optional) – the index or name for Open, by default ‘Open’

  • Volume (str or int, optional) – the index or name for Volume, by default ‘Volume’

Returns

Return type

Stock_Transformer

classmethod from_numpy(numpyData, timeSeriesCol, mainCategoryCol, High, Low, Close, Open, Volume, symbolName=None)[source]

from_numpy from_numpy import data from numpy

Parameters
  • numpyData (numpy ndArray) – input data

  • timeSeriesCol (int) – index of time series column

  • mainCategoryCol (int) – index of main category column

  • High (int, optional) – the column index for High, by default ‘High’

  • Low (int, optional) – the column index for Low, by default ‘Low’

  • Close (int, optional) – the column index for Close, by default ‘Close’

  • Open (int, optional) – the column index for Open, by default ‘Open’

  • Volume (int, optional) – the column index for Volume, by default ‘Volume’

  • symbolName (str or numeric, option) – ticker name only used when single stock, by default None

Returns

Return type

Stock_Transformer

classmethod from_pandas(pandasFrame, timeSeriesCol, mainCategoryCol, symbolName=None, High='High', Low='Low', Close='Close', Open='Open', Volume='Volume')[source]

from_pandas import data from pandas dataFrame

Parameters
  • pandasFrame (pandas DataFrame) – input data

  • timeSeriesCol (str or numeric) – time series column name

  • mainCategoryCol (str or numeric) – main category name

  • symbolName (str or numeric, option) – ticker name only used when single stock, by default None

  • High (str or int, optional) – the column name for High, by default ‘High’

  • Low (str or int, optional) – the column name for Low, by default ‘Low’

  • Close (str or int, optional) – the column name for Close, by default ‘Close’

  • Open (str or int, optional) – the column name for Open, by default ‘Open’

  • Volume (str or int, optional) – the column name for Volume, by default ‘Volume’

Returns

Return type

Stock_Transformer

classmethod from_parquet(parquet_dir, timeSeriesCol, symbolIx, symbolName=None, columns=None, partitioning='hive', filters=None, filesystem=None, High='High', Low='Low', Close='Close', Open='Open', Volume='Volume')[source]

from_parquet import data from parquet file

Parameters
  • parquet_dir (str) – directory of parquet file

  • timeSeriesCol (str or numeric) – time series column name

  • symbolIx (str or numeric) – main category name

  • symbolName (str or numeric, option) – ticker name only used when single stock, by default None

  • columns (str or numeric, optional) – target columns (apache arrow implmentation), by default None

  • partitioning (str, optional) – type of partitioning, by default ‘hive’

  • filters (str, optional) – filter (apache arrow implmentation), by default None

  • filesystem (str, optional) – filesystem (apache arrow implmentation), by default None

  • High (str or int, optional) – the index or name for High, by default ‘High’

  • Low (str or int, optional) – the index or name for Low, by default ‘Low’

  • Close (str or int, optional) – the index or name for Close, by default ‘Close’

  • Open (str or int, optional) – the index or name for Open, by default ‘Open’

  • Volume (str or int, optional) – the index or name for Volume, by default ‘Volume’

Returns

Return type

Stock_Transformer

classmethod from_stock_engine_date(symbols, start_date, end_date, engine, n_threads=8, *args, **kwargs)[source]

from_stock_engine_date [summary]

[extended_summary]

Parameters
  • symbols (str or list) – ticker name

  • start_date (str) – start of the data format: “%Y-%m-%d”, eg “2020-02-20”

  • end_date (str) – end of the data format: “%Y-%m-%d”, eg “2020-02-20”

  • engine (['yahoo','investing']) – fetching api

  • n_threads (int, optional) – multi-thread fetching support only when symbols is a list, by default 8

Returns

Return type

Stock_Transformer

classmethod from_stock_engine_intraday(symbols, start_date, end_date, engine='yahoo', interval='1m', n_threads=8, *args, **kwargs)[source]
classmethod from_stock_engine_period(symbols, period, engine, n_threads=8, *args, **kwargs)[source]

from_stock_engine_period fetching data from online

the current engine support yfinance and investpy

Parameters
  • symbols (str or list) – ticker name

  • period (str) – period of the data for example, 1d,5d,1mo,3mo,6mo,1y,2y,5y,10y,ytd,max

  • engine (['yahoo','investing']) – fetching api

  • n_threads (int, optional) – multi-thread fetching support only when symbols is a list, by default 8

Returns

Return type

Stock_Transformer

classmethod from_time_series_transformer(time_series_transformer, symbolName=None, High='High', Low='Low', Close='Close', Open='Open', Volume='Volume')[source]

from_time_series_transformer making Stock_Transformer from Time_Series_Transformer

Parameters
  • time_series_transformer (Time_Series_Transformer) – input data

  • symbolName (str or numeric, option) – ticker name only used when single stock, by default None

  • High (str or int, optional) – the index or name for High, by default ‘High’

  • Low (str or int, optional) – the index or name for Low, by default ‘Low’

  • Close (str or int, optional) – the index or name for Close, by default ‘Close’

  • Open (str or int, optional) – the index or name for Open, by default ‘Open’

  • Volume (str or int, optional) – the index or name for Volume, by default ‘Volume’

Returns

Return type

Stock_Transformer

get_technial_indicator(strategy, n_jobs=1, verbose=10, backend='loky')[source]

get_technical_indicator making different technical indicator

pandas-ta implmentation https://github.com/twopirllc/pandas-ta

Parameters
  • strategy (Strategy) – pandas-ta strategy

  • n_jobs (int, optional) – number of processes (joblib), by default 1

  • verbose (int, optional) – log level (joblib), by default 0

  • backend (str, optional) – backend type (joblib), by default ‘loky’

Returns

Return type

self

time_series_transform.stock_transform.util module

time_series_transform.stock_transform.util.macd(arr, return_diff=False)[source]

Return the moving average convergence/divergence

Parameters
  • arr (array) – data used to calculate the macd

  • return_diff (bool) – return difference between DIF and DEM if True

Returns

df – macd of the given data, including EMA_12, EMA_26, DIF, DEM, OSC

Return type

dict

time_series_transform.stock_transform.util.rsi(arr, n_day=14)[source]

Return the Relative Strength Index

Parameters

arr (array) – data used to calculate the Relative Strength Index

Returns

rsi – Relative Strength Index of the given array

Return type

array

time_series_transform.stock_transform.util.stochastic_oscillator(arr, window=14)[source]

Return the stochastic oscillator

Parameters
  • arr (pandas or Time_Series_Data) – data used to calculate the stochastic oscillator

  • window (int) – window of the stochastic oscillator

Returns

ret – stochastic oscillator of the given data, including k and d values

Return type

dict

time_series_transform.stock_transform.util.williams_r(arr, n_day=14)[source]

Return the Williams %R index

Parameters
  • arr (array) – data used to calculate the Williams %R

  • n_day (int) – window of the indicator

Returns

r_val – Relative Strength Index of the given array

Return type

array

Module contents