Skip to content

Commit 7f9216d

Browse files
zhupryou-n-g
authored andcommitted
Fix the number of minutes on the first and last trading day of high frequency
1 parent 263ccdf commit 7f9216d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

scripts/data_collector/yahoo/collector.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,14 @@ def normalize_yahoo(
472472
df.index = pd.to_datetime(df.index)
473473
df = df[~df.index.duplicated(keep="first")]
474474
if calendar_list is not None:
475-
df = df.reindex(pd.DataFrame(index=calendar_list).loc[df.index.min() : df.index.max()].index)
475+
df = df.reindex(
476+
pd.DataFrame(index=calendar_list)
477+
.loc[
478+
pd.Timestamp(df.index.min()).date() : pd.Timestamp(df.index.max()).date()
479+
+ pd.Timedelta(hours=23, minutes=59)
480+
]
481+
.index
482+
)
476483
df.sort_index(inplace=True)
477484
df.loc[(df["volume"] <= 0) | np.isnan(df["volume"]), set(df.columns) - {symbol_field_name}] = np.nan
478485
_tmp_series = df["close"].fillna(method="ffill")
@@ -614,6 +621,7 @@ def adjusted_price(self, df: pd.DataFrame) -> pd.DataFrame:
614621
data_1d = YahooData.get_data_from_remote(self.symbol_to_yahoo(symbol), interval="1d", start=_start, end=_end)
615622
if data_1d is None or data_1d.empty:
616623
df["factor"] = 1
624+
# TODO: np.nan or 1 or 0
617625
df["paused"] = np.nan
618626
else:
619627
data_1d = self.data_1d_obj.normalize(data_1d) # type: pd.DataFrame

0 commit comments

Comments
 (0)