1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-06-06 05:51:17 +08:00

1881 Commits

Author SHA1 Message Date
Young
b8bb3adbc8 Bump Qlib Version v0.9.0 2022-12-09 18:06:11 +08:00
Chia-hung Tai
ea10da32ba Fix warning in processor.py. (#1386)
* Fix warning in processor.py.

* Remove comment.
2022-12-08 23:47:05 +08:00
Huoran Li
577923a9f0 Fix RL example bug (#1384)
* Fix data pipeline

* Add TODO
2022-12-06 20:49:56 +08:00
Hyeongmin Moon
9d8a8c6f13 Resolve issues while running Automatic update of daily frequency data (from yahoo finance) for US region (#1358)
* Update YahooNormalizeUS1dExtend(#1196)

* Prevent pandas read_csv errors while running update_data_to_bin for US region

* Fix parse_index error while running update_data_to_bin for US region

* prevent pandas.read_csv error on specific symbol names

* Reordering parameters for better rendering

* removes prefix during feature_dir existence checking

* add explanation comments
2022-12-05 14:50:28 +08:00
you-n-g
d44175e425 Fix RL command Error (#1382) 2022-12-05 09:39:26 +08:00
Maxim Smolskiy
5b73b80293 Fix the Errors/Warnings when building Qlib's documentation (#1381)
* Fix the Errors/Warnings when building Qlib's documentation

* Fix

* Fix

* Empty

* Test CI

* Add doc compiling checking to CI

* Fix

* Tries to be consistent with Makefile

Co-authored-by: you-n-g <you-n-g@users.noreply.github.com>
2022-12-05 09:29:03 +08:00
YQ Tsui
6a47416a2d Fix logging_level: make logging level specified in qlib.init applies to all loggers (#1368)
* fix logging_level: make logging level specified in qlib.init apply to all loggers

* downgrade loglevel in expmanager __init__ to debug (it will be called in each process in multiprocessing operations such as read data)

* correct gramma error

* fix black lint

* use functor to cache loggers and set level

* correct black lint

* correct pylint

* correct pylint
2022-11-29 08:09:22 +08:00
YQ Tsui
4f5ae4d224 fix csi500 end date issue (#1373) 2022-11-28 18:06:29 +08:00
Di
7e5bab599a Add early stopping to double ensemble model, add example (#1375)
* Add early stopping to double ensemble model, add example

* Fix lint error
2022-11-28 14:02:44 +08:00
Linlang
c4ee9ff882 Fixed log_param error (#1362)
* fix_qrun_error

* add_description
2022-11-20 14:18:35 +08:00
YQ Tsui
cc01812c62 Fix typos and grammar errors in docstrings and comments (#1366)
* fix gramma error in doc strings

* fix typos in exchange.py

* fix typos and gramma errors

* fix typo and rename function param to avoid shading python keyword

* remove redundant parathesis; pass kwargs to parent class

* fix pyblack

* further correction

* assign -> be assigned to
2022-11-20 14:15:59 +08:00
Chia-hung Tai
0c4db8b0f8 Set _artifact_uri when mlflow_run is not None. (#1367)
* Set _artifact_uri when mlflow_run is not None.

* Fix black.
2022-11-19 11:56:30 +08:00
Chia-hung Tai
e47b0f1c50 Fix typo. (#1365) 2022-11-19 11:52:34 +08:00
you-n-g
994f89319d Optimize the implementation of uri & Fix async log bug (#1364)
* Optimize the implementation of uri

* remove redundant func

* Set the right order of _set_client_uri

* Update qlib/workflow/expm.py

* Simplify client & add test.Add docs; Fix async bug

* Fix comments & pylint

* Improve README
2022-11-18 13:11:31 +08:00
Maxim Smolskiy
b51e881be3 Fix the Errors with unexpected indentation when building Qlib's documentation (#1352)
* Fix ERROR: Unexpected indentation in qlib/data/dataset/handler.py

* Fix ERROR: Unexpected indentation in qlib/data/dataset/__init__.py

* Fix ERROR: Unexpected indentation in ../qlib/data/cache.py

* Fix ERROR: Unexpected indentation in qlib/model/meta/task.py

* Fix ERROR: Unexpected indentation in qlib/model/meta/dataset.py

* Fix ERROR: Unexpected indentation in qlib/workflow/online/manager.py

* Fix ERROR: Unexpected indentation in qlib/workflow/online/update.py

* Fix ERROR: Unexpected indentation in /qlib/workflow/__init__.py

* Fix ERROR: Unexpected indentation in qlib/data/base.py

* Fix ERROR: Unexpected indentation in qlib/data/dataset/loader.py

* Fix ERROR: Unexpected indentation in qlib/contrib/evaluate.py

* Fix ERROR: Unexpected indentation in qlib/workflow/record_temp.py

* Fix ERROR: Unexpected indentation in qlib/workflow/task/gen.py

* Fix ERROR: Unexpected indentation in qlib/strategy/base.py

* Fix qlib/data/dataset/handler.py

* Retest
2022-11-15 08:49:36 +08:00
Maxim Smolskiy
8802653bb9 Fix the Warnings with duplicate object description when building Qlib's documentation (#1353)
* Add :noindex: to docs/advanced/task_management.rst

* Add :noindex: to docs/component/data.rst

* Add :noindex: to docs/component/model.rst

* Add :noindex: to docs/component/online.rst

* Add :noindex: to docs/component/recorder.rst

* Add :noindex: to docs/component/report.rst

* Retest
2022-11-14 18:53:25 +08:00
Maxim Smolskiy
82afd6a67a Fix the Warnings in rst files when building Qlib's documentation (#1349)
* Fix docs/advanced/alpha.rst

* Fix docs/reference/api.rst

* Fix docs/component/strategy.rst

* Fix docs/start/integration.rst

* Fix docs/component/report.rst

* Fix docs/component/data.rst

* Fix docs/component/rl/framework.rst

* Fix docs/introduction/quick.rst

* Fix docs/advanced/task_management.rst

* Fix CHANGES.rst

* Fix docs/developer/code_standard_and_dev_guide.rst

* Fix docs/hidden/client.rst

* Fix docs/component/online.rst

* Fix docs/start/getdata.rst

* Add docs/hidden to exclude patterns

* Add docs/developer/code_standard_and_dev_guide.rst to index.rst

* Change docs/developer/code_standard_and_dev_guide.rst place in index.rst
2022-11-13 22:07:08 +08:00
qianyun210603
4001a5d157 Bug fix for Rank and WMA operators (#1228)
* bug fix: 1) 100 should be used to scale down percentileofscore return to 0-1, not length of array; 2) for (linear) weighted MA(n), weight should be n, n-1, ..., 1 instead of n-1, ..., 0

* use native pandas fucntion for rank

* remove useless import

* require pandas 1.4+

* rank for py37+pandas 1.3.5 compatibility

* lint improvement

* lint black fix

* use hasattr instead of version to check whether rolling.rank is implemented
2022-11-13 19:03:23 +08:00
He Yi
ff2154c618 fix bug in fix clip_outlier in class RobustZScoreNorm(Processor) (#1294) 2022-11-11 19:53:33 +08:00
Xu Yang
a82cc0b129 update TSDataSampler refineing the memory layout of data array to speed up NN training (#1342)
* update TSDataSampler

* reformat code with black

* use pre-commit to reformat the code

* Add documents

* More docstring

* More Safety

Co-authored-by: Young <afe.young@gmail.com>
2022-11-11 19:35:10 +08:00
you-n-g
3b471a0fe3 Fix CI (#1347) 2022-11-11 10:25:04 +08:00
you-n-g
b46bf8283d Update README.md 2022-11-10 21:15:33 +08:00
Lewen Wang
e182124e75 Add docs for qlib.rl (#1322)
* Add docs for qlib.rl

* Update docs for qlib.rl

* Add homepage introduct to RL framework

* Update index Link

* Fix Icon

* typo

* Update catelog

* Update docs for qlib.rl

* Update docs for qlib.rl

* Update figure

* Update docs for qlib.rl

* Update setup.py

* FIx setup.py

* Update docs and fix some typos

* Fix the reference to RL docs

* Update framework.svg

* Update framework.svg

* Update framework.svg

* Update docs for qlibrl.

* Update docs for qlibrl.

* Update docs for Qlibrl.

* Update docs for qlibrl.

* Update docs for qlibrl.

* Update docs for qlibrl.

* Add new framework

* Update jpg

* Update framework.svg

* Update framework.svg

* Update Qlib framework and description

* Update grammar

* Update README.md

* Update README.md

* Update docs/component/rl.rst

Co-authored-by: you-n-g <you-n-g@users.noreply.github.com>

* Update docs/component/rl.rst

Co-authored-by: you-n-g <you-n-g@users.noreply.github.com>

* Update docs for qlib.rl

* Change theme for docs.

* Update docs for qlib.rl

* Update docs for qlib.rl

* Update docs for qlib.rl

* Update docs for qlib.rl.

* Update docs for qlib.rl

* Update docs for qlib.rl

* Update docs for qlib.rl

Co-authored-by: Young <afe.young@gmail.com>
Co-authored-by: you-n-g <you-n-g@users.noreply.github.com>
2022-11-10 21:10:44 +08:00
Huoran Li
35794846ff Refine RL todos (#1332)
* Refine several todos

* CI issues

* Remove Dropna limitation of `quote_df` in Exchange  (#1334)

* Remove Dropna limitation of `quote_df` of Exchange

* Impreove docstring

* Fix type error when expression is specified (#1335)

* Refine fill_missing_data()

* Remove several TODO comments

* Add back env for interpreters

* Change Literal import

* Resolve PR comments

* Move  to SAOEState

* Add Trainer.get_policy_state_dict()

* Mypy issue

Co-authored-by: you-n-g <you-n-g@users.noreply.github.com>
2022-11-10 21:10:11 +08:00
Jinge Wang
49a5bccfec Don't disable existing logger when initializing qlib. (#1339)
* Don't disable existing logger when initializing qlib.

* Add comma in the end of the config line.

* Add comment to the added config.

Co-authored-by: Jinge Wang <jingewang@microsoft.com>
2022-11-10 09:20:33 +08:00
lerit
59fbf23a71 fix position access error (#1267)
* fix position access error

position is s sub attribute of _value
error since commit(id:89972f6c6f9fa629b4f74093d4ba1e93c9f7a5e5)

* lint with blank
2022-11-08 10:51:43 +08:00
qianyun210603
94e420f755 Correct errors and typos in doc strings (#1338)
* add missing parameters to doc string in order_generate

* fix some typos in doc strings

* reformat base on code style standard

* Update qlib/backtest/__init__.py

* Update examples/run_all_model.py

* Update examples/run_all_model.py

Co-authored-by: you-n-g <you-n-g@users.noreply.github.com>
2022-11-07 23:37:18 +08:00
lerit
2fae407b19 Update dump_bin.py (#1273)
dump_fix data that not in calendar_list, throw error:
```
NaT is not in list
```
2022-11-04 21:15:23 +08:00
wony
67d618d4b2 Update cache.py (#1329)
make D.feature([symbol], [Feature('close')], disk_cache=1) work correctly
2022-11-03 17:08:22 +08:00
Chia-hung Tai
fb5888be9e Use mock data for element operator tests. (#1330) 2022-10-30 16:27:59 +08:00
Linlang
08de1a1874 fix_CI_error (#1325) 2022-10-22 17:32:56 +08:00
Linlang
1861c8edaf optimize_CI (#1314) 2022-10-20 08:38:05 +08:00
Huoran Li
3c62d131a5 Migrate amc4th training (#1316)
* Migrate amc4th training

* Refine RL example scripts

* Resolve PR comments

Co-authored-by: luocy16 <luocy16@mails.tsinghua.edu.cn>
2022-10-19 10:17:43 +08:00
Chao Wang
bc06f0301e Update README.md (#1279)
typo fix.
2022-10-14 11:50:19 +08:00
Chia-hung Tai
84e9df2603 Add REG_US and REG_TW into test case: test_utils.py. (#1310)
* Add REG_US and REG_TW into test case: test_utils.py.

* Fix black.

* Trigger checks.

* Add REG_US and REG_TW into test case: test_utils.py.

* Fix black.

* Trigger checks.
2022-10-14 11:49:30 +08:00
Huoran Li
216a8ec2de RL backtest with simulator (#1299)
* RL backtest with simulator

* Minor modification in init_qlib

* Cherry pick PR 1302

* Resolve PR comments

* Fix missing data processing

* Minor bugfix

* Add TODOs and docs

* Add a comment
2022-10-12 16:44:28 +08:00
Yuchen Fang
54928e956d General handler for open source data preprocessing (#1302)
* feat(data):  add a general highfreq data handler for open source

Add HighFreqOpenHandler and HighFreqOpenBacktestHandler for data pipeline without paused_num
information.

* fix: position of parameter init

* style(data): 💄 rename open to general

* style(data): 💄 lint

* style: 💄 delete useless comment & fix inheritance relation

* style: 💄 lint

* style: 💄 remove duplicated function

Co-authored-by: mingzhehan <v-zhaoxing@Microsoft.com>
2022-10-12 15:18:30 +08:00
lerit
4fa37a96bf Update __init__.py (#1287)
doc for search_records
2022-10-12 08:29:54 +08:00
Chia-hung Tai
b22ecd145b Fix typo (#1308) 2022-10-07 22:32:07 +08:00
Huoran Li
bee05f56ef Migrate backtest logic from NT (#1263)
* Backtest migration

* Minor bug fix in test

* Reorganize file to avoid loop import

* Fix test SAOE bug

* Remove unnecessary names

* Resolve PR comments; remove private classes;

* Fix CI error

* Resolve PR comments

* Refactor data interfaces

* Remove convert_instance_config and change config

* Pylint issue

* Pylint issue

* Fix tempfile warning

* Resolve PR comments

* Add more comments
2022-09-19 14:54:26 +08:00
you-n-g
e762548295 Add docs for the reampling example. (#1285)
* Update features_sample.py

* Update features_sample.py
2022-09-14 18:02:19 +08:00
Huoran Li
7c64ea5c08 Fix _update_dealt_order_amount bug. (#1291)
* Fix bug

* A weird Mypy issue
2022-09-14 14:14:20 +08:00
Chao Wang
80bf16f9a8 Expm typo fix add log (#1271)
* My own implementation of ChangeInstrument Op. There is a newer, simpler
implemenation from remote.
On branch main
Your branch is behind 'origin/main' by 127 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

Changes to be committed:
       modified:   qlib/data/ops.py

Changes not staged for commit:
       modified:   qlib/contrib/evaluate.py
       modified:   qlib/contrib/strategy/signal_strategy.py
       modified:   qlib/utils/__init__.py
       modified:   qlib/workflow/cli.py
       modified:   qlib/workflow/expm.py

Untracked files:
       .idea/

------------------------ >8 ------------------------
Do not modify or remove the line above.
Everything below it will be ignored.
diff --git a/qlib/data/ops.py b/qlib/data/ops.py
index bdc032c0..23db25cc 100644
--- a/qlib/data/ops.py
+++ b/qlib/data/ops.py
@@ -32,6 +32,90 @@ except ValueError as e:

 np.seterr(invalid="ignore")

+#################### Change instrument ########################
+# In some case, one may want to change to another instrument when calculating, for example
+# calculate beta of a stock with respect to a market index
+# this would require change the calculation of features from the stock (original instrument) to
+# the index (reference instrument)
+# #############################
+
+
+class ChangeInstrument(ExpressionOps):
+    """Change Instrument Operator
+    In some case, one may want to change to another instrument when calculating, for example, to
+    calculate beta of a stock with respect to a market index.
+    This would require changing the calculation of features from the stock (original instrument) to
+    the index (reference instrument)
+    Parameters
+    ----------
+    instrument: new instrument for which the downstream operations should be performed upon.
+                i.e., SH000300 (CSI300 index), or ^GPSC (SP500 index).
+
+    feature: the feature to be calculated for the new instrument.
+    Returns
+    ----------
+    Expression
+        feature operation output
+    """
+
+    def __init__(self, instrument, feature):
+        self.instrument = instrument
+        self.feature = feature
+
+    def __str__(self):
+        return "{}({},{})".format(type(self).__name__, self.instrument, self.feature)
+
+    def load(self, instrument, start_index, end_index, freq):
+        """load  feature
+
+        Parameters
+        ----------
+        instrument : str
+            instrument code, however, the actual instrument loaded is self.instrument through initialization
+        start_index : str
+            feature start index [in calendar].
+        end_index : str
+            feature end  index  [in calendar].
+        freq : str
+            feature frequency.
+
+        Returns
+        ----------
+        pd.Series
+            feature series: The index of the series is the calendar index
+        """
+        from .cache import H  # pylint: disable=C0415
+
+        # cache
+        args = str(self), self.instrument, start_index, end_index, freq
+        if args in H["f"]:
+            return H["f"][args]
+        if start_index is not None and end_index is not None and start_index > end_index:
+            raise ValueError("Invalid index range: {} {}".format(start_index, end_index))
+        try:
+            series = self._load_internal(self.instrument, start_index, end_index, freq)
+        except Exception as e:
+            get_module_logger("data").debug(
+                f"Loading data error: instrument={instrument}, expression={str(self)}, "
+                f"start_index={start_index}, end_index={end_index}, freq={freq}. "
+                f"error info: {str(e)}"
+            )
+            raise
+        series.name = str(self)
+        H["f"][args] = series
+        return series
+
+    def _load_internal(self, instrument, start_index, end_index, freq):
+        series = self.feature.load(self.instrument, start_index, end_index, freq)
+        return series
+
+    def get_longest_back_rolling(self):
+        return self.feature.get_longest_back_rolling()
+
+    def get_extended_window_size(self):
+        return self.feature.get_extended_window_size()
+
+
 #################### Element-Wise Operator ####################

@@ -1541,6 +1625,7 @@ class TResample(ElemOperator):

 TOpsList = [TResample]
 OpsList = [
+    ChangeInstrument,
     Rolling,
     Ref,
     Max,

* update expm.py

* removed duplicate implementation for ChangeInstrument
2022-09-02 17:32:31 +08:00
you-n-g
dffaeaf07b Fix CI pylint bug (#1270)
* Fix CI pylint bug

* Update log.py
2022-08-30 08:53:57 +08:00
animic
157ef529bb update recorder.rst (#1264) 2022-08-29 17:50:51 +08:00
Linlang
ae85562a03 fix_yahoo_collector_bug (#1257) 2022-08-29 17:49:14 +08:00
Huoran Li
1d65d28b28 Qlib simulator refinement (redo of PR 1244) (#1262)
* Use dict-like configuration

* Rename from_neutrader to integration

* SAOE strategy

* Optimize file structure

* Optimize code

* Format code

* create_state_maintainer_recursive

* Remove explicit time_per_step

* CI test passed

* Resolve PR comments

* Pass all CI

* Minor test issue

* Refine SAOE adapter logic

* Minor bugfix

* Cherry pick updates

* Resolve PR comments

* CI issues

* Refine adapter & saoe_data logic

* Resolve PR comments

* Resolve PR comments

* Rename ONE_SEC to EPS_T; complete backtest loop

* CI issue

* Resolve Yuge's PR comments
2022-08-24 14:09:45 +08:00
路旁的叶修
e78fe48a26 Update signal_strategy.py (#1251) 2022-08-22 17:45:54 +08:00
OussCHE
8480407150 fixes #1187 error "Please install necessary libs for CatBoostModel." (#1246)
* Update __init__.py

* Update __init__.py
2022-08-22 17:17:07 +08:00
you-n-g
a25b736c64 Refine type hint and recorder (#1248)
* Refine type hint and recorder

* log environment automatically

* Add literal annotation

* fix type hint bug 3.7
2022-08-12 22:48:13 +08:00