The augment_atr function is used to calculate Average True Range (ATR) and Normalized Average True Range (NATR) for a given dataset and return the augmented dataset. Set the normalize parameter to True to calculate NATR.
The data parameter is the input data that can be either a pandas DataFrame or a pandas DataFrameGroupBy object. It contains the data on which the Bollinger Bands will be calculated.
required
date_column
str
The date_column parameter is a string that specifies the name of the column in the data DataFrame that contains the dates.
required
high_column
str
The high_column parameter is a string that specifies the name of the column in the data DataFrame that contains the high prices of the asset.
required
low_column
str
The low_column parameter is a string that specifies the name of the column in the data DataFrame that contains the low prices of the asset.
required
close_column
str
The close_column parameter is a string that specifies the name of the column in the data DataFrame that contains the closing prices of the asset.
required
periods
Union[int, Tuple[int, int], List[int]]
The periods parameter in the augment_atr function can be specified as an integer, a tuple, or a list. This parameter specifies the number of rolling periods to use when calculating the ATR.
20
normalize
bool
The normalize parameter is a boolean flag that indicates whether or not to normalize the ATR values. If set to True, the function will normalize the ATR values to express this volatility as a percentage of the closing price.
False
reduce_memory
bool
The reduce_memory parameter is a boolean flag that indicates whether or not to reduce the memory usage of the input data before performing the calculation. If set to True, the function will attempt to reduce the memory usage of the input data using techniques such as downcasting numeric columns and converting object columns
False
engine
str
The engine parameter specifies the computation engine to use for calculating the Bollinger Bands. It can take two values: โpandasโ or โpolarsโ. If โpandasโ is selected, the function will use the pandas library for computation. If โpolarsโ is selected,
'pandas'
Returns
Type
Description
pd.DataFrame
The function augment_atr returns a pandas DataFrame.
Notes
ATR (Average True Range)
The Average True Range (ATR) is a technical analysis indicator used to measure market volatility. It was introduced by J. Welles Wilder Jr. in his 1978 book โNew Concepts in Technical Trading Systems.โ
The ATR is calculated as follows:
True Range: For each period (typically a day), the True Range is the greatest of the following:
The current high minus the current low.
The absolute value of the current high minus the previous close.
The absolute value of the current low minus the previous close.
Average True Range: The ATR is an average of the True Range over a specified number of periods (commonly 14 days).
NATR (Normalized Average True Range)
The NATR (Normalized Average True Range) is a variation of the ATR that normalizes the ATR values to express this volatility as a percentage of the closing price.
The NATR (normalize = True) is calculated as follows: NATR = (ATR / Close) * 100
Examples
import pandas as pdimport pytimetk as tkdf = tk.load_dataset("stocks_daily", parse_dates = ['date'])df