Skip to content

turtle_quant_1.strategies.helpers.support_resistance.stnry_gaussian_kde

turtle_quant_1.strategies.helpers.support_resistance.stnry_gaussian_kde

Stationary Gaussian KDE support and resistance strategy.

StnryGaussianKde

StnryGaussianKde()

Bases: BaseSupResStrategy

Stationary Gaussian KDE support and resistance strategy.

Refer to: - https://github.com/neurotrader888/TechnicalAnalysisAutomation/blob/main/mp_support_resist.py - https://www.youtube.com/watch?v=mNWPSFOVoYA

This strategy identifies support and resistance levels by using Gaussian KDE to identify significant peaks in the market profile.

Initialize the StnryGaussianKde strategy.

Source code in src/turtle_quant_1/strategies/helpers/support_resistance/stnry_gaussian_kde.py
def __init__(self):
    """Initialize the StnryGaussianKde strategy."""
    super().__init__()

generate_historical_levels

generate_historical_levels(
    data: DataFrame, symbol: str
) -> DataFrame

Generate Gaussian KDE levels for historical data.

Parameters:

Name Type Description Default
data DataFrame

DataFrame with OHLCV data containing columns: ['datetime', 'Open', 'High', 'Low', 'Close', 'Volume']

required
symbol str

The symbol being analyzed.

required

Returns:

Type Description
DataFrame

DataFrame with Gaussian KDE levels.

DataFrame

The columns are: ['datetime', 'level_values'].

Source code in src/turtle_quant_1/strategies/helpers/support_resistance/stnry_gaussian_kde.py
def generate_historical_levels(
    self, data: pd.DataFrame, symbol: str
) -> pd.DataFrame:
    """Generate Gaussian KDE levels for historical data.

    Args:
        data: DataFrame with OHLCV data containing columns:
              ['datetime', 'Open', 'High', 'Low', 'Close', 'Volume']
        symbol: The symbol being analyzed.

    Returns:
        DataFrame with Gaussian KDE levels.
        The columns are: ['datetime', 'level_values'].
    """
    level_values = self._calc_sup_res_levels(data)

    # Create output DataFrame with 1-to-1 mapping to original data
    result = pd.DataFrame(
        {
            "datetime": pd.to_datetime(data["datetime"]).reset_index(drop=True),
            "level_values": level_values,
        }
    )

    return result