diff --git a/openseries/_common_model.py b/openseries/_common_model.py index 5a5d97f9..4cc39a46 100644 --- a/openseries/_common_model.py +++ b/openseries/_common_model.py @@ -351,9 +351,9 @@ def worst_month(self: Self) -> float | Series[float]: """ wmdf = self.tsdf.copy() wmdf.index = DatetimeIndex(wmdf.index) - result = ( - wmdf.resample("BME").last().pct_change(fill_method=cast(str, None)).min() - ) + result = wmdf.resample("BME").last().pct_change( + fill_method=None, # type: ignore[arg-type,unused-ignore] + ).min() if self.tsdf.shape[1] == 1: return float(result.iloc[0]) @@ -1023,7 +1023,7 @@ def arithmetic_ret_func( result = ( self.tsdf.loc[cast(int, earlier) : cast(int, later)] - .pct_change(fill_method=cast(str, None)) + .pct_change(fill_method=None) # type: ignore[arg-type,unused-ignore] .mean() * time_factor ) @@ -1082,9 +1082,9 @@ def vol_func( time_factor = how_many / fraction data = self.tsdf.loc[cast(int, earlier) : cast(int, later)] - result = ( - data.pct_change(fill_method=cast(str, None)).std().mul(sqrt(time_factor)) - ) + result = data.pct_change( + fill_method=None, # type: ignore[arg-type,unused-ignore] + ).std().mul(sqrt(time_factor)) if self.tsdf.shape[1] == 1: return float(cast(SupportsFloat, result.iloc[0])) @@ -1280,14 +1280,14 @@ def _var_implied_vol_and_target_func( if drift_adjust: imp_vol = (-sqrt(time_factor) / norm.ppf(level)) * ( self.tsdf.loc[cast(int, earlier) : cast(int, later)] - .pct_change(fill_method=cast(str, None)) + .pct_change(fill_method=None) # type: ignore[arg-type,unused-ignore] .quantile(1 - level, interpolation=interpolation) - self.tsdf.loc[cast(int, earlier) : cast(int, later)] - .pct_change(fill_method=cast(str, None)) + .pct_change(fill_method=None) # type: ignore[arg-type,unused-ignore] .sum() / len( self.tsdf.loc[cast(int, earlier) : cast(int, later)].pct_change( - fill_method=cast(str, None), + fill_method=None, # type: ignore[arg-type,unused-ignore] ), ) ) @@ -1295,7 +1295,7 @@ def _var_implied_vol_and_target_func( imp_vol = ( -sqrt(time_factor) * self.tsdf.loc[cast(int, earlier) : cast(int, later)] - .pct_change(fill_method=cast(str, None)) + .pct_change(fill_method=None) # type: ignore[arg-type,unused-ignore] .quantile(1 - level, interpolation=interpolation) / norm.ppf(level) ) @@ -1358,14 +1358,16 @@ def cvar_down_func( cvar_df = self.tsdf.loc[cast(int, earlier) : cast(int, later)].copy(deep=True) result = [ cvar_df.loc[:, x] # type: ignore[call-overload,index] - .pct_change(fill_method=cast(str, None)) + .pct_change(fill_method=None) # type: ignore[arg-type,unused-ignore] .sort_values() .iloc[ : int( ceil( (1 - level) * cvar_df.loc[:, x] # type: ignore[index] - .pct_change(fill_method=cast(str, None)) + .pct_change( + fill_method=None, # type: ignore[arg-type,unused-ignore] + ) .count(), ), ) @@ -1425,7 +1427,7 @@ def downside_deviation_func( ) how_many = ( self.tsdf.loc[cast(int, earlier) : cast(int, later)] - .pct_change(fill_method=cast(str, None)) + .pct_change(fill_method=None) # type: ignore[arg-type,unused-ignore] .count(numeric_only=True) ) if periods_in_a_year_fixed: @@ -1440,7 +1442,7 @@ def downside_deviation_func( dddf = ( self.tsdf.loc[cast(int, earlier) : cast(int, later)] - .pct_change(fill_method=cast(str, None)) + .pct_change(fill_method=None) # type: ignore[arg-type,unused-ignore] .sub(min_accepted_return / time_factor) ) @@ -1543,7 +1545,7 @@ def skew_func( ) result: NDArray[float64] = skew( a=self.tsdf.loc[cast(int, earlier) : cast(int, later)] - .pct_change(fill_method=cast(str, None)) + .pct_change(fill_method=None) # type: ignore[arg-type,unused-ignore] .to_numpy(), bias=True, nan_policy="omit", @@ -1591,7 +1593,7 @@ def kurtosis_func( ) result: NDArray[float64] = kurtosis( self.tsdf.loc[cast(int, earlier) : cast(int, later)].pct_change( - fill_method=cast(str, None), + fill_method=None, # type: ignore[arg-type,unused-ignore] ), fisher=True, bias=True, @@ -1688,9 +1690,9 @@ def positive_share_func( ) pos = ( self.tsdf.loc[cast(int, earlier) : cast(int, later)] - .pct_change(fill_method=cast(str, None))[1:][ + .pct_change(fill_method=None)[1:][ # type: ignore[arg-type,unused-ignore] self.tsdf.loc[cast(int, earlier) : cast(int, later)].pct_change( - fill_method=cast(str, None), + fill_method=None, # type: ignore[arg-type,unused-ignore] )[1:] > zero ] @@ -1698,7 +1700,7 @@ def positive_share_func( ) tot = ( self.tsdf.loc[cast(int, earlier) : cast(int, later)] - .pct_change(fill_method=cast(str, None))[1:] + .pct_change(fill_method=None)[1:] # type: ignore[arg-type,unused-ignore] .count() ) share = pos / tot @@ -1877,7 +1879,7 @@ def omega_ratio_func( to_dt=to_date, ) retdf = self.tsdf.loc[cast(int, earlier) : cast(int, later)].pct_change( - fill_method=cast(str, None), + fill_method=None, # type: ignore[arg-type,unused-ignore] ) pos = retdf[retdf > min_accepted_return].sub(min_accepted_return).sum() neg = retdf[retdf < min_accepted_return].sub(min_accepted_return).sum() @@ -1966,7 +1968,9 @@ def value_ret_calendar_period( period = "-".join([str(year), str(month).zfill(2)]) vrdf = self.tsdf.copy() vrdf.index = DatetimeIndex(vrdf.index) - resultdf = DataFrame(vrdf.pct_change(fill_method=None)) # type: ignore[arg-type] + resultdf = DataFrame(vrdf.pct_change( + fill_method=None, # type: ignore[arg-type,unused-ignore] + )) result = resultdf.loc[period] + 1 cal_period = result.cumprod(axis="index").iloc[-1] - 1 if self.tsdf.shape[1] == 1: @@ -2018,7 +2022,7 @@ def var_down_func( ) result = ( self.tsdf.loc[cast(int, earlier) : cast(int, later)] - .pct_change(fill_method=cast(str, None)) + .pct_change(fill_method=None) # type: ignore[arg-type,unused-ignore] .quantile(1 - level, interpolation=interpolation) ) @@ -2066,7 +2070,7 @@ def worst_func( ) result = ( self.tsdf.loc[cast(int, earlier) : cast(int, later)] - .pct_change(fill_method=cast(str, None)) + .pct_change(fill_method=None) # type: ignore[arg-type,unused-ignore] .rolling(observations, min_periods=observations) .sum() .min() @@ -2113,7 +2117,7 @@ def z_score_func( to_dt=to_date, ) zscframe = self.tsdf.loc[cast(int, earlier) : cast(int, later)].pct_change( - fill_method=cast(str, None), + fill_method=None, # type: ignore[arg-type,unused-ignore] ) result = (zscframe.iloc[-1] - zscframe.mean()) / zscframe.std() @@ -2183,7 +2187,7 @@ def rolling_return( ret_label = cast(tuple[str], self.tsdf.iloc[:, column].name)[0] retseries = ( self.tsdf.iloc[:, column] - .pct_change(fill_method=cast(str, None)) + .pct_change(fill_method=None) # type: ignore[arg-type,unused-ignore] .rolling(observations, min_periods=observations) .sum() ) @@ -2260,7 +2264,9 @@ def rolling_vol( else: time_factor = self.periods_in_a_year vol_label = cast(tuple[str, ValueType], self.tsdf.iloc[:, column].name)[0] - dframe = self.tsdf.iloc[:, column].pct_change(fill_method=cast(str, None)) + dframe = self.tsdf.iloc[:, column].pct_change( + fill_method=None, # type: ignore[arg-type,unused-ignore] + ) volseries = dframe.rolling( observations, min_periods=observations, diff --git a/openseries/series.py b/openseries/series.py index ed36528c..40703c0f 100644 --- a/openseries/series.py +++ b/openseries/series.py @@ -436,7 +436,9 @@ def value_to_ret(self: Self) -> Self: The returns of the values in the series """ - self.tsdf = self.tsdf.pct_change(fill_method=None) # type: ignore[arg-type] + self.tsdf = self.tsdf.pct_change( + fill_method=None, # type: ignore[arg-type,unused-ignore] + ) self.tsdf.iloc[0] = 0 self.valuetype = ValueType.RTRN self.tsdf.columns = MultiIndex.from_arrays( @@ -696,7 +698,9 @@ def running_adjustment( returns_input = True else: values = [cast(float, self.tsdf.iloc[0, 0])] - ra_df = self.tsdf.pct_change(fill_method=None) # type: ignore[arg-type] + ra_df = self.tsdf.pct_change( + fill_method=None, # type: ignore[arg-type,unused-ignore] + ) returns_input = False ra_df = ra_df.dropna() diff --git a/openseries/simulation.py b/openseries/simulation.py index 7725dc95..1e687dcc 100644 --- a/openseries/simulation.py +++ b/openseries/simulation.py @@ -123,7 +123,9 @@ def realized_mean_return(self: Self) -> float: return cast( float, ( - self.results.pct_change(fill_method=cast(str, None)).mean() + self.results.pct_change( + fill_method=None, # type: ignore[arg-type,unused-ignore] + ).mean() * self.trading_days_in_year ).iloc[0], ) @@ -141,7 +143,9 @@ def realized_vol(self: Self) -> float: return cast( float, ( - self.results.pct_change(fill_method=cast(str, None)).std() + self.results.pct_change( + fill_method=None, # type: ignore[arg-type,unused-ignore] + ).std() * sqrt(self.trading_days_in_year) ).iloc[0], ) diff --git a/poetry.lock b/poetry.lock index 63f97b8c..380fe528 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1017,13 +1017,13 @@ typing-extensions = ">=4.6.0,<4.7.0 || >4.7.0" [[package]] name = "pytest" -version = "8.3.2" +version = "8.3.3" description = "pytest: simple powerful testing with Python" optional = false python-versions = ">=3.8" files = [ - {file = "pytest-8.3.2-py3-none-any.whl", hash = "sha256:4ba08f9ae7dcf84ded419494d229b48d0903ea6407b030eaec46df5e6a73bba5"}, - {file = "pytest-8.3.2.tar.gz", hash = "sha256:c132345d12ce551242c87269de812483f5bcc87cdbb4722e48487ba194f9fdce"}, + {file = "pytest-8.3.3-py3-none-any.whl", hash = "sha256:a6853c7375b2663155079443d2e45de913a911a11d669df02a50814944db57b2"}, + {file = "pytest-8.3.3.tar.gz", hash = "sha256:70b98107bd648308a7952b06e6ca9a50bc660be218d53c257cc1fc94fda10181"}, ] [package.dependencies] @@ -1425,4 +1425,4 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess [metadata] lock-version = "2.0" python-versions = ">=3.10,<3.13" -content-hash = "b1cc6d9dd45b76fb9a89a0b85972b7f0e08ebb19dc005d93b1790763f3e0b541" +content-hash = "3f77d7875b797a28f719a99957e0fe224a097f9a15bc7e9bd17eaebc50479318" diff --git a/pyproject.toml b/pyproject.toml index 92228c14..c2f99f08 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,7 +52,7 @@ genbadge = {version = ">=1.1.1,<2.0.0", extras = ["coverage"]} mypy = "^1.11.2" pandas-stubs = ">=2.1.2,<3.0.0" pre-commit = ">=3.7.1,<4.0.0" -pytest = ">=8.2.2,<9.0.0" +pytest = "^8.3.3" ruff = "^0.6.4" types-openpyxl = ">=3.1.2,<4.0.0" types-python-dateutil = ">=2.8.2,<3.0.0"