from enum import IntEnum
import logging
import json
+from statistics import median
import time
import numpy as np
import pandas as pd
https://github.com/sponsors/robcaulk
"""
- version = "3.7.75"
+ version = "3.7.76"
@cached_property
def _optuna_config(self) -> dict:
natr_period: int = 14,
natr_ratio: float = 6.0,
) -> tuple[list[int], list[float], list[int]]:
- min_confirmation_window: int = 2
- max_confirmation_window: int = 6
+ min_confirmation_window: int = 3
+ max_confirmation_window: int = 5
n = len(df)
if df.empty or n < max(natr_period, 2 * max_confirmation_window + 1):
return [], [], []
) -> int:
volatility_quantile = calculate_volatility_quantile(pos)
if np.isnan(volatility_quantile):
- return int(round(np.median([min_window, max_window])))
+ return int(round(median([min_window, max_window])))
return np.clip(
round(max_window - (max_window - min_window) * volatility_quantile),
def calculate_depth(
pos: int,
min_depth: int = 6,
- max_depth: int = 24,
+ max_depth: int = 26,
) -> int:
volatility_quantile = calculate_volatility_quantile(pos)
if np.isnan(volatility_quantile):
- return int(round(np.median([min_depth, max_depth])))
+ return int(round(median([min_depth, max_depth])))
return np.clip(
round(max_depth - (max_depth - min_depth) * volatility_quantile),
pos: int,
min_strength: float = 0.5,
max_strength: float = 1.5,
+ volatility_exponent: float = 1.5,
) -> float:
volatility_quantile = calculate_volatility_quantile(pos)
if np.isnan(volatility_quantile):
- return np.median([min_strength, max_strength])
+ return median([min_strength, max_strength])
- return min_strength + (max_strength - min_strength) * volatility_quantile
+ return min_strength + (max_strength - min_strength) * (
+ volatility_quantile**volatility_exponent
+ )
def update_candidate_pivot(pos: int, value: float, direction: TrendDirection):
nonlocal candidate_pivot_pos, candidate_pivot_value, candidate_pivot_direction
max_label_period_candles,
step=candles_step,
)
- label_natr_ratio = trial.suggest_float("label_natr_ratio", 4.0, 16.0, step=0.01)
+ label_natr_ratio = trial.suggest_float("label_natr_ratio", 2.0, 10.0, step=0.01)
df = df.iloc[
-(
from enum import IntEnum
from functools import lru_cache
+from statistics import median
import numpy as np
import pandas as pd
import scipy as sp
natr_period: int = 14,
natr_ratio: float = 6.0,
) -> tuple[list[int], list[float], list[int]]:
- min_confirmation_window: int = 2
- max_confirmation_window: int = 6
+ min_confirmation_window: int = 3
+ max_confirmation_window: int = 5
n = len(df)
if df.empty or n < max(natr_period, 2 * max_confirmation_window + 1):
return [], [], []
) -> int:
volatility_quantile = calculate_volatility_quantile(pos)
if np.isnan(volatility_quantile):
- return int(round(np.median([min_window, max_window])))
+ return int(round(median([min_window, max_window])))
return np.clip(
round(max_window - (max_window - min_window) * volatility_quantile),
def calculate_depth(
pos: int,
min_depth: int = 6,
- max_depth: int = 24,
+ max_depth: int = 26,
) -> int:
volatility_quantile = calculate_volatility_quantile(pos)
if np.isnan(volatility_quantile):
- return int(round(np.median([min_depth, max_depth])))
+ return int(round(median([min_depth, max_depth])))
return np.clip(
round(max_depth - (max_depth - min_depth) * volatility_quantile),
pos: int,
min_strength: float = 0.5,
max_strength: float = 1.5,
+ volatility_exponent: float = 1.5,
) -> float:
volatility_quantile = calculate_volatility_quantile(pos)
if np.isnan(volatility_quantile):
- return np.median([min_strength, max_strength])
+ return median([min_strength, max_strength])
- return min_strength + (max_strength - min_strength) * volatility_quantile
+ return min_strength + (max_strength - min_strength) * (
+ volatility_quantile**volatility_exponent
+ )
def update_candidate_pivot(pos: int, value: float, direction: TrendDirection):
nonlocal candidate_pivot_pos, candidate_pivot_value, candidate_pivot_direction