Trim dataframes accordingly ...

This commit is contained in:
Matthias
2024-04-16 18:17:20 +02:00
parent 18a4d6972d
commit 7f386874ad
2 changed files with 10 additions and 2 deletions

View File

@@ -47,7 +47,8 @@ def combine_dataframes_by_column(
def combined_dataframes_with_rel_mean(
data: Dict[str, pd.DataFrame], column: str = "close") -> pd.DataFrame:
data: Dict[str, pd.DataFrame], fromdt: datetime, todt: datetime,
column: str = "close") -> pd.DataFrame:
"""
Combine multiple dataframes "column"
:param data: Dict of Dataframes, dict key should be pair.
@@ -57,6 +58,8 @@ def combined_dataframes_with_rel_mean(
:raise: ValueError if no data is provided.
"""
df_comb = combine_dataframes_by_column(data, column)
# Trim dataframes to the given timeframe
df_comb = df_comb.iloc[(df_comb.index >= fromdt) & (df_comb.index < todt)]
df_comb['count'] = df_comb.count(axis=1)
df_comb['mean'] = df_comb.mean(axis=1)
df_comb['rel_mean'] = df_comb['mean'].pct_change().fillna(0)

View File

@@ -254,13 +254,18 @@ def test_combine_dataframes_with_mean(testdatadir):
def test_combined_dataframes_with_rel_mean(testdatadir):
pairs = ["ETH/BTC", "ADA/BTC"]
data = load_data(datadir=testdatadir, pairs=pairs, timeframe='5m')
df = combined_dataframes_with_rel_mean(data)
df = combined_dataframes_with_rel_mean(
data,
datetime(2018, 1, 12, tzinfo=timezone.utc),
datetime(2018, 1, 28, tzinfo=timezone.utc)
)
assert isinstance(df, DataFrame)
assert "ETH/BTC" not in df.columns
assert "ADA/BTC" not in df.columns
assert "mean" in df.columns
assert "rel_mean" in df.columns
assert "count" in df.columns
assert len(df) < len(data['ETH/BTC'])
def test_combine_dataframes_with_mean_no_data(testdatadir):