Skip to content

refactor(constants): single source of truth for A-share constants (P1.1)#64

Merged
Jcstack merged 1 commit into
mainfrom
refactor/p1-ashare-constants
Jun 26, 2026
Merged

refactor(constants): single source of truth for A-share constants (P1.1)#64
Jcstack merged 1 commit into
mainfrom
refactor/p1-ashare-constants

Conversation

@Jcstack

@Jcstack Jcstack commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Closes #47. The lot size, commission/stamp rates, max-position cap, and board price limits were re-declared as literal defaults in trading, strategy, backtest, and risk modules. Introduces src/utils/ashare_constants.py as the canonical source; the sites now import the shared values instead of re-hardcoding them.

  • strategy/base.py: PRICE_LIMITS imported from canonical and re-exported (so backtest/engine's from src.strategy.base import PRICE_LIMITS is unchanged); numeric defaults reference LOT_SIZE/COMMISSION_RATE/STAMP_DUTY_RATE.
  • trading/constraints.py: CHINEXT/STAR prefixes + numeric defaults from canonical.
  • risk/position_sizer.py: LOT_SIZE / MAX_SINGLE_POSITION from canonical.

Behavior-preserving — all values identical. Verified: PRICE_LIMITS identity-equal across the re-export chain; 249 strategy/backtest/constraint/risk tests green; ruff clean.

Scope note: each module's board-detection logic still lives locally (the implementations genuinely diverge — decimal vs percent limits, differing BSE handling). Unifying that logic is a deeper, behavior-sensitive follow-up; this PR removes the duplicated constants, which was the drift hazard. Simulation-only; not investment advice.

…nts (#47)

Closes #47 (P1.1). The lot size, commission/stamp rates, max-position cap, and
board price limits were re-declared as literal defaults across trading,
strategy, backtest, and risk modules. Introduce src/utils/ashare_constants.py
as the canonical source and import the shared values instead of re-hardcoding:

- strategy/base.py: PRICE_LIMITS now imported from the canonical module (and
  re-exported, so backtest/engine's `from src.strategy.base import PRICE_LIMITS`
  is unchanged); numeric defaults reference LOT_SIZE/COMMISSION_RATE/STAMP_DUTY_RATE.
- trading/constraints.py: CHINEXT/STAR prefixes + numeric defaults from canonical.
- risk/position_sizer.py: LOT_SIZE / MAX_SINGLE_POSITION from canonical.

All values are identical to before — behavior-preserving (verified: PRICE_LIMITS
identity-equal across the re-export chain, 249 strategy/backtest/constraint/
risk tests green, ruff clean).

Note: each module's board-*detection* logic and rule application still live
locally (they genuinely diverge — decimal vs percent limits, differing BSE
handling). Unifying that logic is a deeper, behavior-sensitive follow-up; this PR
consolidates the constants, which was the drift hazard.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Jcstack
Jcstack enabled auto-merge (squash) June 26, 2026 03:32
@Jcstack
Jcstack merged commit 06798c4 into main Jun 26, 2026
5 of 6 checks passed
@Jcstack
Jcstack deleted the refactor/p1-ashare-constants branch June 26, 2026 07:31
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.

[P1.1] A-share constraints reimplemented 4× — consolidate to one module

1 participant