Exemplo n.º 1
0
        def _normalize(file_path: Path):
            columns = ["open", "close", "high", "low", "volume"]
            df = pd.read_csv(file_path)
            df.set_index("date", inplace=True)
            df.index = pd.to_datetime(df.index)
            df = df[~df.index.duplicated(keep="first")]

            # using China stock market data calendar
            df = df.reindex(pd.Index(get_calendar_list()))
            df.sort_index(inplace=True)

            df.loc[(df["volume"] <= 0) | np.isnan(df["volume"]),
                   set(df.columns) - {"symbol"}] = np.nan
            df["factor"] = df["adjclose"] / df["close"]
            for _col in columns:
                if _col == "volume":
                    df[_col] = df[_col] / df["factor"]
                else:
                    df[_col] = df[_col] * df["factor"]
            _tmp_series = df["close"].fillna(method="ffill")
            df["change"] = _tmp_series / _tmp_series.shift(1) - 1
            columns += ["change", "factor"]
            df.loc[(df["volume"] <= 0) | np.isnan(df["volume"]),
                   columns] = np.nan
            df.index.names = ["date"]
            df.loc[:,
                   columns].to_csv(self.normalize_dir.joinpath(file_path.name))
Exemplo n.º 2
0
    def calendar_list(self) -> list:
        """get history trading date

        Returns
        -------
        """
        return get_calendar_list(bench=True)
Exemplo n.º 3
0
    def calendar_list(self) -> list:
        """get history trading date

        Returns
        -------
        """
        return get_calendar_list(bench_code=self.index_name.upper())
Exemplo n.º 4
0
    def calendar_list(self) -> List[pd.Timestamp]:
        """get history trading date

        Returns
        -------
            calendar list
        """
        return get_calendar_list(bench_code=self.index_name.upper())
Exemplo n.º 5
0
    def calendar_list(self) -> List[pd.Timestamp]:
        """get history trading date

        Returns
        -------
            calendar list
        """
        _calendar = getattr(self, "_calendar_list", None)
        if not _calendar:
            _calendar = get_calendar_list(bench_code=self.index_name.upper())
            setattr(self, "_calendar_list", _calendar)
        return _calendar
Exemplo n.º 6
0
    def calendar_list(self) -> List[pd.Timestamp]:
        """get history trading date

        Returns
        -------
            calendar list
        """
        _calendar_list = getattr(self, "_calendar_list", None)
        if _calendar_list is None:
            _calendar_list = list(filter(lambda x: x >= self.bench_start_date, get_calendar_list("US_ALL")))
            setattr(self, "_calendar_list", _calendar_list)
        return _calendar_list
Exemplo n.º 7
0
 def _get_calendar_list(self):
     return get_calendar_list("ALL")
Exemplo n.º 8
0
 def _get_1d_calendar_list(self) -> Iterable[pd.Timestamp]:
     return get_calendar_list("ALL")
Exemplo n.º 9
0
 def _get_calendar_list(self) -> Iterable[pd.Timestamp]:
     # TODO: from MSN
     return get_calendar_list("ALL")
Exemplo n.º 10
0
 def _get_1d_calendar_list(self):
     return get_calendar_list("IN_ALL")
Exemplo n.º 11
0
 def _get_calendar_list(self):
     # TODO: from MSN
     return get_calendar_list("ALL")