Skip to content

Commit

Permalink
Fix ohlcv data sources tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MDUYN committed Mar 22, 2024
1 parent a953c6b commit f1b70a3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def get_data(
# it's not already
if 'Datetime' in df.columns and pd.api.types.is_string_dtype(
df['Datetime']):
df['Datetime'] = pd.to_datetime(df['Datetime'])
df['Datetime'] = pd.to_datetime(df['Datetime'], utc=True)

# Filter rows based on the start and end dates
filtered_df = df[
Expand Down Expand Up @@ -157,7 +157,7 @@ def get_data(self, index_datetime=None, **kwargs):
# it's not already
if 'Datetime' in df.columns and pd.api.types.is_string_dtype(
df['Datetime']):
df['Datetime'] = pd.to_datetime(df['Datetime'])
df['Datetime'] = pd.to_datetime(df['Datetime'], utc=True)

# Filter rows based on the start and end dates
filtered_df = df[(df['Datetime'] <= index_datetime)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
from datetime import datetime, timedelta

from dateutil.tz import tzutc
from unittest import TestCase

from investing_algorithm_framework.infrastructure import \
Expand All @@ -26,8 +28,8 @@ def setUp(self) -> None:
)

def test_right_columns(self):
file_name = "OHLCV_BTC-EUR_BINANCE_15m_2023-12-" \
"01:00:00_2023-12-25:00:00.csv"
file_name = "OHLCV_BTC-EUR_BINANCE" \
"_2h_2023-08-07:07:59_2023-12-02:00:00.csv"
CSVOHLCVMarketDataSource(
csv_file_path=f"{self.resource_dir}/"
"market_data_sources/"
Expand All @@ -36,9 +38,9 @@ def test_right_columns(self):
)

def test_start_date(self):
start_date = datetime(2023, 12, 1)
file_name = "OHLCV_BTC-EUR_BINANCE_15m_2023-12-" \
"01:00:00_2023-12-25:00:00.csv"
start_date = datetime(2023, 8, 7, 8, 0, tzinfo=tzutc())
file_name = "OHLCV_BTC-EUR_BINANCE" \
"_2h_2023-08-07:07:59_2023-12-02:00:00.csv"
csv_ohlcv_market_data_source = CSVOHLCVMarketDataSource(
csv_file_path=f"{self.resource_dir}/"
"market_data_sources/"
Expand All @@ -51,9 +53,9 @@ def test_start_date(self):
)

def test_end_date(self):
end_date = datetime(2023, 12, 25)
file_name = "OHLCV_BTC-EUR_BINANCE_15m_2023-12-" \
"01:00:00_2023-12-25:00:00.csv"
end_date = datetime(2023, 12, 2, 0, 0, tzinfo=tzutc())
file_name = "OHLCV_BTC-EUR_BINANCE" \
"_2h_2023-08-07:07:59_2023-12-02:00:00.csv"
csv_ohlcv_market_data_source = CSVOHLCVMarketDataSource(
csv_file_path=f"{self.resource_dir}/"
"market_data_sources/"
Expand All @@ -66,9 +68,9 @@ def test_end_date(self):
)

def test_empty(self):
start_date = datetime(2023, 12, 1)
file_name = "OHLCV_BTC-EUR_BINANCE_15m_2023-12-" \
"01:00:00_2023-12-25:00:00.csv"
start_date = datetime(2023, 8, 7, 8, 0, tzinfo=tzutc())
file_name = "OHLCV_BTC-EUR_BINANCE" \
"_2h_2023-08-07:07:59_2023-12-02:00:00.csv"
data_source = CSVOHLCVMarketDataSource(
csv_file_path=f"{self.resource_dir}/"
"market_data_sources/"
Expand All @@ -78,13 +80,13 @@ def test_empty(self):
)
self.assertFalse(data_source.empty())
self.assertEqual(start_date, data_source.start_date)
data_source.start_date = datetime(2023, 12, 25)
data_source.end_date = datetime(2023, 12, 16)
data_source.start_date = datetime(2023, 12, 25, 0, 0, tzinfo=tzutc())
data_source.end_date = datetime(2023, 12, 16, 0, 0, tzinfo=tzutc())
self.assertTrue(data_source.empty())

def test_get_data(self):
file_name = "OHLCV_BTC-EUR_BINANCE_15m_2023-12-" \
"01:00:00_2023-12-25:00:00.csv"
file_name = "OHLCV_BTC-EUR_BINANCE" \
"_2h_2023-08-07:07:59_2023-12-02:00:00.csv"
datasource = CSVOHLCVMarketDataSource(
csv_file_path=f"{self.resource_dir}/"
"market_data_sources/"
Expand All @@ -104,8 +106,8 @@ def test_get_data(self):
self.assertTrue(number_of_runs > 0)

def test_get_identifier(self):
file_name = "OHLCV_BTC-EUR_BINANCE_15m_2023-12-" \
"01:00:00_2023-12-25:00:00.csv"
file_name = "OHLCV_BTC-EUR_BINANCE" \
"_2h_2023-08-07:07:59_2023-12-02:00:00.csv"
datasource = CSVOHLCVMarketDataSource(
csv_file_path=f"{self.resource_dir}/"
"market_data_sources/"
Expand All @@ -117,8 +119,8 @@ def test_get_identifier(self):
self.assertEqual("test", datasource.get_identifier())

def test_get_market(self):
file_name = "OHLCV_BTC-EUR_BINANCE_15m_2023-12-" \
"01:00:00_2023-12-25:00:00.csv"
file_name = "OHLCV_BTC-EUR_BINANCE" \
"_2h_2023-08-07:07:59_2023-12-02:00:00.csv"
datasource = CSVOHLCVMarketDataSource(
csv_file_path=f"{self.resource_dir}/"
"market_data_sources/"
Expand All @@ -131,8 +133,8 @@ def test_get_market(self):
self.assertEqual("test", datasource.get_market())

def test_get_symbol(self):
file_name = "OHLCV_BTC-EUR_BINANCE_15m_2023-12-" \
"01:00:00_2023-12-25:00:00.csv"
file_name = "OHLCV_BTC-EUR_BINANCE" \
"_2h_2023-08-07:07:59_2023-12-02:00:00.csv"
datasource = CSVOHLCVMarketDataSource(
csv_file_path=f"{self.resource_dir}/"
"market_data_sources/"
Expand All @@ -144,8 +146,8 @@ def test_get_symbol(self):
self.assertEqual("BTC/EUR", datasource.get_symbol())

def test_get_timeframe(self):
file_name = "OHLCV_BTC-EUR_BINANCE_15m_2023-12-" \
"01:00:00_2023-12-25:00:00.csv"
file_name = "OHLCV_BTC-EUR_BINANCE" \
"_2h_2023-08-07:07:59_2023-12-02:00:00.csv"
datasource = CSVOHLCVMarketDataSource(
csv_file_path=f"{self.resource_dir}/"
"market_data_sources/"
Expand Down

0 comments on commit f1b70a3

Please sign in to comment.