File tree Expand file tree Collapse file tree 3 files changed +15
-1
lines changed
investing_algorithm_framework Expand file tree Collapse file tree 3 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -833,6 +833,7 @@ def check_data_completeness(
833833 end_date = backtest_date_range .end_date ,
834834 pandas = True ,
835835 add_pandas_index = False ,
836+ add_datetime_column = True ,
836837 time_frame = data_source .time_frame
837838 )
838839 df = df .copy ()
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ def convert_polars_to_pandas(
66 data : PolarsDataFrame ,
77 remove_duplicates = True ,
88 add_index = True ,
9+ add_datetime_column = True ,
910 datetime_column_name = "Datetime"
1011):
1112 """
@@ -21,6 +22,8 @@ def convert_polars_to_pandas(
2122 dates will be removed from the dataframe
2223 add_index: Boolean - If set to true, an index will
2324 be added to the dataframe
25+ add_datetime_column: Boolean - If set to true, a datetime
26+ column will be added to the dataframe
2427 datetime_column_name: String - the column name that has the
2528 datetime object. By default this is set to column name Datetime
2629 This is only used if add_index is set to True
@@ -35,6 +38,9 @@ def convert_polars_to_pandas(
3538
3639 df = data .to_pandas ().copy ()
3740
41+ if add_datetime_column and datetime_column_name not in df .columns :
42+ df [datetime_column_name ] = pd .to_datetime (df .index )
43+
3844 # Ensure datetime column is datetime type
3945 df [datetime_column_name ] = pd .to_datetime (df [datetime_column_name ])
4046
Original file line number Diff line number Diff line change @@ -494,6 +494,7 @@ def get_ohlcv_data(
494494 window_size : Optional [int ] = None ,
495495 pandas : bool = False ,
496496 add_pandas_index : bool = True ,
497+ add_datetime_column : bool = False ,
497498 ):
498499 """
499500 Function to get OHLCV data from the data provider.
@@ -507,6 +508,10 @@ def get_ohlcv_data(
507508 end_date (datetime): The end date for the OHLCV data.
508509 window_size (int): The window size for the OHLCV data.
509510 pandas (bool): Whether to return the data as a pandas DataFrame.
511+ add_pandas_index (bool): Whether to add a pandas index to
512+ the DataFrame if pandas is True.
513+ add_datetime_column (bool): Whether to add a datetime column
514+ to the DataFrame if pandas is True.
510515
511516 Returns:
512517 DataFrame: The OHLCV data for the given symbol and market.
@@ -544,7 +549,9 @@ def get_ohlcv_data(
544549 if pandas :
545550 if isinstance (data , pl .DataFrame ):
546551 return convert_polars_to_pandas (
547- data , add_index = add_pandas_index
552+ data ,
553+ add_index = add_pandas_index ,
554+ add_datetime_column = add_datetime_column
548555 )
549556 else :
550557 return data
You can’t perform that action at this time.
0 commit comments