### Install project dependencies Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/CONTRIBUTING.md Installs the project in editable mode along with development tools. ```shell pip install -e '.[dev]' ``` -------------------------------- ### Install TTI Library Source: https://context7.com/vsaveris/trading-technical-indicators/llms.txt Commands to install the stable release via pip or clone the development version from GitHub. ```bash # Stable release pip install tti # Development version git clone https://github.com/vsaveris/trading-technical-indicators.git pip install . ``` -------------------------------- ### Install TTI Unreleased Development Version Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/README.md Clone the repository and install the development version for the latest features and fixes. ```bash git clone https://github.com/vsaveris/trading-technical-indicators.git pip install . ``` -------------------------------- ### Install the latest version of tti Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/installation.md Use this command to install the most recent release of the package. ```bash $ pip install -U tti ``` -------------------------------- ### Install a specific version of tti Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/installation.md Use this command to install a specific previous release by version number. ```bash $ pip install tti==0.1.b0 ``` -------------------------------- ### Install pre-commit hooks Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/CONTRIBUTING.md Configures pre-commit hooks to run automatically before commits. ```shell pre-commit install ``` -------------------------------- ### Accumulation Distribution Line Indicator Example Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/README.md This example demonstrates how to use the Accumulation Distribution Line indicator from the TTI library. It includes reading data, calculating the indicator, retrieving values, generating signals, and plotting the graph. Ensure you have the 'SCMN.SW.csv' data file in the './data/' directory. ```python import pandas as pd from tti.indicators import AccumulationDistributionLine # Read data from csv file. Set the index to the correct column # (dates column) df = pd.read_csv('./data/SCMN.SW.csv', parse_dates=True, index_col=0) # Create indicator adl_indicator = AccumulationDistributionLine(input_data=df) # Get indicator's calculated data print('\nTechnical Indicator data:\n', adl_indicator.getTiData()) # Get indicator's value for a specific date print('\nTechnical Indicator value at 2012-09-06:', adl_indicator.getTiValue('2012-09-06')) # Get the most recent indicator's value print('\nMost recent Technical Indicator value:', adl_indicator.getTiValue()) # Get signal from indicator print('\nTechnical Indicator signal:', adl_indicator.getTiSignal()) # Show the Graph for the calculated Technical Indicator adl_indicator.getTiGraph().show() ``` -------------------------------- ### TypicalPrice Calculation Example Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/examples/indicators/README.txt Demonstrates the calculation of the TypicalPrice technical indicator. The indicator is calculated quickly (0.0 seconds) and a visualization is saved. ```python Example code execution for technical indicator: TypicalPrice - Indicator calculated in: 0.0 seconds. - Graph ./figures/example_TypicalPrice.png saved. - Technical Indicator data: tp date 2012-01-03 130.9900 2012-01-04 128.0600 2012-01-05 128.9167 2012-01-06 128.9433 2012-01-09 127.5367 ... ... 2012-09-06 143.4100 2012-09-07 144.3633 2012-09-10 142.1833 2012-09-11 141.3500 2012-09-12 140.6100 [176 rows x 1 columns] - Technical Indicator value at 2012-03-20 00:00:00 : [138.78] - Technical Indicator value at 2012-09-12 00:00:00 : [140.61] - Technical Indicator signal: ('hold', 0) ``` -------------------------------- ### UltimateOscillator Calculation Example Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/examples/indicators/README.txt Shows the calculation of the UltimateOscillator technical indicator. The calculation is efficient (0.0 seconds) and a graph is generated. ```python Example code execution for technical indicator: UltimateOscillator - Indicator calculated in: 0.0 seconds. - Graph ./figures/example_UltimateOscillator.png saved. - Technical Indicator data: uosc date 2012-01-03 NaN 2012-01-04 NaN 2012-01-05 NaN 2012-01-06 NaN 2012-01-09 NaN ... ... 2012-09-06 59.4288 2012-09-07 59.1439 2012-09-10 50.4252 2012-09-11 49.2713 2012-09-12 45.7378 [176 rows x 1 columns] - Technical Indicator value at 2012-02-01 00:00:00 : [nan] - Technical Indicator value at 2012-09-12 00:00:00 : [45.7378] - Technical Indicator signal: ('buy', -1) ``` -------------------------------- ### Python Example for Accumulation Distribution Line Indicator Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti_indicators_examples.md This script demonstrates how to use the AccumulationDistributionLine indicator from the tti.indicators package. It includes reading data, calculating the indicator, retrieving values and signals, and generating/saving graphs for both the indicator and a trading simulation. Ensure you have the necessary data file ('./data/SCMN.SW.csv') and directories ('./figures/') set up. ```python import pandas as pd from tti.indicators import AccumulationDistributionLine # Read data from csv file. Set the index to the correct column # (dates column) df = pd.read_csv('./data/SCMN.SW.csv', parse_dates=True, index_col=0) # Create indicator adl_indicator = AccumulationDistributionLine(input_data=df) # Get indicator's calculated data print('\nTechnical Indicator data:\n', adl_indicator.getTiData()) # Get indicator's value for a specific date print('\nTechnical Indicator value at 2012-09-06:', adl_indicator.getTiValue('2012-09-06')) # Get the most recent indicator's value print('\nMost recent Technical Indicator value:', adl_indicator.getTiValue()) # Get signal from indicator print('\nTechnical Indicator signal:', adl_indicator.getTiSignal()) # Show the Graph for the calculated Technical Indicator adl_indicator.getTiGraph().show() # Save the Graph for the calculated Technical Indicator adl_indicator.getTiGraph().savefig('./figures/example_AccumulationDistributionLine.png') print('\nGraph for the calculated ADL indicator data, saved.') # Execute simulation based on trading signals simulation_data, simulation_statistics, simulation_graph = \ adl_indicator.getTiSimulation( close_values=df[['close']], max_exposure=None, short_exposure_factor=1.5) print('\nSimulation Data:\n', simulation_data) print('\nSimulation Statistics:\n', simulation_statistics) # Save the Graph for the executed trading signal simulation simulation_graph.savefig('./figures/simulation_AccumulationDistributionLine.png') print('\nGraph for the executed trading signal simulation, saved.') ``` -------------------------------- ### SwingIndex Calculation Example Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/examples/indicators/README.txt Demonstrates the calculation of the SwingIndex technical indicator. The indicator is calculated in 0.0 seconds and a graph is saved. ```python Example code execution for technical indicator: SwingIndex - Indicator calculated in: 0.0 seconds. - Graph ./figures/example_SwingIndex.png saved. - Technical Indicator data: swi date 2012-01-03 NaN 2012-01-04 -50.8371 2012-01-05 40.6143 2012-01-06 -18.4259 2012-01-09 -21.8606 ... ... 2012-09-06 13.3789 2012-09-07 17.0256 2012-09-10 -65.2951 2012-09-11 -13.9607 2012-09-12 -10.4854 [176 rows x 1 columns] - Technical Indicator value at 2012-06-26 00:00:00 : [5.2975] - Technical Indicator value at 2012-09-12 00:00:00 : [-10.4854] - Technical Indicator signal: ('hold', 0) ``` -------------------------------- ### VolatilityChaikins Calculation Example Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/examples/indicators/README.txt Shows the calculation of the VolatilityChaikins technical indicator. The calculation is fast (0.0 seconds) and a graph is generated. ```python Example code execution for technical indicator: VolatilityChaikins - Indicator calculated in: 0.0 seconds. - Graph ./figures/example_VolatilityChaikins.png saved. - Technical Indicator data: vch date 2012-01-03 NaN 2012-01-04 NaN 2012-01-05 NaN 2012-01-06 NaN 2012-01-09 NaN ... ... 2012-09-06 -13.7945 2012-09-07 -24.8259 2012-09-10 -13.4037 2012-09-11 -7.1835 2012-09-12 -11.3849 [176 rows x 1 columns] - Technical Indicator value at 2012-05-21 00:00:00 : [21.2588] - Technical Indicator value at 2012-09-12 00:00:00 : [-11.3849] - Technical Indicator signal: ('hold', 0) ``` -------------------------------- ### Example Data for Technical Indicators Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti_indicators_examples.md This is a sample of the input data format expected by the tti.indicators package, specifically for the Accumulation Distribution Line. It requires 'High', 'Low', 'close', and 'Volume' columns, indexed by 'Date'. ```bash High Low close Volume Date 1998-10-05 388.084991 342.890991 369.908997 2732524.0 1998-10-06 385.628998 371.382996 385.138000 477160.0 1998-10-07 403.313995 377.769012 398.402008 647460.0 1998-10-08 396.928009 376.295013 382.190002 292460.0 1998-10-09 394.963013 386.119995 388.084991 259155.0 ``` -------------------------------- ### VerticalHorizontalFilter Calculation Example Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/examples/indicators/README.txt Illustrates the calculation of the VerticalHorizontalFilter technical indicator. The indicator is calculated in 0.0 seconds and a graph is saved. ```python Example code execution for technical indicator: VerticalHorizontalFilter - Indicator calculated in: 0.0 seconds. - Graph ./figures/example_VerticalHorizontalFilter.png saved. - Technical Indicator data: vhf date 2012-01-03 NaN 2012-01-04 NaN 2012-01-05 NaN 2012-01-06 NaN 2012-01-09 NaN ... ... 2012-09-06 0.5833 2012-09-07 0.9161 2012-09-10 0.5227 2012-09-11 0.6520 2012-09-12 0.6894 [176 rows x 1 columns] - Technical Indicator value at 2012-03-29 00:00:00 : [0.3822] - Technical Indicator value at 2012-09-12 00:00:00 : [0.6894] - Technical Indicator signal: ('buy', -1) ``` -------------------------------- ### TripleExponentialMovingAverage Calculation Example Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/examples/indicators/README.txt Shows the calculation of the TripleExponentialMovingAverage technical indicator. The indicator calculation is fast (0.0 seconds) and a corresponding graph is saved. ```python Example code execution for technical indicator: TripleExponentialMovingAverage - Indicator calculated in: 0.0 seconds. - Graph ./figures/example_TripleExponentialMovingAverage.png saved. - Technical Indicator data: tema date 2012-01-03 NaN 2012-01-04 NaN 2012-01-05 NaN 2012-01-06 NaN 2012-01-09 NaN ... ... 2012-09-06 143.1025 2012-09-07 144.0617 2012-09-10 142.2558 2012-09-11 141.2326 2012-09-12 140.4494 [176 rows x 1 columns] - Technical Indicator value at 2012-03-07 00:00:00 : [134.6989] - Technical Indicator value at 2012-09-12 00:00:00 : [140.4494] - Technical Indicator signal: ('buy', -1) ``` -------------------------------- ### GET /getTiGraph Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Generates a visualization plot for the calculated indicator. ```APIDOC ## GET /getTiGraph ### Description Generates a plot customized for each Technical Indicator. ### Method GET ### Endpoint /getTiGraph ### Response #### Success Response (200) - **plot** (matplotlib.pyplot) - The generated plot. ``` -------------------------------- ### PriceAndVolumeTrend Class Initialization Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Initializes the PriceAndVolumeTrend indicator with input data and configuration. ```APIDOC ## class tti.indicators.PriceAndVolumeTrend ### Description Initializes the Price And Volume Trend Technical Indicator. ### Parameters - **input_data** (pandas.DataFrame) - Required - The input data containing 'close' and 'volume' columns with a DatetimeIndex. - **fill_missing_values** (bool) - Optional - If True, missing values in the input data are filled. ``` -------------------------------- ### GET /ti/signal Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Calculates and returns the trading signal for the Technical Indicator. ```APIDOC ## GET /ti/signal ### Description Calculates and returns the trading signal for the calculated technical indicator. ### Method GET ### Endpoint /ti/signal ### Response #### Success Response (200) - **signal** (dict) - The calculated trading signal. Possible values are ('hold', 0), ('buy', -1), ('sell', 1). #### Response Example ```json { "signal": { "action": "buy", "code": -1 } } ``` ``` -------------------------------- ### GET /ti/graph Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Generates and returns a plot customized for the Technical Indicator. ```APIDOC ## GET /ti/graph ### Description Generates a plot customized for each Technical Indicator. ### Method GET ### Endpoint /ti/graph ### Response #### Success Response (200) - **plot** (matplotlib.pyplot) - The generated plot. #### Response Example (Binary data representing a plot image, e.g., PNG, JPEG) ``` -------------------------------- ### Build project distributions Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/CONTRIBUTING.md Builds the package using the build module. ```shell python -m pip install --upgrade build twine python -m build ``` -------------------------------- ### GET /getTiSignal Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Calculates and returns the trading signal based on the indicator. ```APIDOC ## GET /getTiSignal ### Description Calculates and returns the trading signal for the calculated technical indicator. ### Method GET ### Endpoint /getTiSignal ### Response #### Success Response (200) - **signal** (dict) - The calculated trading signal, mapping to ('hold', 0), ('buy', -1), or ('sell', 1). ``` -------------------------------- ### Run tests and linting Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/CONTRIBUTING.md Executes the test suite and runs code quality tools locally. ```shell pytest -q ``` ```shell ruff check . ruff format . ``` -------------------------------- ### GET /ti/data Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Retrieves the Technical Indicator values for the entire calculated period. ```APIDOC ## GET /ti/data ### Description Returns the Technical Indicator values for the whole period. ### Method GET ### Endpoint /ti/data ### Response #### Success Response (200) - **data** (pandas.DataFrame) - The Technical Indicator values. The index is of type `pandas.DatetimeIndex` and contains one column, the `pvi`. #### Response Example ```json { "data": { "2023-01-01": 100.5, "2023-01-02": 101.2, "2023-01-03": 102.0 } } ``` ``` -------------------------------- ### EaseOfMovement Class Initialization Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Initializes the EaseOfMovement indicator with input data and configuration parameters. ```APIDOC ## EaseOfMovement Initialization ### Description Initializes the EaseOfMovement technical indicator class. ### Parameters - **input_data** (pandas.DataFrame) - Required - Input data containing 'high', 'low', and 'volume' columns with a DatetimeIndex. - **period** (int) - Optional - The past periods for moving average calculation (default=40). - **fill_missing_values** (bool) - Optional - Whether to fill missing values in input data (default=True). ``` -------------------------------- ### GET /getTiData Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Retrieves the full set of calculated Technical Indicator values. ```APIDOC ## GET /getTiData ### Description Returns the Technical Indicator values for the whole period. ### Method GET ### Endpoint /getTiData ### Response #### Success Response (200) - **data** (pandas.DataFrame) - The Technical Indicator values. ``` -------------------------------- ### GET /ti/value Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Retrieves the Technical Indicator value for a specific date or the most recent entry. ```APIDOC ## GET /ti/value ### Description Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry. ### Method GET ### Endpoint /ti/value ### Parameters #### Query Parameters - **date** (str) - Optional - A date string, in the same format as the format of the `input_data` index. ### Response #### Success Response (200) - **value** (float or None) - The value of the Technical Indicator for the given date. If no value is found for the given date, returns None. #### Response Example ```json { "value": 123.45 } ``` ``` -------------------------------- ### Get Technical Indicator Signal Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Calculates and returns the trading signal for the Technical Indicator. ```APIDOC ## GET /api/indicators/ti_signal ### Description Calculates and returns the trading signal for the calculated technical indicator. ### Method GET ### Endpoint /api/indicators/ti_signal ### Response #### Success Response (200) - **signal** (dict) - The calculated trading signal. Possible values are ('hold', 0), ('buy', -1), ('sell', 1). #### Response Example { "signal": {"type": "buy", "value": -1} } ``` -------------------------------- ### NegativeVolumeIndex Class Initialization Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Initializes the NegativeVolumeIndex indicator with input data containing close and volume columns. ```APIDOC ## Class: tti.indicators.NegativeVolumeIndex ### Description Initializes the Negative Volume Index Technical Indicator. ### Parameters - **input_data** (pandas.DataFrame) - Required - The input data. Required input columns are `close`, `volume`. The index is of type `pandas.DatetimeIndex`. - **fill_missing_values** (bool) - Optional - If set to True, missing values in the input data are being filled. Default is True. ### Raises - **WrongTypeForInputParameter** - **WrongValueForInputParameter** - **NotEnoughInputData** - **TypeError** - **ValueError** ``` -------------------------------- ### StandardDeviation Class Initialization Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Initializes the Standard Deviation indicator with input data and configuration parameters. ```APIDOC ## Class: tti.indicators.StandardDeviation ### Description Standard Deviation Technical Indicator class implementation. ### Parameters - **input_data** (pandas.DataFrame) - Required - The input data. Required input column is `close`. The index is of type `pandas.DatetimeIndex`. - **period** (int) - Optional (default=20) - The past periods to be used for the calculation of the simple moving average. - **fill_missing_values** (bool) - Optional (default=True) - If set to True, missing values in the input data are being filled. ``` -------------------------------- ### Get Technical Indicator Graph Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Generates and returns a plot customized for the Technical Indicator. ```APIDOC ## GET /api/indicators/ti_graph ### Description Generates a plot customized for each Technical Indicator. ### Method GET ### Endpoint /api/indicators/ti_graph ### Response #### Success Response (200) - **plot** (matplotlib.pyplot) - The generated plot. #### Response Example (Image data or plot object representation) ``` -------------------------------- ### Upload to PyPI Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/CONTRIBUTING.md Uploads the built distributions to PyPI using twine. ```shell twine upload dist/* ``` -------------------------------- ### GET /getTiValue Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Retrieves the Technical Indicator value for a specific date or the most recent entry. ```APIDOC ## GET /getTiValue ### Description Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry. ### Method GET ### Endpoint /getTiValue ### Parameters #### Query Parameters - **date** (str) - Optional - A date string, in the same format as the input_data index. ### Response #### Success Response (200) - **value** (float or None) - The value of the Technical Indicator for the given date. ``` -------------------------------- ### Get Technical Indicator Data Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Retrieves all calculated Technical Indicator values for the entire period. ```APIDOC ## GET /api/indicators/ti_data ### Description Returns the Technical Indicator values for the whole period. ### Method GET ### Endpoint /api/indicators/ti_data ### Response #### Success Response (200) - **data** (pandas.DataFrame) - The Technical Indicator values. #### Response Example { "data": { "2023-01-01": {"obv": 1000.0}, "2023-01-02": {"obv": 1200.0} } } ``` -------------------------------- ### Create and Use Stochastic Oscillator (%K and %D) Source: https://context7.com/vsaveris/trading-technical-indicators/llms.txt Instantiate Stochastic Oscillator to generate %K and %D lines. Supports Fast (k_slowing_periods=1) and Slow (k_slowing_periods=3) variants with configurable smoothing and methods. Identifies overbought (>80) and oversold (<20) conditions. ```python import pandas as pd from tti.indicators import StochasticOscillator df = pd.read_csv('./data/stock_data.csv', parse_dates=True, index_col=0) # Fast Stochastic (default) fast_stoch = StochasticOscillator( input_data=df, k_periods=14, k_slowing_periods=1, # Fast d_periods=3, d_method='simple' ) # Slow Stochastic (smoother, fewer false signals) slow_stoch = StochasticOscillator( input_data=df, k_periods=14, k_slowing_periods=3, # Slow d_periods=3, d_method='exponential' ) # Get %K and %D values ti_data = slow_stoch.getTiData() print("Stochastic values:\n", ti_data.tail()) # Output columns: %K, %D # Get trading signal signal = slow_stoch.getTiSignal() print(f"Signal: {signal}") # Sell signals: # - %K or %D falls below 80 from above # - %K crosses below %D in overbought region (>80) # Buy signals: ``` -------------------------------- ### WilliamsR Indicator - Get Technical Indicator Data Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Retrieves all calculated Technical Indicator values for the entire period. ```APIDOC ## GET /api/indicators/williamsr/data ### Description Returns the Technical Indicator values for the whole period. ### Method GET ### Endpoint /api/indicators/williamsr/data ### Response #### Success Response (200) - **data** (pandas.DataFrame) - The Technical Indicator values. Index is of type pandas.DatetimeIndex. It contains one column, the `wr`. #### Response Example ```json { "data": { "2023-01-01": -0.25, "2023-01-02": -0.50, "2023-01-03": -0.75 } } ``` ``` -------------------------------- ### Forecast Oscillator Initialization Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Initializes the Forecast Oscillator indicator with input data and configuration parameters. ```APIDOC ## POST /indicators/forecast-oscillator ### Description Initializes the Forecast Oscillator indicator class with the provided input data and calculation parameters. ### Parameters #### Request Body - **input_data** (pandas.DataFrame) - Required - The input data containing a 'close' column with a DatetimeIndex. - **period** (int) - Optional - The number of past periods to use for calculation (default=14). - **fill_missing_values** (bool) - Optional - Whether to fill missing values in the input data (default=True). ``` -------------------------------- ### Chande Momentum Oscillator (CMO) - Get Indicator Graph Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Generates and returns a plot of the Chande Momentum Oscillator. ```APIDOC ## GET /api/indicators/cmo/graph ### Description Generates a plot customized for the Chande Momentum Oscillator. ### Method GET ### Endpoint /api/indicators/cmo/graph ### Response #### Success Response (200) - **graph** (matplotlib.pyplot) - The generated plot. #### Response Example (Image data or plot object representation) ``` -------------------------------- ### POST /getTiSimulation Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Executes a trading simulation based on technical indicator signals, managing positions and calculating performance metrics. ```APIDOC ## POST /getTiSimulation ### Description Executes a trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. It tracks long and short positions, exposure limits, and portfolio balance. ### Method POST ### Endpoint /getTiSimulation ### Parameters #### Request Body - **close_values** (pandas.DataFrame) - Required - The close prices of the stock for the simulation period. Index is DateTimeIndex, contains column 'close'. - **max_exposure** (float) - Optional - Maximum allowed exposure for all opened positions. Defaults to None. - **short_exposure_factor** (float) - Optional - The exposure factor when a new short position is opened. Defaults to 1.5. ### Response #### Success Response (200) - **Dataframe** (pandas.DataFrame) - Contains simulation details: signal, open_trading_action, stock_value, exposure, portfolio_value, earnings, balance. - **Statistics** (dict) - Contains simulation stats: number_of_trading_days, number_of_buy_signals, number_of_ignored_buy_signals, number_of_sell_signals, number_of_ignored_sell_signals, last_stock_value, last_exposure, last_open_long_positions, last_open_short_positions, last_portfolio_value, last_earnings, final_balance. - **Graph** (matplotlib.pyplot) - Visual representation of stock price, exposure, and balance. ### Errors - **WrongTypeForInputParameter**: Input argument has wrong type. - **WrongValueForInputParameter**: Unsupported value for input argument. - **NotValidInputDataForSimulation**: Invalid close_values passed for the simulation. ``` -------------------------------- ### WilliamsR Indicator - Get Trading Signal Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Calculates and returns the trading signal based on the Williams %R Technical Indicator. ```APIDOC ## GET /api/indicators/williamsr/signal ### Description Calculates and returns the trading signal for the calculated technical indicator. ### Method GET ### Endpoint /api/indicators/williamsr/signal ### Response #### Success Response (200) - **signal** (string) - The calculated trading signal. Possible values are 'hold', 'buy', or 'sell'. #### Response Example ```json { "signal": "buy" } ``` ``` -------------------------------- ### VolumeRateOfChange Initialization and Methods Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md This section details the initialization of the Volume Rate of Change (VRC) indicator and its associated methods for retrieving data, graphs, and trading signals. ```APIDOC ## Class: tti.indicators.VolumeRateOfChange ### Description Volume Rate of Change Technical Indicator class implementation. ### Parameters #### Path Parameters - **input_data** (pandas.DataFrame) - Required - The input data. Required input column is `volume`. The index is of type `pandas.DatetimeIndex`. - **period** (int) - Optional - The past periods to be used for the calculation of the indicator. Default is 5. - **fill_missing_values** (bool) - Optional - If set to True, missing values in the input data are being filled. Default is True. ### Methods #### getTiValue(date=None) ##### Description Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry. ##### Parameters - **date** (str) - Optional - A date string, in the same format as the format of the `input_data` index. Default is None. ##### 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 #### getTiData() ##### Description Returns the Technical Indicator values for the whole period. ##### Returns - The Technical Indicator values. - **Return type**: pandas.DataFrame #### getTiGraph() ##### Description Generates a plot customized for each Technical Indicator. ##### Returns - The generated plot. - **Return type**: matplotlib.pyplot #### getTiSignal() ##### Description Calculates and returns the trading signal for the calculated technical indicator. ##### Returns - The calculated trading signal. - **Return type**: {(‘hold’, 0), (‘buy’, -1), (‘sell’, 1)} ``` -------------------------------- ### WilliamsR Indicator - Get Technical Indicator Graph Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Generates and returns a plot customized for the Williams %R Technical Indicator. ```APIDOC ## GET /api/indicators/williamsr/graph ### Description Generates a plot customized for the Williams %R Technical Indicator. ### Method GET ### Endpoint /api/indicators/williamsr/graph ### Response #### Success Response (200) - **plot** (matplotlib.pyplot) - The generated plot. #### Response Example (Image data or plot object representation) ``` -------------------------------- ### Stochastic Momentum Index (SMI) - Get Indicator Graph Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Generates and returns a plot customized for the Stochastic Momentum Index. ```APIDOC ## GET /api/indicators/smi/graph ### Description Generates a plot customized for the Stochastic Momentum Index. ### Method GET ### Endpoint /api/indicators/smi/graph ### Response #### Success Response (200) - **graph** (matplotlib.pyplot) - The generated plot. #### Response Example (Image data or plot object representation) ``` -------------------------------- ### POST /getTiSimulation Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Executes a trading simulation based on technical indicator signals, managing long and short positions with exposure constraints. ```APIDOC ## POST /getTiSimulation ### Description Executes a trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. It manages long and short positions and calculates performance metrics. ### Method POST ### Endpoint /getTiSimulation ### Parameters #### Request Body - **close_values** (pandas.DataFrame) - Required - The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex. Contains one column `close`. - **max_exposure** (float) - Optional - Maximum allowed exposure for all opened positions. Defaults to None. - **short_exposure_factor** (float) - Optional - The exposure factor when a new short position is opened. Defaults to 1.5. ### Response #### Success Response (200) - **Returns** (tuple) - A tuple containing a pandas.DataFrame (simulation details), a dict (statistics), and a matplotlib.pyplot (graph). #### Error Handling - **WrongTypeForInputParameter**: Raised if an input argument has the wrong type. - **WrongValueForInputParameter**: Raised if an unsupported value is passed for an input argument. - **NotValidInputDataForSimulation**: Raised if invalid `close_values` are passed. ``` -------------------------------- ### POST /getTiSimulation Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Executes a trading simulation based on technical indicator signals, managing long and short positions with configurable exposure limits. ```APIDOC ## POST /getTiSimulation ### Description Executes a trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. It tracks long and short positions and calculates performance metrics. ### Method POST ### Endpoint /getTiSimulation ### Parameters #### Request Body - **close_values** (pandas.DataFrame) - Required - The close prices of the stock for the simulation period. Index is DateTimeIndex, contains column 'close'. - **max_exposure** (float) - Optional - Maximum allowed exposure for all opened positions. Defaults to None. - **short_exposure_factor** (float) - Optional - The exposure factor when a new short position is opened. Defaults to 1.5. ### Response #### Success Response (200) - **Returns** (tuple) - A tuple containing a pandas.DataFrame (simulation details), a dict (statistics), and a matplotlib.pyplot (graph). ### Errors - **WrongTypeForInputParameter**: Input argument has wrong type. - **WrongValueForInputParameter**: Unsupported value for input argument. - **NotValidInputDataForSimulation**: Invalid close_values passed for the simulation. ``` -------------------------------- ### Get Technical Indicator Value Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Retrieves the Technical Indicator value for a specific date or the most recent entry if no date is provided. ```APIDOC ## GET /api/indicators/ti_value ### Description Returns the Technical Indicator value for a given date. If the date is None, it returns the most recent entry. ### Method GET ### Endpoint /api/indicators/ti_value ### Parameters #### Query Parameters - **date** (str) - Optional - A date string, in the same format as the format of the `input_data` index. ### Response #### Success Response (200) - **value** (float or None) - The value of the Technical Indicator for the given date. If no value is found for the given date, returns None. #### Response Example { "value": 123.45 } ``` -------------------------------- ### PriceRateOfChange Class Initialization Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Initializes the PriceRateOfChange indicator with input data and configuration parameters. ```APIDOC ## class tti.indicators.PriceRateOfChange ### Description Initializes the Price Rate Of Change Technical Indicator. ### Parameters - **input_data** (pandas.DataFrame) - Required - The input data containing a 'close' column with a pandas.DatetimeIndex. - **period** (int) - Optional - The past periods to be used for calculation (default=25). - **fill_missing_values** (bool) - Optional - Whether to fill missing values in input data (default=True). ``` -------------------------------- ### Moving Average Indicator Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Implementation of the Moving Average technical indicator, including methods to get data, graph, and signals. ```APIDOC ## Class tti.indicators.MovingAverage ### Description Moving Average Technical Indicator class implementation. ### Parameters #### Constructor Parameters - **input_data** (pandas.DataFrame) - Required - The input data. Required input column is `close`. The index is of type `pandas.DatetimeIndex`. - **period** (int) - Optional, 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 are for Intermediate and 100-200 days are for Long Term. - **ma_type** (str) - Optional, default='simple' - The type of the calculated moving average. Supported values are `simple`, `exponential`, `time_series`, `triangular` and `variable`. - **fill_missing_values** (bool) - Optional, default=True - If set to True, missing values in the input data are being filled. ### Methods #### getTiData() ##### Description Returns the Technical Indicator values for the whole period. ##### Returns - **ti_data** (pandas.DataFrame) - The Technical Indicator values. Index is of type `pandas.DatetimeIndex`. It contains one column, the `ma`. #### getTiGraph() ##### Description Generates a plot customized for each Technical Indicator. ##### Returns - **plot** (matplotlib.pyplot) - The generated plot. #### getTiSignal() ##### Description Calculates and returns the trading signal for the calculated technical indicator. ##### Returns - **signal** ({'hold', 0}, {'buy', -1}, {'sell', 1}) - The calculated trading signal. ### 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`. ``` -------------------------------- ### POST /getTiSimulation Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Executes a trading simulation based on technical indicator signals, managing long and short positions with optional exposure constraints. ```APIDOC ## POST /getTiSimulation ### Description Executes trading simulation based on the trading signals produced by the technical indicator, by applying an Active trading strategy. It tracks long and short positions and calculates performance metrics. ### Method POST ### Endpoint /getTiSimulation ### Parameters #### Request Body - **close_values** (pandas.DataFrame) - Required - The close prices of the stock, for the whole simulation period. Index is of type DateTimeIndex. Contains one column `close`. - **max_exposure** (float) - Optional - Maximum allowed exposure for all opened positions. Defaults to None. - **short_exposure_factor** (float) - Optional - The exposure factor when a new short position is opened. Defaults to 1.5. ### Response #### Success Response (200) - **Returns** (tuple) - A tuple containing a pandas.DataFrame (simulation details), a dict (statistics), and a matplotlib.pyplot (graph). ### Errors - **WrongTypeForInputParameter**: Input argument has wrong type. - **WrongValueForInputParameter**: Unsupported value for input argument. - **NotValidInputDataForSimulation**: Invalid close_values passed for the simulation. ``` -------------------------------- ### Trading Simulation with Accumulation Distribution Line Source: https://context7.com/vsaveris/trading-technical-indicators/llms.txt Runs backtesting simulations using the built-in trading engine. Evaluates indicator performance by simulating trades based on signals. Requires pandas and AccumulationDistributionLine. ```python import pandas as pd from tti.indicators import AccumulationDistributionLine df = pd.read_csv('./data/SCMN.SW.csv', parse_dates=True, index_col=0) # Create indicator adl = AccumulationDistributionLine(input_data=df) # Run trading simulation simulation_data, statistics, simulation_graph = adl.getTiSimulation( close_values=df[['close']], # Must be DataFrame with 'close' column max_exposure=None, # None = unlimited, or set max capital at risk short_exposure_factor=1.5 # Multiplier for short position exposure ) # View simulation results print("Simulation Data (last 5 days):\n", simulation_data.tail()) # Columns: signal, open_trading_action, stock_value, exposure, # portfolio_value, earnings, balance # View simulation statistics print("\nSimulation Statistics:") for key, value in statistics.items(): print(f" {key}: {value}") # Output includes: # number_of_trading_days: 5651 # number_of_buy_signals: 4767 # number_of_sell_signals: 601 # last_stock_value: 475.5 # last_exposure: 22340.73 # last_open_long_positions: 40 # last_open_short_positions: 0 # last_earnings: 19817.21 # final_balance: 38837.21 ``` -------------------------------- ### Create and Use Moving Averages (SMA, EMA, TSMA, TMA, VMA) Source: https://context7.com/vsaveris/trading-technical-indicators/llms.txt Instantiate various Moving Average types (simple, exponential, time-series, triangular, variable) with specified periods. Retrieve indicator data, trading signals, and current values. Different periods are suitable for different analysis timeframes. ```python import pandas as pd from tti.indicators import MovingAverage df = pd.read_csv('./data/stock_data.csv', parse_dates=True, index_col=0) # Simple Moving Average (SMA) sma = MovingAverage(input_data=df, period=20, ma_type='simple') # Exponential Moving Average (EMA) - more weight to recent prices ema = MovingAverage(input_data=df, period=20, ma_type='exponential') # Time-Series Moving Average (TSMA) tsma = MovingAverage(input_data=df, period=20, ma_type='time_series') # Triangular Moving Average (TMA) - double-smoothed tma = MovingAverage(input_data=df, period=20, ma_type='triangular') # Variable Moving Average (VMA) - volatility-adjusted vma = MovingAverage(input_data=df, period=20, ma_type='variable') # Get calculated values print("SMA values:\n", sma.getTiData().tail()) # Output column: ma-simple (or ma-exponential, etc.) # Get trading signal signal = sma.getTiSignal() print(f"Signal: {signal}") # Returns ('buy', -1) when close > MA # Returns ('hold', 0) otherwise # Compare multiple MAs print(f"SMA: {sma.getTiValue()[0]:.2f}") print(f"EMA: {ema.getTiValue()[0]:.2f}") ``` -------------------------------- ### VolatilityChaikins Class Initialization Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Initializes the Volatility Chaikins indicator with input data and configuration parameters. ```APIDOC ## Class: tti.indicators.VolatilityChaikins ### Description Initializes the Volatility Chaikins Technical Indicator class. ### Parameters - **input_data** (pandas.DataFrame) - Required - Input data containing 'high' and 'low' columns with a DatetimeIndex. - **ema_period** (int) - Optional - Periods for EMA calculation (default=10). - **change_period** (int) - Optional - Period for calculating change (default=10). - **fill_missing_values** (bool) - Optional - Whether to fill missing values (default=True). ``` -------------------------------- ### TimeSeriesForecast Calculation Example Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/examples/indicators/README.txt Illustrates the calculation of the TimeSeriesForecast technical indicator. The calculation time is 0.0 seconds and a graph is generated. ```python Example code execution for technical indicator: TimeSeriesForecast - Indicator calculated in: 0.0 seconds. - Graph ./figures/example_TimeSeriesForecast.png saved. - Technical Indicator data: tsf date 2012-01-03 NaN 2012-01-04 NaN 2012-01-05 NaN 2012-01-06 NaN 2012-01-09 NaN ... ... 2012-09-06 143.0036 2012-09-07 143.2993 2012-09-10 142.5787 2012-09-11 141.7865 2012-09-12 141.1675 [176 rows x 1 columns] - Technical Indicator value at 2012-08-15 00:00:00 : [137.5237] - Technical Indicator value at 2012-09-12 00:00:00 : [141.1675] - Technical Indicator signal: ('hold', 0) ``` -------------------------------- ### POST /getTiSimulation Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Executes a trading simulation based on technical indicator signals, applying an active strategy to open and close long and short positions. ```APIDOC ## POST /getTiSimulation ### Description Executes a trading simulation based on the trading signals produced by the technical indicator. It manages long and short positions and tracks portfolio performance metrics. ### Method POST ### Endpoint /getTiSimulation ### Parameters #### Request Body - **close_values** (pandas.DataFrame) - Required - The close prices of the stock for the simulation period. Index is DateTimeIndex, contains column 'close'. - **max_exposure** (float) - Optional - Maximum allowed exposure for all opened positions. Defaults to None. - **short_exposure_factor** (float) - Optional - The exposure factor when a new short position is opened. Defaults to 1.5. ### Response #### Success Response (200) - **DataFrame** (pandas.DataFrame) - Contains simulation details: signal, open_trading_action, stock_value, exposure, portfolio_value, earnings, balance. - **Statistics** (dict) - Contains simulation statistics: number_of_trading_days, number_of_buy_signals, number_of_ignored_buy_signals, number_of_sell_signals, number_of_ignored_sell_signals, last_stock_value, last_exposure, last_open_long_positions, last_open_short_positions, last_portfolio_value, last_earnings, final_balance. - **Graph** (matplotlib.pyplot) - A graph displaying stock price, exposure, and balance. ``` -------------------------------- ### Stochastic Momentum Index (SMI) - Get Indicator Data Source: https://github.com/vsaveris/trading-technical-indicators/blob/master/docs/source/tti.indicators.md Retrieves the full Technical Indicator values for the entire calculated period. ```APIDOC ## GET /api/indicators/smi/data ### Description Returns the Technical Indicator values for the whole period. ### Method GET ### Endpoint /api/indicators/smi/data ### Response #### Success Response (200) - **data** (pandas.DataFrame) - The Technical Indicator values. Index is of type pandas.DatetimeIndex. It contains one column, the `smi`. #### Response Example ```json { "data": { "2023-01-01": 0.75, "2023-01-02": 0.80, "2023-01-03": 0.78 } } ``` ```