Skip to content

feat: add REG_GB (London Stock Exchange) core region support#2156

Open
kaish114 wants to merge 5 commits intomicrosoft:mainfrom
kaish114:feat/add-reg-gb-core-region
Open

feat: add REG_GB (London Stock Exchange) core region support#2156
kaish114 wants to merge 5 commits intomicrosoft:mainfrom
kaish114:feat/add-reg-gb-core-region

Conversation

@kaish114
Copy link
Copy Markdown

@kaish114 kaish114 commented Mar 14, 2026

Summary

This PR adds core framework support for REG_GB (London Stock Exchange) as a new trading region in Qlib, complementing the Yahoo Finance data collector support added in #2155.

Changes:

  • qlib/constant.py: Add REG_GB = "gb" constant
  • qlib/config.py: Add REG_GB to _default_region_config with LSE-appropriate defaults (trade_unit=1, limit_threshold=None, deal_price="close")
  • qlib/utils/time.py: Add GB_TIME (08:00–16:30, no midday break) and wire REG_GB into get_min_cal, is_single_value, and time_to_day_index
  • tests/misc/test_utils.py: Add GBTimeUtils test class covering get_min_cal, is_single_value, and time_to_day_index for REG_GB

LSE trading hours: 08:00–16:30 Europe/London, continuous session (no lunch break), 510 one-minute bars per day.

Timezone & DST note

GB_TIME uses timezone-naive local hours (08:00–16:30), consistent with how all other regions (including REG_US which also observes DST) are handled in Qlib. The LSE always opens and closes at the same local time regardless of GMT/BST, so the 510-bar calendar is stable year-round. DST resolution for minute-level data is handled at collection time via _timezone = "Europe/London" in the Yahoo Finance collector (PR #2155). This is the same design assumption as the existing US region implementation.

Test plan

  • tests/misc/test_utils.py::TimeUtils::test_cal_sam_minute passes with REG_GB in the regions list
  • tests/misc/test_utils.py::GBTimeUtils — 10 new tests: calendar count (510 bars), open/close times, is_single_value (last bar, mid-session, sub-freq window), time_to_day_index (open, mid, last bar, out-of-range ValueError)
  • All 12 tests in tests/misc/test_utils.py pass
  • black -l 120 --target-version py311 — no changes needed

Add GB_TIME constant (08:00-16:30 Europe/London, no midday break) and
wire REG_GB into get_min_cal, is_single_value, and time_to_day_index.
Covers: 510-bar calendar count, open/close bar times, last-bar
single-value detection, mid-session multi-value, index arithmetic,
and out-of-range ValueError for GB (London Stock Exchange) region.
@kaish114
Copy link
Copy Markdown
Author

CI failures are pre-existing infrastructure issues, not related to this PR

All failing checks trace back to two pre-existing issues in the CI environment — neither is caused by changes in this PR.

1. test_pit.py — East Money API unreachable from GitHub Actions runners

The test_pit.py setup calls get_calendar_list() in scripts/data_collector/utils.py, which makes an HTTP request to the East Money (东方财富) API to fetch the CSI300 trading calendar:

GET https://push2his.eastmoney.com/api/qt/stock/kline/get?secid=1.000300&...
ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

This API is unreachable from GitHub Actions runners (geo-restricted or rate-limited outside China). All 5 test_pit.py tests pass locally.

2. rl/test_trainer.py::test_trainer_earlystop — flaky float comparison

FAILED rl/test_trainer.py::test_trainer_earlystop - assert 30.0 > 30

Pre-existing floating-point precision issue in the RL trainer test, unrelated to this PR.


This PR's tests — all pass

This PR only modifies qlib/constant.py, qlib/config.py, qlib/utils/time.py, and tests/misc/test_utils.py. Running the full test suite locally (Python 3.13, macOS):

misc/test_utils.py ............   [12/12 passed]

All 12 tests in misc/test_utils.py pass, including the 10 new GBTimeUtils tests added in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant