tti.indicators package

Trading-Technical-Indicators (tti) python library

the tti.indicators package includes the implementation of all of the supported Technical Indicators.

class tti.indicators.AccumulationDistributionLine(input_data, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Accumulation Distribution Line Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, close, volume. The index is of type pandas.DatetimeIndex.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the adl.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.AverageTrueRange(input_data, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Average True Range Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, close. The index is of type pandas.DatetimeIndex.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the atr.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.BollingerBands(input_data, period=20, std_number=2, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Bollinger Bands Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns is close. The index is of type pandas.DatetimeIndex.

  • period (int, default=20) – The past periods to be used for the calculation of the middle band (simple moving average).

  • std_number (int, default=2) – The number of standard deviations to be used for calculating the upper and lower bands.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains three columns, the middle_band, upper_band and lower_band.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.ChaikinMoneyFlow(input_data, period=5, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Chaikin Money Flow Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, close, volume. The index is of type pandas.DatetimeIndex.

  • period (int, default=5) – The past periods to be used for the calculation of the sum parts in the indicator formula.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the cmf.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.ChaikinOscillator(input_data, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Chaikin Oscillator Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, close, volume. The index is of type pandas.DatetimeIndex.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the co.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.ChandeMomentumOscillator(input_data, period=5, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Chande Momentum Oscillator Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns is``close``. The index is of type pandas.DatetimeIndex.

  • period (int, default=5) – The past periods to be used for the calculation of the indicator.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the cmo.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.CommodityChannelIndex(input_data, period=5, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Commodity Channel Index Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, close. The index is of type pandas.DatetimeIndex.

  • period (int, default=5) – The past periods to be used for the

  • calculation of the indicator.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the cci.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.DetrendedPriceOscillator(input_data, period=6, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Detrended Price Oscillator Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns is close. The index is of type pandas.DatetimeIndex.

  • period (int, default=6) – The past periods to be used for the calculation of the indicator.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the dpo.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.DirectionalMovementIndex(input_data, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Directional Movement Index Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, close. The index is of type pandas.DatetimeIndex.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains three columns, the +di, -di, dx, adx and the adxr.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.DoubleExponentialMovingAverage(input_data, period=5, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Double Exponential Moving Average Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns is close. The index is of type pandas.DatetimeIndex.

  • period (int, default=5) – The past periods to be used for the calculation of the indicator.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the dema.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.EaseOfMovement(input_data, period=40, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Ease Of Movement Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, volume. The index is of type pandas.DatetimeIndex.

  • period (int, default=40) – The past periods to be used for the calculation of the moving average.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains two columns, the emv and the emv_ma.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.Envelopes(input_data, period=20, shift=0.1, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Envelopes Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input column is close. The index is of type pandas.DatetimeIndex.

  • period (int, default=20) – The past periods to be used for the calculation of the moving average.

  • shift (float, default=0.10) – The shift percentage to be applied.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains two columns, the upper_band and the lower_band.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.FibonacciRetracement(input_data, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Fibonacci Retracement Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input column is close. The index is of type pandas.DatetimeIndex.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains five columns, the resistance levels rl_0.0,`` rl_23.6``, rl_38.2, rl_50.0, rl_61.8 and rl_100.0.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.ForecastOscillator(input_data, period=14, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Forecast Oscillator Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input column is close. The index is of type pandas.DatetimeIndex.

  • period (int, default=14) – The past periods to be used for the calculation of the indicator.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the fosc.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.IchimokuCloud(input_data, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Ichimoku Cloud Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, close. The index is of type pandas.DatetimeIndex.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains four columns the tenkan_sen, kijun_sen, senkou_a, senkou_b.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.IntradayMovementIndex(input_data, period=14, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Intraday Movement Index Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are open, close. The index is of type pandas.DatetimeIndex.

  • period (int, default=14) – The past periods to be used for the calculation of the indicator.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the imi.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.KlingerOscillator(input_data, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Klinger Oscillator Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, close, volume. The index is of type pandas.DatetimeIndex.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the ko.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.LinearRegressionIndicator(input_data, period=14, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Linear regression Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input column is close. The index is of type pandas.DatetimeIndex.

  • period (int, default=14) – The past periods to be used for the calculation of the forecast.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the lri.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.LinearRegressionSlope(input_data, period=14, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Linear Regression Slope Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input column is close. The index is of type pandas.DatetimeIndex.

  • period (int, default=14) – The past periods to be used for the calculation of the indicator.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the lrs.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.MarketFacilitationIndex(input_data, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Market Facilitation Index Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, volume. The index is of type pandas.DatetimeIndex.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the mfi.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.MassIndex(input_data, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Mass Index Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, close. The index is of type pandas.DatetimeIndex.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the mi.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.MedianPrice(input_data, period=20, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Median Price Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, close. The index is of type pandas.DatetimeIndex.

  • period (int, default=20) – The past periods to be used for the calculation of the moving average for the trading signal.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the mp.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.Momentum(input_data, period=12, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Momentum Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input column is close. The index is of type pandas.DatetimeIndex.

  • period (int, default=12) – The past periods to be used for the calculation of the indicator.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the mom.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.MovingAverage(input_data, period=20, ma_type='simple', fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Moving Average Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input column is close. The index is of type pandas.DatetimeIndex.

  • period (int, default=20) – The past periods to be used for the calculation of the moving average. 5-13 days are for Very Short Term, 14-25 days are for Short Term, 26-49 days are for Minor Intermediate, 50-100 days for Intermediate and 100-200 days are for Long Term.

  • ma_type (str, default=’simple’) – The type of the calculated moving average. Supported values are simple, exponential, time_series, triangular and variable.

  • fill_missing_values (bool, default is True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the ma.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.MovingAverageConvergenceDivergence(input_data, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Moving Average Convergence Divergence Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input column is close. The index is of type pandas.DatetimeIndex.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains two columns, the macd and the signal_line.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.NegativeVolumeIndex(input_data, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Negative Volume Index Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are close, volume. The index is of type pandas.DatetimeIndex.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the nvi.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.OnBalanceVolume(input_data, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

On Balance Volume Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are close, volume. The index is of type pandas.DatetimeIndex.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the obv.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.ParabolicSAR(input_data, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Parabolic SAR Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, close. The index is of type pandas.DatetimeIndex.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the sar.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.Performance(input_data, mode='LONG', target=0.05, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Performance Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input column is close. The index is of type pandas.DatetimeIndex.

  • mode (str, default=’LONG’) – The current position entered at period 0 (first row in the input data). Possible values are LONG and SHORT.

  • target (numeric, default is 0.05) – The target percentage movement of the price. When mode is LONG the target is positive, and an exit signal is produced when the target is reached. When mode is SHORT the target is negative, and an exit signal is produced when the target is reached.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains two columns, the prf and the target_<mode>.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.PositiveVolumeIndex(input_data, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Positive Volume Index Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are close, volume. The index is of type pandas.DatetimeIndex.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the pvi.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.PriceAndVolumeTrend(input_data, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Price And Volume Trend Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are close, volume. The index is of type pandas.DatetimeIndex.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the pvt.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.PriceChannel(input_data, period=5, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Price Channel Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, close. The index is of type pandas.DatetimeIndex.

  • period (int, default=5) – The past periods to be used for the calculation of the indicator.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains two columns, the highest_high and the lowest_low.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.PriceOscillator(input_data, long_ma=30, short_ma=10, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Price Oscillator Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input column is close`. The index is of type pandas.DatetimeIndex.

  • long_ma (int, default=30) – The periods to be used for the calculation of the Long Moving Average.

  • short_ma (int, default=10) – The periods to be used for the calculation of the Short Moving Average.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the posc.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.PriceRateOfChange(input_data, period=25, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Price Rate Of Change Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input column is close. The index is of type pandas.DatetimeIndex.

  • period (int, default=25) – The past periods to be used for the calculation of the indicator.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the prc.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.ProjectionBands(input_data, period=14, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Projection Bands Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, close. The index is of type pandas.DatetimeIndex.

  • period (int, default=14) – The past periods to be used for the calculation of the indicator.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains two columns, the upper_band, lower_band.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.ProjectionOscillator(input_data, period=14, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Projection Oscillator Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, close. The index is of type pandas.DatetimeIndex.

  • period (int, default=14) – The past periods to be used for the calculation of the indicator.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains two columns, the posc and the trigger_line.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.Qstick(input_data, period=8, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Qstick Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are open, close. The index is of type pandas.DatetimeIndex.

  • period (int, default=8) – The past periods to be used for the calculation of the indicator.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the qstick.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.RangeIndicator(input_data, range_period=5, smoothing_period=3, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Range Indicator Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, close, volume. The index is of type pandas.DatetimeIndex.

  • range_period (int, default=5) – The range periods to be used for the calculation of the indicator.

  • smoothing_period (int, default=3) – The smoothing periods to be used for the calculation of the indicator.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the ri.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.RelativeMomentumIndex(input_data, period=8, momentum_period=4, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Relative Momentum Index Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input column is close. The index is of type pandas.DatetimeIndex.

  • period (int, default=8) – The past periods to be used for the calculation of the indicator.

  • momentum_period (int, default=4) – The momentum periods to be used for the calculation of the indicator.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the rmi.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.RelativeStrengthIndex(input_data, period=14, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Relative Strength Index Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input column is close. The index is of type pandas.DatetimeIndex.

  • period (int, default=14) – The past periods to be used for the calculation of the indicator. Popular values are 14, 9 and 25.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column rsi.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.RelativeVolatilityIndex(input_data, period=5, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Relative Volatility Index Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low. The index is of type pandas.DatetimeIndex.

  • period (int, default=5) – The past periods to be used for the calculation of the indicator.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the rvi.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.StandardDeviation(input_data, period=20, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Standard Deviation Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input column is close. The index is of type pandas.DatetimeIndex.

  • period (int, default=20) – The past periods to be used for the calculation of the simple moving average.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the sd.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.StochasticMomentumIndex(input_data, period=5, smoothing_period=3, double_smoothing_period=3, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Stochastic Momentum Index Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, close. The index is of type pandas.DatetimeIndex.

  • period (int, default=5) – The past periods to be used for the calculation of the indicator.

  • smoothing_period (int, default=3) – The number of periods to be used when smoothing.

  • double_smoothing_period (int, default=3) – The number of periods to be used when double smoothing.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the smi.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.StochasticOscillator(input_data, k_periods=14, k_slowing_periods=1, d_periods=3, d_method='simple', fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Stochastic Oscillator Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, close. The index is of type pandas.DatetimeIndex.

  • k_periods (int, default=14) – Number of periods to be used in the stochastic calculation %K.

  • k_slowing_periods (int, default=1) – Smoothing to be used in the stochastic calculation. Supported values are 1 and 3. 1 is considered as Fast Stochastic and 3 is considered as Slow Stochastic.

  • d_periods (int, default=3) – Periods to be used when calculating the moving average %D of %K.

  • d_method (str, default=’simple’) – The moving average to be used when calculating %D. Supported values are simple for Simple Moving Average and exponential for Exponential Moving Average. More methods can be supported in a future release.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains two columns: the stochastic oscillator %K and the moving average of %K the %D.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.SwingIndex(input_data, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Swing Index Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are open, high, low, close. The index is of type pandas.DatetimeIndex.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the swi.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.TimeSeriesForecast(input_data, period=14, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Time Series Forecast Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input column is close. The index is of type pandas.DatetimeIndex.

  • period (int, default=14) – The past periods to be used for the calculation of the indicator.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the tsf.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.TripleExponentialMovingAverage(input_data, period=5, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Triple Exponential Moving Average Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input column is close. The index is of type pandas.DatetimeIndex.

  • period (int, default=5) – The past periods to be used for the calculation of the indicator.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

RAttributes:

_input_data (pandas.DataFrame): The input_data after preprocessing.

_ti_data (pandas.DataFrame): The calculated indicator. Index is of type

pandas.DatetimeIndex. It contains one column, the tema.

_properties (dict): Indicator properties.

_calling_instance (str): The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.TypicalPrice(input_data, period=200, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Typical Price Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, close. The index is of type pandas.DatetimeIndex.

  • period (int, default=200) – The past periods to be used for the calculation of the moving average in trading signal.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the tp.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.UltimateOscillator(input_data, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Ultimate Oscillator Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, close. The index is of type pandas.DatetimeIndex.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the uosc.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.VerticalHorizontalFilter(input_data, period=5, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Vertical Horizontal Filter Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input column is close. The index is of type pandas.DatetimeIndex.

  • period (int, default=5) – The past periods to be used for the calculation of the indicator.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the vhf.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.VolatilityChaikins(input_data, ema_period=10, change_period=10, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Volatility Chaikins Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low. The index is of type pandas.DatetimeIndex.

  • ema_period (int, default=10) – The past periods to be used for the calculation of the daily high and low prices exponential moving average.

  • change_period (int, default=10) – The period for calculating the change in the exponential moving average of the daily high and low prices.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the vch.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.VolumeOscillator(input_data, long_period=5, short_period=2, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Volume Oscillator Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input column is volume. The index is of type pandas.DatetimeIndex.

  • long_period (int, default=5) – The past periods to be used for the calculation of the long moving average.

  • short_period (int, default=2) – The past periods to be used for the calculation of the short moving average.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the vosc.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.VolumeRateOfChange(input_data, period=5, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Volume Rate of Change Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input column is volume. The index is of type pandas.DatetimeIndex.

  • period (int, default=5) – The past periods to be used for the calculation of the indicator.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the vrc.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.WeightedClose(input_data, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Weighted Close Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, close. The index is of type pandas.DatetimeIndex.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the wc.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.WildersSmoothing(input_data, period=5, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Wilders Smoothing Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input column is close. The index is of type pandas.DatetimeIndex.

  • period (int, default=5) – The past periods to be used for the calculation of the indicator.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the ws.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.WilliamsAccumulationDistribution(input_data, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Williams Accumulation Distribution Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, close. The index is of type pandas.DatetimeIndex.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the wad.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.

class tti.indicators.WilliamsR(input_data, period=5, fill_missing_values=True)

Bases: tti.indicators._technical_indicator.TechnicalIndicator

Williams %R Technical Indicator class implementation.

Parameters
  • input_data (pandas.DataFrame) – The input data. Required input columns are high, low, close. The index is of type pandas.DatetimeIndex.

  • period (int, default=5) – The past periods to be used for the calculation of the indicator.

  • fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.

Variables
  • _input_data (pandas.DataFrame) – The input_data after preprocessing.

  • _ti_data (pandas.DataFrame) – The calculated indicator. Index is of type pandas.DatetimeIndex. It contains one column, the wr.

  • _properties (dict) – Indicator properties.

  • _calling_instance (str) – The name of the class.

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotEnoughInputData – Not enough data for calculating the indicator.

  • TypeError – Type error occurred when validating the input_data.

  • ValueError – Value error occurred when validating the input_data.

getTiData()

Returns the Technical Indicator values for the whole period.

Returns

The Technical Indicator values.

Return type

pandas.DataFrame

getTiGraph()

Generates a plot customized for each Technical Indicator.

Returns

The generated plot.

Return type

matplotlib.pyplot

getTiSignal()

Calculates and returns the trading signal for the calculated technical indicator.

Returns

The calculated trading signal.

Return type

{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}

getTiSimulation(close_values, max_exposure=None, short_exposure_factor=1.5)

Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a buy trading signal a new long position is opened. With a sell trading signal a new short position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for opened long positions and current stock price < bought price for opened short positions) the positions are being closed. Only one stock piece is used in each open transaction.

Parameters
  • close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column close.

  • max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (short and long). If the exposure reaches this threshold, no further positions are being opened. A new position can be opened again only when exposure reduces through a position close. If set to None, then there is no upper limit for the opened positions (exposure). When a new long position is opened, exposure is increased by the stock_price. When a short position is opened, exposure is increased by the short_exposure_factor * stock_price. Values >0.0 or None are supported.

  • short_exposure_factor (float, default=1.5) – The exposure factor when a new short position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.

Returns

Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.

The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:

signal: the signal produced at each day of the simulation period.

open_trading_action: the open trading action applied. Possible values are long, short and none.

stock_value: The value of the stock during the simulation period.

exposure: The accumulated exposure during the simulation period. Increased by stock_price when a long position is opened, and by short_exposure_factor * stock_price when a short position is opened. Reduced by the same amounts when relevant positions are being closed.

portfolio_value: The portfolio value during the simulation period, current_stock_price * (opened_long - opened_short).

earnings: The accumulated earnings during the simulation period. Increased by the current_price - opened_position_price when a long position is closed. Increased by the opened_position_price - current_price when a short position is closed.

balance: The balance during the simulation period. It is the earnings + portfolio_value.

The dictionary contains the below keys:

number_of_trading_days: the number of trading days in the simulation round.

number_of_buy_signals: the number of buy signals produced during the simulation period.

number_of_ignored_buy_signals: the number of buy signals ignored because of the max_exposure limitation.

number_of_sell_signals: the number of sell signals produced during the simulation period.

number_of_ignored_sell_signals: the number of sell signals ignored because of the max_exposure limitation.

last_stock_value: The value of the stock at the end of the simulation.

last_exposure: The exposure value at the end of the simulation period.

last_open_long_positions: The number of the still opened long positions at the end of the simulation period.

last_open_short_positions: The number of the still opened short positions at the end of the simulation period.

last_portfolio_value: The portfolio_value at the end of the simulation period.

last_earnings: The earnings at the end of the simulation period.

final_balance: The balance at the end of the simulation period.

Return type

(pandas.DataFrame, dict, matplotlib.pyplot)

Raises
  • WrongTypeForInputParameter – Input argument has wrong type.

  • WrongValueForInputParameter – Unsupported value for input argument.

  • NotValidInputDataForSimulation – Invalid close_values passed for the simulation.

getTiValue(date=None)

Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.

Parameters

date (str, default=None) – A date string, in the same format as the format of the input_data index.

Returns

The value of the Technical Indicator for the given date. If none value found for the given date, returns None.

Return type

[float] or None

runSimulation(close_values, max_items_per_transaction=1, max_investment=0.0)

Deprecated method since release 0.1.b3. Replaced by the getTiSimulation method. This code will be removed from the package in stable-release 1.0.

Raises

TtiPackageDeprecatedMethod – Method is deprecated.