mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-21 19:27:36 +08:00
Compare commits
5 Commits
v0.8.5
...
you-n-g-pa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61f2433c9b | ||
|
|
84ff662a26 | ||
|
|
00e40e775b | ||
|
|
45fe5e6974 | ||
|
|
366a9c33f3 |
18
.github/workflows/test_macos.yml
vendored
18
.github/workflows/test_macos.yml
vendored
@@ -34,25 +34,10 @@ jobs:
|
|||||||
python -m black qlib -l 120 --check --diff
|
python -m black qlib -l 120 --check --diff
|
||||||
# Test Qlib installed with pip
|
# Test Qlib installed with pip
|
||||||
|
|
||||||
- name: Check Qlib with flake8
|
|
||||||
run: |
|
|
||||||
pip install --upgrade pip
|
|
||||||
pip install flake8
|
|
||||||
cd ..
|
|
||||||
flake8 --ignore=E501,F541,E266,E402,W503,E731,E203 qlib
|
|
||||||
|
|
||||||
- name: Install Qlib with pip
|
- name: Install Qlib with pip
|
||||||
run: |
|
run: |
|
||||||
python -m pip install numpy==1.19.5
|
python -m pip install numpy==1.19.5
|
||||||
python -m pip install pyqlib --ignore-installed ruamel.yaml numpy
|
python -m pip install pyqlib --ignore-installed ruamel.yaml numpy
|
||||||
- name: Make html with sphnix
|
|
||||||
run: |
|
|
||||||
pip install -U sphinx
|
|
||||||
pip install sphinx_rtd_theme readthedocs_sphinx_ext
|
|
||||||
pip install --exists-action=w --no-cache-dir -r docs/requirements.txt
|
|
||||||
cd docs
|
|
||||||
sphinx-build -b html . build
|
|
||||||
cd ..
|
|
||||||
- name: Install Lightgbm for MacOS
|
- name: Install Lightgbm for MacOS
|
||||||
run: |
|
run: |
|
||||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Microsoft/qlib/main/.github/brew_install.sh)"
|
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Microsoft/qlib/main/.github/brew_install.sh)"
|
||||||
@@ -64,8 +49,7 @@ jobs:
|
|||||||
brew install libomp.rb
|
brew install libomp.rb
|
||||||
- name: Test data downloads
|
- name: Test data downloads
|
||||||
run: |
|
run: |
|
||||||
python scripts/get_data.py qlib_data --name qlib_data_simple --target_dir ~/.qlib/qlib_data/cn_data_simple --interval 1d --region cn
|
python scripts/get_data.py qlib_data --target_dir ~/.qlib/qlib_data/cn_data --interval 1d --region cn
|
||||||
python -c "import os; userpath=os.path.expanduser('~'); os.rename(userpath + '/.qlib/qlib_data/cn_data_simple', userpath + '/.qlib/qlib_data/cn_data')"
|
|
||||||
- name: Test workflow by config (install from pip)
|
- name: Test workflow by config (install from pip)
|
||||||
run: |
|
run: |
|
||||||
python qlib/workflow/cli.py examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml
|
python qlib/workflow/cli.py examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml
|
||||||
|
|||||||
@@ -437,7 +437,7 @@ Dataset
|
|||||||
|
|
||||||
The ``Dataset`` module in ``Qlib`` aims to prepare data for model training and inferencing.
|
The ``Dataset`` module in ``Qlib`` aims to prepare data for model training and inferencing.
|
||||||
|
|
||||||
The motivation of this module is that we want to maximize the flexibility of of different models to handle data that are suitable for themselves. This module gives the model the flexibility to process their data in an unique way. For instance, models such as ``GBDT`` may work well on data that contains `nan` or `None` value, while neural networks such as ``MLP`` will break down on such data.
|
The motivation of this module is that we want to maximize the flexibility of different models to handle data that are suitable for themselves. This module gives the model the flexibility to process their data in an unique way. For instance, models such as ``GBDT`` may work well on data that contains `nan` or `None` value, while neural networks such as ``MLP`` will break down on such data.
|
||||||
|
|
||||||
If user's model need process its data in a different way, user could implement his own ``Dataset`` class. If the model's
|
If user's model need process its data in a different way, user could implement his own ``Dataset`` class. If the model's
|
||||||
data processing is not special, ``DatasetH`` can be used directly.
|
data processing is not special, ``DatasetH`` can be used directly.
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ The meaning of each field is as follows:
|
|||||||
Dataset Section
|
Dataset Section
|
||||||
~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
The `dataset` field describes the parameters for the ``Dataset`` module in ``Qlib`` as well those for the module ``DataHandler``. For more information about the ``Dataset`` module, please refer to `Qlib Model <../component/data.html#dataset>`_.
|
The `dataset` field describes the parameters for the ``Dataset`` module in ``Qlib`` as well those for the module ``DataHandler``. For more information about the ``Dataset`` module, please refer to `Qlib Data <../component/data.html#dataset>`_.
|
||||||
|
|
||||||
The keywords arguments configuration of the ``DataHandler`` is as follows:
|
The keywords arguments configuration of the ``DataHandler`` is as follows:
|
||||||
|
|
||||||
@@ -248,7 +248,7 @@ The keywords arguments configuration of the ``DataHandler`` is as follows:
|
|||||||
|
|
||||||
Users can refer to the document of `DataHandler <../component/data.html#datahandler>`_ for more information about the meaning of each field in the configuration.
|
Users can refer to the document of `DataHandler <../component/data.html#datahandler>`_ for more information about the meaning of each field in the configuration.
|
||||||
|
|
||||||
Here is the configuration for the ``Dataset`` module which will take care of data preprossing and slicing during the training and testing phase.
|
Here is the configuration for the ``Dataset`` module which will take care of data preprocessing and slicing during the training and testing phase.
|
||||||
|
|
||||||
.. code-block:: YAML
|
.. code-block:: YAML
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
# Licensed under the MIT License.
|
# Licensed under the MIT License.
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
__version__ = "0.8.5"
|
__version__ = "0.8.5.99"
|
||||||
__version__bak = __version__ # This version is backup for QlibConfig.reset_qlib_version
|
__version__bak = __version__ # This version is backup for QlibConfig.reset_qlib_version
|
||||||
import os
|
import os
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ def pred_autocorr(pred: pd.Series, lag=1, inst_col="instrument", date_col="datet
|
|||||||
"""
|
"""
|
||||||
if isinstance(pred, pd.DataFrame):
|
if isinstance(pred, pd.DataFrame):
|
||||||
pred = pred.iloc[:, 0]
|
pred = pred.iloc[:, 0]
|
||||||
get_module_logger("pred_autocorr").warning("Only the first column in {pred.columns} of `pred` is kept")
|
get_module_logger("pred_autocorr").warning(f"Only the first column in {pred.columns} of `pred` is kept")
|
||||||
pred_ustk = pred.sort_index().unstack(inst_col)
|
pred_ustk = pred.sort_index().unstack(inst_col)
|
||||||
corr_s = {}
|
corr_s = {}
|
||||||
for (idx, cur), (_, prev) in zip(pred_ustk.iterrows(), pred_ustk.shift(lag).iterrows()):
|
for (idx, cur), (_, prev) in zip(pred_ustk.iterrows(), pred_ustk.shift(lag).iterrows()):
|
||||||
|
|||||||
@@ -68,9 +68,9 @@ def parse_position(position: dict = None) -> pd.DataFrame:
|
|||||||
if not _trading_day_sell_df.empty:
|
if not _trading_day_sell_df.empty:
|
||||||
_trading_day_sell_df["status"] = -1
|
_trading_day_sell_df["status"] = -1
|
||||||
_trading_day_sell_df["date"] = _trading_date
|
_trading_day_sell_df["date"] = _trading_date
|
||||||
_trading_day_df = _trading_day_df.append(_trading_day_sell_df, sort=False)
|
_trading_day_df = pd.concat([_trading_day_df, _trading_day_sell_df], sort=False)
|
||||||
|
|
||||||
result_df = result_df.append(_trading_day_df, sort=True)
|
result_df = pd.concat([result_df, _trading_day_df], sort=True)
|
||||||
|
|
||||||
previous_data = dict(
|
previous_data = dict(
|
||||||
date=_trading_date,
|
date=_trading_date,
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ def _get_monthly_risk_analysis_with_report(report_normal_df: pd.DataFrame) -> pd
|
|||||||
# _m_report_long_short,
|
# _m_report_long_short,
|
||||||
pd.Timestamp(year=gp_m[0], month=gp_m[1], day=month_days),
|
pd.Timestamp(year=gp_m[0], month=gp_m[1], day=month_days),
|
||||||
)
|
)
|
||||||
_monthly_df = _monthly_df.append(_temp_df, sort=False)
|
_monthly_df = pd.concat([_monthly_df, _temp_df], sort=False)
|
||||||
|
|
||||||
return _monthly_df
|
return _monthly_df
|
||||||
|
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ class BaseCollector(abc.ABC):
|
|||||||
df["symbol"] = symbol
|
df["symbol"] = symbol
|
||||||
if instrument_path.exists():
|
if instrument_path.exists():
|
||||||
_old_df = pd.read_csv(instrument_path)
|
_old_df = pd.read_csv(instrument_path)
|
||||||
df = _old_df.append(df, sort=False)
|
df = pd.concat([_old_df, df], sort=False)
|
||||||
df.to_csv(instrument_path, index=False)
|
df.to_csv(instrument_path, index=False)
|
||||||
|
|
||||||
def cache_small_data(self, symbol, df):
|
def cache_small_data(self, symbol, df):
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ class IndexBase:
|
|||||||
] = _row.date
|
] = _row.date
|
||||||
else:
|
else:
|
||||||
_tmp_df = pd.DataFrame([[_row.symbol, self.bench_start_date, _row.date]], columns=instruments_columns)
|
_tmp_df = pd.DataFrame([[_row.symbol, self.bench_start_date, _row.date]], columns=instruments_columns)
|
||||||
new_df = new_df.append(_tmp_df, sort=False)
|
new_df = pd.concat([new_df, _tmp_df], sort=False)
|
||||||
|
|
||||||
inst_df = new_df.loc[:, instruments_columns]
|
inst_df = new_df.loc[:, instruments_columns]
|
||||||
_inst_prefix = self.INST_PREFIX.strip()
|
_inst_prefix = self.INST_PREFIX.strip()
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ class YahooCollectorCN1d(YahooCollectorCN):
|
|||||||
_path = self.save_dir.joinpath(f"sh{_index_code}.csv")
|
_path = self.save_dir.joinpath(f"sh{_index_code}.csv")
|
||||||
if _path.exists():
|
if _path.exists():
|
||||||
_old_df = pd.read_csv(_path)
|
_old_df = pd.read_csv(_path)
|
||||||
df = _old_df.append(df, sort=False)
|
df = pd.concat([_old_df, df], sort=False)
|
||||||
df.to_csv(_path, index=False)
|
df.to_csv(_path, index=False)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
@@ -404,7 +404,7 @@ class YahooNormalize(BaseNormalize):
|
|||||||
.index
|
.index
|
||||||
)
|
)
|
||||||
df.sort_index(inplace=True)
|
df.sort_index(inplace=True)
|
||||||
df.loc[(df["volume"] <= 0) | np.isnan(df["volume"]), set(df.columns) - {symbol_field_name}] = np.nan
|
df.loc[(df["volume"] <= 0) | np.isnan(df["volume"]), list(set(df.columns) - {symbol_field_name})] = np.nan
|
||||||
|
|
||||||
change_series = YahooNormalize.calc_change(df, last_close)
|
change_series = YahooNormalize.calc_change(df, last_close)
|
||||||
# NOTE: The data obtained by Yahoo finance sometimes has exceptions
|
# NOTE: The data obtained by Yahoo finance sometimes has exceptions
|
||||||
|
|||||||
Reference in New Issue
Block a user