Skip to content

Commit

Permalink
feat: Replace remove_warmup_periods() implementation with Python (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeDongGeon1996 authored Apr 15, 2024
1 parent d219bce commit d48387d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
1 change: 0 additions & 1 deletion stock_indicators/_cslib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
from Skender.Stock.Indicators import Quote as CsQuote
from Skender.Stock.Indicators import QuoteUtility as CsQuoteUtility
from Skender.Stock.Indicators import ResultBase as CsResultBase
from Skender.Stock.Indicators import Pruning as CsPruning

# Enums
from Skender.Stock.Indicators import BetaType as CsBetaType
Expand Down
32 changes: 11 additions & 21 deletions stock_indicators/indicators/common/results.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from datetime import datetime as PyDateTime
from typing import Callable, Iterable, List, Optional, Type, TypeVar

from stock_indicators._cslib import CsResultBase, CsPruning
from stock_indicators._cslib import CsResultBase
from stock_indicators._cstypes import DateTime as CsDateTime
from stock_indicators._cstypes import List as CsList
from stock_indicators._cstypes import to_pydatetime


Expand Down Expand Up @@ -77,26 +76,17 @@ def __add__(self, other: "IndicatorResults"):
def __mul__(self, value: int):
return self.__class__(list(self._csdata).__mul__(value), self._wrapper_class)

@_verify_data
def remove_warmup_periods(self, remove_periods: int):
"""Remove a specific quantity of results from the beginning of the results list."""
if not isinstance(remove_periods, int):
raise TypeError("remove_periods must be an integer.")

return self.__class__(list(self._csdata)[remove_periods:], self._wrapper_class)

def find(self, lookup_date: PyDateTime) -> Optional[_T]:
"""Find indicator values on a specific date. It returns `None` if no result found."""
if not isinstance(lookup_date, PyDateTime):
raise TypeError(
"lookup_date must be an instance of datetime.datetime."
)

return next((r for r in self if r.date == lookup_date), None)
raise TypeError("lookup_date must be an instance of datetime.datetime.")

@_verify_data
def remove_warmup_periods(self, remove_periods: int):
"""
Remove a specific quantity of results from the beginning of the results list.
"""
if not isinstance(remove_periods, int):
raise TypeError(
"remove_periods must be an integer."
)

removed_results = CsPruning.RemoveWarmupPeriods[CsResultBase](
CsList(self._get_csdata_type(), self._csdata), remove_periods
)
return self.__class__(removed_results, self._wrapper_class)
return next((r for r in self if r.date == lookup_date), None)

0 comments on commit d48387d

Please sign in to comment.