strategy.utils.price_model
np
pd
BaseModel
PriceModel Objects
class PriceModel(BaseModel)
__init__
def __init__(data)
Initialize the PriceModel with data.
Arguments:
data
: DataFrame with OHLCV columns or Series/array-like of close prices.
raw
def raw()
Return the raw price data without any transformation.
Returns:
Series, the original price data.
sma
def sma(window)
Calculate the Simple Moving Average (SMA).
Arguments:
window
: Integer, the window size for SMA.
Returns:
Series, the SMA values.
ema
def ema(window)
Calculate the Exponential Moving Average (EMA).
Arguments:
window
: Integer, the window size for EMA.
Returns:
Series, the EMA values.
hma
def hma(window)
Calculate the Hull Moving Average (HMA).
Arguments:
window
: Integer, the window size for HMA.
Returns:
Series, the HMA values.
wma
def wma(window)
Calculate the Weighted Moving Average (WMA).
Arguments:
window
: Integer, the window size for WMA.
Returns:
Series, the WMA values.
tma
def tma(window)
Calculate the Triangular Moving Average (TMA).
Arguments:
window
: Integer, the window size for TMA.
Returns:
Series, the TMA values.
kama
def kama(window)
Calculate the Kaufman's Adaptive Moving Average (KAMA).
Arguments:
window
: Integer, the window size for KAMA.
Returns:
Series, the KAMA values.
model
def model(model_type, window)
Select the price model to use.
Arguments:
model_type
: String, the type of model ('raw', 'sma', 'ema', 'hma', 'wma', 'tma', 'kama').window
: Integer, the window size for the model. Not used for 'raw' model type.
Returns:
Series, the calculated model values.
get_data_window
@classmethod
def get_data_window(cls, model_type, window)
Calculate the required minimum data length for each model type.
Note: These are minimum requirements. For better initialization, especially for models like EMA, consider using 2x or 3x the window size.
Arguments:
model_type
: String, the type of model ('raw', 'sma', 'ema', 'hma', 'wma', 'tma', 'kama').window
: Integer, the window size for the model. Not used for 'raw' model type.
Returns:
Integer, the required data length for the specified model.