mirror of
https://github.com/webclinic017/drift.git
synced 2026-08-22 15:28:12 +00:00
chore(Linter): reformatted code with black (#211)
* chore(Linter): reformatted code with black * Create black.yaml
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
from numpy import float32
|
||||
from ..types import EventFilter
|
||||
from data_loader.types import ReturnSeries
|
||||
@@ -7,8 +5,8 @@ import pandas as pd
|
||||
from numba import njit
|
||||
from numba.typed import List
|
||||
|
||||
class CUSUMVolatilityEventFilter(EventFilter):
|
||||
|
||||
class CUSUMVolatilityEventFilter(EventFilter):
|
||||
def __init__(self, vol_period: int):
|
||||
self.vol_period = vol_period
|
||||
|
||||
@@ -36,34 +34,37 @@ class CUSUMVolatilityEventFilter(EventFilter):
|
||||
|
||||
return pd.DatetimeIndex(filtered_indices)
|
||||
|
||||
class CUSUMFixedEventFilter(EventFilter):
|
||||
|
||||
class CUSUMFixedEventFilter(EventFilter):
|
||||
def __init__(self, threshold: float):
|
||||
self.threshold = threshold
|
||||
|
||||
def get_event_start_times(self, returns: ReturnSeries) -> pd.DatetimeIndex:
|
||||
diffed_returns = returns.diff()
|
||||
int_indicies = _process(List(diffed_returns.to_list()), abs(returns.mean()) * self.threshold)
|
||||
int_indicies = _process(
|
||||
List(diffed_returns.to_list()), abs(returns.mean()) * self.threshold
|
||||
)
|
||||
|
||||
return pd.DatetimeIndex([returns.index[i] for i in int_indicies])
|
||||
|
||||
|
||||
@njit
|
||||
def _process(diffed_returns: List, threshold: float32) -> List:
|
||||
pos_threshold: float32 = 0.0 # type: ignore
|
||||
neg_threshold: float32 = 0.0 # type: ignore
|
||||
pos_threshold: float32 = 0.0 # type: ignore
|
||||
neg_threshold: float32 = 0.0 # type: ignore
|
||||
filtered_indicies = List()
|
||||
for index in range(1, len(diffed_returns[1:])):
|
||||
pos_threshold, neg_threshold = ( # type: ignore
|
||||
max(0, pos_threshold + diffed_returns[index]), # type: ignore
|
||||
min(0, neg_threshold + diffed_returns[index]), # type: ignore
|
||||
pos_threshold, neg_threshold = ( # type: ignore
|
||||
max(0, pos_threshold + diffed_returns[index]), # type: ignore
|
||||
min(0, neg_threshold + diffed_returns[index]), # type: ignore
|
||||
)
|
||||
|
||||
if neg_threshold < -threshold:
|
||||
neg_threshold = 0.0 # type: ignore
|
||||
neg_threshold = 0.0 # type: ignore
|
||||
filtered_indicies.append(index)
|
||||
|
||||
elif pos_threshold > threshold:
|
||||
pos_threshold = 0.0 # type: ignore
|
||||
pos_threshold = 0.0 # type: ignore
|
||||
filtered_indicies.append(index)
|
||||
|
||||
return filtered_indicies
|
||||
return filtered_indicies
|
||||
|
||||
@@ -2,8 +2,7 @@ from ..types import EventFilter
|
||||
from data_loader.types import ReturnSeries
|
||||
import pandas as pd
|
||||
|
||||
class NoEventFilter(EventFilter):
|
||||
|
||||
class NoEventFilter(EventFilter):
|
||||
def get_event_start_times(self, returns: ReturnSeries) -> pd.DatetimeIndex:
|
||||
return returns.index
|
||||
|
||||
|
||||
Reference in New Issue
Block a user