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.TechnicalIndicatorAccumulation 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 typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, theadl._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.AverageTrueRange(input_data, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorAverage 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 typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, theatr._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.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.TechnicalIndicatorBollinger Bands Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns is
close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains three columns, themiddle_band,upper_bandandlower_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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.ChaikinMoneyFlow(input_data, period=5, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorChaikin 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 typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thecmf._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.ChaikinOscillator(input_data, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorChaikin 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 typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, theco._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.ChandeMomentumOscillator(input_data, period=5, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorChande 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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thecmo._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.CommodityChannelIndex(input_data, period=5, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorCommodity 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 typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thecci._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.DetrendedPriceOscillator(input_data, period=6, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorDetrended Price Oscillator Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns is
close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thedpo._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.DirectionalMovementIndex(input_data, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorDirectional 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 typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains three columns, the+di,-di,dx,adxand theadxr._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.DoubleExponentialMovingAverage(input_data, period=5, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorDouble Exponential Moving Average Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns is
close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thedema._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.EaseOfMovement(input_data, period=40, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorEase 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 typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains two columns, theemvand theemv_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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.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.TechnicalIndicatorEnvelopes Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains two columns, theupper_bandand thelower_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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.FibonacciRetracement(input_data, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorFibonacci Retracement Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains five columns, the resistance levelsrl_0.0,`` rl_23.6``,rl_38.2,rl_50.0,rl_61.8andrl_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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.ForecastOscillator(input_data, period=14, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorForecast Oscillator Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thefosc._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.IchimokuCloud(input_data, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorIchimoku Cloud Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high,low,close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains four columns thetenkan_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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.IntradayMovementIndex(input_data, period=14, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorIntraday Movement Index Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
open,close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, theimi._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.KlingerOscillator(input_data, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorKlinger 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 typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, theko._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.LinearRegressionIndicator(input_data, period=14, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorLinear regression Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thelri._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.LinearRegressionSlope(input_data, period=14, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorLinear Regression Slope Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thelrs._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.MarketFacilitationIndex(input_data, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorMarket 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 typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, themfi._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.MassIndex(input_data, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorMass Index Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high,low,close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, themi._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.MedianPrice(input_data, period=20, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorMedian Price Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high,low,close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, themp._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.Momentum(input_data, period=12, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorMomentum Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, themom._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.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.TechnicalIndicatorMoving Average Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close. The index is of typepandas.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,triangularandvariable.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thema._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.MovingAverageConvergenceDivergence(input_data, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorMoving Average Convergence Divergence Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains two columns, themacdand thesignal_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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.NegativeVolumeIndex(input_data, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorNegative Volume Index Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
close,volume. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thenvi._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.OnBalanceVolume(input_data, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorOn Balance Volume Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
close,volume. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, theobv._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.ParabolicSAR(input_data, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorParabolic SAR Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high,low,close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thesar._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.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.TechnicalIndicatorPerformance Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close. The index is of typepandas.DatetimeIndex.mode (str, default=’LONG’) – The current position entered at period 0 (first row in the input data). Possible values are
LONGandSHORT.target (numeric, default is 0.05) – The target percentage movement of the price. When mode is
LONGthe target is positive, and an exit signal is produced when the target is reached. When mode isSHORTthe 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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains two columns, theprfand thetarget_<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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.PositiveVolumeIndex(input_data, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorPositive Volume Index Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
close,volume. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thepvi._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.PriceAndVolumeTrend(input_data, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorPrice 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 typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thepvt._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.PriceChannel(input_data, period=5, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorPrice Channel Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high,low,close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains two columns, thehighest_highand thelowest_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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.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.TechnicalIndicatorPrice 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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, theposc._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.PriceRateOfChange(input_data, period=25, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorPrice Rate Of Change Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, theprc._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.ProjectionBands(input_data, period=14, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorProjection Bands Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high,low,close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains two columns, theupper_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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.ProjectionOscillator(input_data, period=14, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorProjection Oscillator Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high,low,close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains two columns, theposcand thetrigger_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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.Qstick(input_data, period=8, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorQstick Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
open,close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, theqstick._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.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.TechnicalIndicatorRange 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 typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, theri._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.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.TechnicalIndicatorRelative Momentum Index Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thermi._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.RelativeStrengthIndex(input_data, period=14, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorRelative Strength Index Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one columnrsi._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.RelativeVolatilityIndex(input_data, period=5, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorRelative Volatility Index Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high,low. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thervi._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.StandardDeviation(input_data, period=20, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorStandard Deviation Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thesd._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.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.TechnicalIndicatorStochastic 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 typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thesmi._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.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.TechnicalIndicatorStochastic Oscillator Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high,low,close. The index is of typepandas.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.
1is considered asFast Stochasticand3is considered asSlow Stochastic.d_periods (int, default=3) – Periods to be used when calculating the moving average
%Dof%K.d_method (str, default=’simple’) – The moving average to be used when calculating
%D. Supported values aresimplefor Simple Moving Average andexponentialfor 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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains two columns: the stochastic oscillator%Kand the moving average of%Kthe%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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.SwingIndex(input_data, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorSwing 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 typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, theswi._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.TimeSeriesForecast(input_data, period=14, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorTime Series Forecast Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thetsf._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.TripleExponentialMovingAverage(input_data, period=5, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorTriple Exponential Moving Average Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close. The index is of typepandas.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_dataafter preprocessing.- _ti_data (pandas.DataFrame): The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thetema.
_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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.TypicalPrice(input_data, period=200, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorTypical Price Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high,low,close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thetp._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.UltimateOscillator(input_data, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorUltimate Oscillator Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high,low,close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, theuosc._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.VerticalHorizontalFilter(input_data, period=5, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorVertical Horizontal Filter Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thevhf._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.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.TechnicalIndicatorVolatility Chaikins Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high,low. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thevch._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.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.TechnicalIndicatorVolume Oscillator Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
volume. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thevosc._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.VolumeRateOfChange(input_data, period=5, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorVolume Rate of Change Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
volume. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thevrc._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.WeightedClose(input_data, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorWeighted Close Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high,low,close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thewc._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.WildersSmoothing(input_data, period=5, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorWilders Smoothing Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thews._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.WilliamsAccumulationDistribution(input_data, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorWilliams 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 typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thewad._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.
-
class
tti.indicators.WilliamsR(input_data, period=5, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicatorWilliams %R Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high,low,close. The index is of typepandas.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_dataafter preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex. It contains one column, thewr._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
buytrading signal a newlongposition is opened. With aselltrading signal a newshortposition is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlongpositions and current stock price < bought price for openedshortpositions) 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 (
shortandlong). 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 newlongposition is opened, exposure is increased by thestock_price. When ashortposition is opened, exposure is increased by theshort_exposure_factor * stock_price. Values >0.0 or None are supported.short_exposure_factor (float, default=1.5) – The exposure factor when a new
shortposition 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 arelong,shortandnone.stock_value: The value of the stock during the simulation period.exposure: The accumulated exposure during the simulation period. Increased bystock_pricewhen alongposition is opened, and byshort_exposure_factor * stock_pricewhen ashortposition 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 thecurrent_price - opened_position_pricewhen alongposition is closed. Increased by theopened_position_price - current_pricewhen ashortposition is closed.balance: The balance during the simulation period. It is theearnings + 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 ofbuysignals produced during the simulation period.number_of_ignored_buy_signals: the number ofbuysignals ignored because of themax_exposurelimitation.number_of_sell_signals: the number ofsellsignals produced during the simulation period.number_of_ignored_sell_signals: the number ofsellsignals ignored because of themax_exposurelimitation.last_stock_value: The value of the stock at the end of the simulation.last_exposure: Theexposurevalue at the end of the simulation period.last_open_long_positions: The number of the still openedlongpositions at the end of the simulation period.last_open_short_positions: The number of the still openedshortpositions at the end of the simulation period.last_portfolio_value: Theportfolio_valueat the end of the simulation period.last_earnings: Theearningsat the end of the simulation period.final_balance: Thebalanceat 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_valuespassed 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_dataindex.- 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 thegetTiSimulationmethod. This code will be removed from the package in stable-release1.0.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.