chore(Linter): reformatted code with black (#211)

* chore(Linter): reformatted code with black

* Create black.yaml
This commit is contained in:
Mark Aron Szulyovszky
2022-02-17 19:22:17 +01:00
committed by GitHub
parent f3fee4a4e1
commit 8dd2d88740
101 changed files with 2595 additions and 2319 deletions
+14 -13
View File
@@ -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
+1 -2
View File
@@ -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