Source code for energytrackr.plot.builtin_plot_objects.ema_line
"""Plotting object for Exponential Moving Average (EMA) line."""fromdataclassesimportdataclassfromtypingimportAnyimportpandasaspdfromenergytrackr.plot.builtin_plot_objects.series_lineimportSeriesLine
[docs]@dataclass(frozen=True)classEMALineConfig:"""Configuration for the Exponential Moving Average (EMA) line plot object."""span:int=20color:str="green"line_width:int=2radius:float=0.3legend:str="EMA"default_visible:bool=True
[docs]classEMALine(SeriesLine[EMALineConfig]):"""Draws an exponential moving average over the median values."""def__init__(self,**params:dict[str,Any])->None:"""Initialize the EMA line with optional parameters overriding defaults."""super().__init__(EMALineConfig,**params)
[docs]defcompute(self,series:pd.Series)->pd.Series:"""Compute the exponential moving average of the series. Args: series: Input median series. Returns: EMA series with the same index. """returnseries.ewm(span=self.config.span,adjust=False).mean()