tti.indicators package¶
Trading-Technical-Indicators (tti) python library
the tti.indicators package includes the implementation of all of the supported Technical Indicators.
-
class
tti.indicators.
AccumulationDistributionLine
(input_data, fill_missing_values=True)¶ Bases:
tti.indicators._technical_indicator.TechnicalIndicator
Accumulation Distribution Line Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,close
,volume
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Average True Range Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Bollinger 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_data
after preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex
. It contains three columns, themiddle_band
,upper_band
andlower_band
._properties (dict) – Indicator properties.
_calling_instance (str) – The name of the class.
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotEnoughInputData – Not enough data for calculating the indicator.
TypeError – Type error occurred when validating the
input_data
.ValueError – Value error occurred when validating the
input_data
.
-
getTiData
()¶ Returns the Technical Indicator values for the whole period.
- Returns
The Technical Indicator values.
- Return type
pandas.DataFrame
-
getTiGraph
()¶ Generates a plot customized for each Technical Indicator.
- Returns
The generated plot.
- Return type
matplotlib.pyplot
-
getTiSignal
()¶ Calculates and returns the trading signal for the calculated technical indicator.
- Returns
The calculated trading signal.
- Return type
{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}
-
getTiSimulation
(close_values, max_exposure=None, short_exposure_factor=1.5)¶ Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Chaikin Money Flow Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,close
,volume
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Chaikin Oscillator Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,close
,volume
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Chande Momentum Oscillator Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns is``close``. The index is of type
pandas.DatetimeIndex
.period (int, default=5) – The past periods to be used for the calculation of the indicator.
fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.
- Variables
_input_data (pandas.DataFrame) – The
input_data
after preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex
. It contains one column, 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Commodity Channel Index Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Detrended Price Oscillator Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns is
close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Directional Movement Index Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,close
. The index is of 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_data
after preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex
. It contains three columns, the+di
,-di
,dx
,adx
and 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Double Exponential Moving Average Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns is
close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Ease Of Movement Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,volume
. The index is of 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_data
after preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex
. It contains two columns, theemv
and 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Envelopes 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_data
after preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex
. It contains two columns, theupper_band
and 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Fibonacci 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_data
after 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.8
andrl_100.0
._properties (dict) – Indicator properties.
_calling_instance (str) – The name of the class.
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotEnoughInputData – Not enough data for calculating the indicator.
TypeError – Type error occurred when validating the
input_data
.ValueError – Value error occurred when validating the
input_data
.
-
getTiData
()¶ Returns the Technical Indicator values for the whole period.
- Returns
The Technical Indicator values.
- Return type
pandas.DataFrame
-
getTiGraph
()¶ Generates a plot customized for each Technical Indicator.
- Returns
The generated plot.
- Return type
matplotlib.pyplot
-
getTiSignal
()¶ Calculates and returns the trading signal for the calculated technical indicator.
- Returns
The calculated trading signal.
- Return type
{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}
-
getTiSimulation
(close_values, max_exposure=None, short_exposure_factor=1.5)¶ Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Forecast 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Ichimoku Cloud Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Intraday Movement Index Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
open
,close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Klinger Oscillator Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,close
,volume
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Linear 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Linear Regression Slope Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Market Facilitation Index Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,volume
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Mass Index Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Median Price Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Momentum 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
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=20) – The past periods to be used for the calculation of the moving average. 5-13 days are for Very Short Term, 14-25 days are for Short Term, 26-49 days are for Minor Intermediate, 50-100 days for Intermediate and 100-200 days are for Long Term.
ma_type (str, default=’simple’) – The type of the calculated moving average. Supported values are
simple
,exponential
,time_series
,triangular
andvariable
.fill_missing_values (bool, default is True) – If set to True, missing values in the input data are being filled.
- Variables
_input_data (pandas.DataFrame) – The
input_data
after preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex
. It contains one column, 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Moving Average Convergence Divergence Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close
. The index is of 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_data
after preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex
. It contains two columns, themacd
and 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Negative Volume Index Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
close
,volume
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
On Balance Volume Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
close
,volume
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Parabolic SAR Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Performance 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
LONG
andSHORT
.target (numeric, default is 0.05) – The target percentage movement of the price. When mode is
LONG
the target is positive, and an exit signal is produced when the target is reached. When mode isSHORT
the target is negative, and an exit signal is produced when the target is reached.fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.
- Variables
_input_data (pandas.DataFrame) – The
input_data
after preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex
. It contains two columns, theprf
and 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Positive Volume Index Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
close
,volume
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Price And Volume Trend Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
close
,volume
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Price Channel Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,close
. The index is of 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_data
after preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex
. It contains two columns, thehighest_high
and 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Price Oscillator Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is close`. The index is of type
pandas.DatetimeIndex
.long_ma (int, default=30) – The periods to be used for the calculation of the Long Moving Average.
short_ma (int, default=10) – The periods to be used for the calculation of the Short Moving Average.
fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.
- Variables
_input_data (pandas.DataFrame) – The
input_data
after preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex
. It contains one column, 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Price Rate Of Change Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Projection Bands Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Projection Oscillator Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,close
. The index is of 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_data
after preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex
. It contains two columns, theposc
and 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Qstick 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Range Indicator Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,close
,volume
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Relative Momentum Index Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Relative Strength Index Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Relative Volatility Index Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Standard 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Stochastic Momentum Index Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Stochastic Oscillator Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,close
. The index is of 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.
1
is considered asFast Stochastic
and3
is considered asSlow Stochastic
.d_periods (int, default=3) – Periods to be used when calculating the moving average
%D
of%K
.d_method (str, default=’simple’) – The moving average to be used when calculating
%D
. Supported values aresimple
for Simple Moving Average andexponential
for Exponential Moving Average. More methods can be supported in a future release.fill_missing_values (bool, default=True) – If set to True, missing values in the input data are being filled.
- Variables
_input_data (pandas.DataFrame) – The
input_data
after preprocessing._ti_data (pandas.DataFrame) – The calculated indicator. Index is of type
pandas.DatetimeIndex
. It contains two columns: the stochastic oscillator%K
and the moving average of%K
the%D
._properties (dict) – Indicator properties.
_calling_instance (str) – The name of the class.
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotEnoughInputData – Not enough data for calculating the indicator.
TypeError – Type error occurred when validating the
input_data
.ValueError – Value error occurred when validating the
input_data
.
-
getTiData
()¶ Returns the Technical Indicator values for the whole period.
- Returns
The Technical Indicator values.
- Return type
pandas.DataFrame
-
getTiGraph
()¶ Generates a plot customized for each Technical Indicator.
- Returns
The generated plot.
- Return type
matplotlib.pyplot
-
getTiSignal
()¶ Calculates and returns the trading signal for the calculated technical indicator.
- Returns
The calculated trading signal.
- Return type
{(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)}
-
getTiSimulation
(close_values, max_exposure=None, short_exposure_factor=1.5)¶ Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. With a
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Swing Index Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
open
,high
,low
,close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Time Series Forecast Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Triple Exponential Moving Average Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Typical Price Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Ultimate Oscillator Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Vertical Horizontal Filter Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Volatility Chaikins Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Volume 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Volume Rate of Change Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input column is
volume
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Weighted Close Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Wilders 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Williams Accumulation Distribution Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. 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.TechnicalIndicator
Williams %R Technical Indicator class implementation.
- Parameters
input_data (pandas.DataFrame) – The input data. Required input columns are
high
,low
,close
. The index is of 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_data
after 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
buy
trading signal a newlong
position is opened. With asell
trading signal a newshort
position is opened. Opened positions are scanned on each simulation round, and if conditions are met (current stock price > bought price for openedlong
positions and current stock price < bought price for openedshort
positions) the positions are being closed. Only one stock piece is used in each open transaction.- Parameters
close_values (pandas.DataFrame) – The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex with same values as the input to the indicator data. It contains one column
close
.max_exposure (float, default=None) – Maximum allowed exposure for all the opened positions (
short
andlong
). 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 newlong
position is opened, exposure is increased by thestock_price
. When ashort
position 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
short
position is opened. Usually is above 1.0 and it is used as security when a short position is opened. Values >=1.0 are supported.
- Returns
Dataframe which holds details about the trading simulation executed, dictionary which holds statistics about the simulation and a graph which displays the stock price, the exposure, and the balance during the simulation.
The index of the dataframe is the whole trading period (DateTimeIndex).Columns are:
signal
: the signal produced at each day of the simulation period.open_trading_action
: the open trading action applied. Possible values arelong
,short
andnone
.stock_value
: The value of the stock during the simulation period.exposure
: The accumulated exposure during the simulation period. Increased bystock_price
when along
position is opened, and byshort_exposure_factor * stock_price
when ashort
position is opened. Reduced by the same amounts when relevant positions are being closed.portfolio_value
: The portfolio value during the simulation period,current_stock_price * (opened_long - opened_short)
.earnings
: The accumulated earnings during the simulation period. Increased by thecurrent_price - opened_position_price
when along
position is closed. Increased by theopened_position_price - current_price
when ashort
position 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 ofbuy
signals produced during the simulation period.number_of_ignored_buy_signals
: the number ofbuy
signals ignored because of themax_exposure
limitation.number_of_sell_signals
: the number ofsell
signals produced during the simulation period.number_of_ignored_sell_signals
: the number ofsell
signals ignored because of themax_exposure
limitation.last_stock_value
: The value of the stock at the end of the simulation.last_exposure
: Theexposure
value at the end of the simulation period.last_open_long_positions
: The number of the still openedlong
positions at the end of the simulation period.last_open_short_positions
: The number of the still openedshort
positions at the end of the simulation period.last_portfolio_value
: Theportfolio_value
at the end of the simulation period.last_earnings
: Theearnings
at the end of the simulation period.final_balance
: Thebalance
at the end of the simulation period.- Return type
(pandas.DataFrame, dict, matplotlib.pyplot)
- Raises
WrongTypeForInputParameter – Input argument has wrong type.
WrongValueForInputParameter – Unsupported value for input argument.
NotValidInputDataForSimulation – Invalid
close_values
passed for the simulation.
-
getTiValue
(date=None)¶ Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry.
- Parameters
date (str, default=None) – A date string, in the same format as the format of the
input_data
index.- Returns
The value of the Technical Indicator for the given date. If none value found for the given date, returns None.
- Return type
[float] or None
-
runSimulation
(close_values, max_items_per_transaction=1, max_investment=0.0)¶ Deprecated method since release
0.1.b3
. Replaced by thegetTiSimulation
method. This code will be removed from the package in stable-release1.0
.- Raises
TtiPackageDeprecatedMethod – Method is deprecated.