Skip to content

Commit 39f88da

Browse files
SunsetWolfLinlang
andauthored
download orderbook data (#1754)
* download orderbook data * fix CI error * fix CI error * test fix CI error * test fix CI error * test fix CI error * test fix CI error * test fix CI error * test fix CI error * test fix CI error * test fix CI error * test fix CI error * test fix CI error * test fix CI error * test fix CI error * test fix CI error * test fix CI error * test fix CI error * test fix CI error * test fix CI error * test fix CI error * test fix CI error * optimize get_data code * optimize get_data code * optimize get_data code * optimize README --------- Co-authored-by: Linlang <v-linlanglv@microsoft.com>
1 parent 98f569e commit 39f88da

File tree

14 files changed

+30
-34
lines changed

14 files changed

+30
-34
lines changed

examples/benchmarks/TRA/src/model.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ def predict(self, dataset, segment="test"):
324324

325325

326326
class LSTM(nn.Module):
327-
328327
"""LSTM Model
329328
330329
Args:
@@ -414,7 +413,6 @@ def forward(self, x):
414413

415414

416415
class Transformer(nn.Module):
417-
418416
"""Transformer Model
419417
420418
Args:
@@ -475,7 +473,6 @@ def forward(self, x):
475473

476474

477475
class TRA(nn.Module):
478-
479476
"""Temporal Routing Adaptor (TRA)
480477
481478
TRA takes historical prediction errors & latent representation as inputs,

examples/orderbook_data/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ pip install arctic # NOTE: pip may fail to resolve the right package dependency
2727
2. Please follow following steps to download example data
2828
```bash
2929
cd examples/orderbook_data/
30-
wget http://fintech.msra.cn/stock_data/downloads/highfreq_orderboook_example_data.tar.bz2
31-
tar xf highfreq_orderboook_example_data.tar.bz2
30+
python ../../scripts/get_data.py download_data --target_dir . --file_name highfreq_orderbook_example_data.zip
3231
```
3332

3433
3. Please import the example data to your mongo db
3534
```bash
36-
cd examples/orderbook_data/
3735
python create_dataset.py initialize_library # Initialization Libraries
3836
python create_dataset.py import_data # Initialization Libraries
3937
```
@@ -42,7 +40,6 @@ python create_dataset.py import_data # Initialization Libraries
4240

4341
After importing these data, you run `example.py` to create some high-frequency features.
4442
```bash
45-
cd examples/orderbook_data/
4643
pytest -s --disable-warnings example.py # If you want run all examples
4744
pytest -s --disable-warnings example.py::TestClass::test_exp_10 # If you want to run specific example
4845
```

qlib/backtest/__init__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,15 @@ def create_account_instance(
162162
init_cash=init_cash,
163163
position_dict=position_dict,
164164
pos_type=pos_type,
165-
benchmark_config={}
166-
if benchmark is None
167-
else {
168-
"benchmark": benchmark,
169-
"start_time": start_time,
170-
"end_time": end_time,
171-
},
165+
benchmark_config=(
166+
{}
167+
if benchmark is None
168+
else {
169+
"benchmark": benchmark,
170+
"start_time": start_time,
171+
"end_time": end_time,
172+
}
173+
),
172174
)
173175

174176

qlib/backtest/report.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,9 +622,11 @@ def cal_trade_indicators(
622622
print(
623623
"[Indicator({}) {}]: FFR: {}, PA: {}, POS: {}".format(
624624
freq,
625-
trade_start_time
626-
if isinstance(trade_start_time, str)
627-
else trade_start_time.strftime("%Y-%m-%d %H:%M:%S"),
625+
(
626+
trade_start_time
627+
if isinstance(trade_start_time, str)
628+
else trade_start_time.strftime("%Y-%m-%d %H:%M:%S")
629+
),
628630
fulfill_rate,
629631
price_advantage,
630632
positive_rate,

qlib/contrib/eva/alpha.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
The interface should be redesigned carefully in the future.
55
"""
6+
67
import pandas as pd
78
from typing import Tuple
89
from qlib import get_module_logger

qlib/contrib/model/pytorch_tra.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,6 @@ def predict(self, dataset, segment="test"):
511511

512512

513513
class RNN(nn.Module):
514-
515514
"""RNN Model
516515
517516
Args:
@@ -601,7 +600,6 @@ def forward(self, x):
601600

602601

603602
class Transformer(nn.Module):
604-
605603
"""Transformer Model
606604
607605
Args:
@@ -649,7 +647,6 @@ def forward(self, x):
649647

650648

651649
class TRA(nn.Module):
652-
653650
"""Temporal Routing Adaptor (TRA)
654651
655652
TRA takes historical prediction errors & latent representation as inputs,

qlib/contrib/strategy/signal_strategy.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ def generate_trade_decision(self, execute_result=None):
373373

374374

375375
class EnhancedIndexingStrategy(WeightStrategyBase):
376-
377376
"""Enhanced Indexing Strategy
378377
379378
Enhanced indexing combines the arts of active management and passive management,

qlib/model/ens/ensemble.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def __call__(self, ensemble_dict: dict, *args, **kwargs):
3030

3131

3232
class SingleKeyEnsemble(Ensemble):
33-
3433
"""
3534
Extract the object if there is only one key and value in the dict. Make the result more readable.
3635
{Only key: Only value} -> Only value
@@ -64,7 +63,6 @@ def __call__(self, ensemble_dict: Union[dict, object], recursion: bool = True) -
6463

6564

6665
class RollingEnsemble(Ensemble):
67-
6866
"""Merge a dict of rolling dataframe like `prediction` or `IC` into an ensemble.
6967
7068
NOTE: The values of dict must be pd.DataFrame, and have the index "datetime".

qlib/model/riskmodel/shrink.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,7 @@ def _get_shrink_param_lw_single_factor(self, X: np.ndarray, S: np.ndarray, F: np
247247
v1 = y.T.dot(z) / t - cov_mkt[:, None] * S
248248
roff1 = np.sum(v1 * cov_mkt[:, None].T) / var_mkt - np.sum(np.diag(v1) * cov_mkt) / var_mkt
249249
v3 = z.T.dot(z) / t - var_mkt * S
250-
roff3 = (
251-
np.sum(v3 * np.outer(cov_mkt, cov_mkt)) / var_mkt**2 - np.sum(np.diag(v3) * cov_mkt**2) / var_mkt**2
252-
)
250+
roff3 = np.sum(v3 * np.outer(cov_mkt, cov_mkt)) / var_mkt**2 - np.sum(np.diag(v3) * cov_mkt**2) / var_mkt**2
253251
roff = 2 * roff1 - roff3
254252
rho = rdiag + roff
255253

qlib/workflow/online/strategy.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ def get_collector(self) -> Collector:
9090

9191

9292
class RollingStrategy(OnlineStrategy):
93-
9493
"""
9594
This example strategy always uses the latest rolling model sas online models.
9695
"""

0 commit comments

Comments
 (0)