Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

TopkDropoutStrategy ignores get_risk_degree() for position sizing

Aperta Adatta ai principianti
#2,276 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

@zhaow-de ci sta già lavorando.

Dal 21/6/2026.

  • #2277 di @zhaow-de — aperta
  • #2281 di @yinli-systems — chiusa senza merge
  • #2286 di @Whning0513 — chiusa senza merge
  • #2331 di @akshaykumarhudedmani — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
python
Ambito
fintech-quant

Direzione di ricerca

Leggi qlib/contrib/strategy/signal_strategy.py, in particolare TopkDropoutStrategy.generate_trade_decision intorno alla riga 266 e la documentazione di get_risk_degree() vicino alla riga 69. Confronta il relativo percorso di sizing con WeightStrategyBase intorno alla riga 365, quindi verifica che un getter sovrascritto influenzi il sizing degli acquisti, mentre il comportamento esistente della strategia rimane invariato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

🐛 Bug Description

get_risk_degree() is documented as the dynamic market-timing hook ("Dynamically risk_degree will result in Market timing.", qlib/contrib/strategy/signal_strategy.py:69). But TopkDropoutStrategy.generate_trade_decision sizes new buys with the raw attribute self.risk_degree, not the getter:

# qlib/contrib/strategy/signal_strategy.py:266
value = cash * self.risk_degree / len(buy) if len(buy) > 0 else 0

It is the only use of risk_degree in TopkDropoutStrategy, and it bypasses get_risk_degree(). So a subclass that overrides get_risk_degree() to return a time-varying multiplier (the documented way to implement market timing) has zero effect on a TopkDropout book — the override is never called. (By contrast, WeightStrategyBase at line 365 and its subclass EnhancedIndexingStrategy at line 482 do call self.get_risk_degree(...), so the inconsistency is within the same module.)

To Reproduce

  1. Subclass TopkDropoutStrategy and override get_risk_degree() to return, say, 0.0 on some dates (a regime gate to cash) and self.risk_degree otherwise.
  2. Backtest it vs. the un-subclassed TopkDropoutStrategy on the same signal.
  3. The two produce identical trades/returns — the overridden get_risk_degree() is never consulted for buy sizing.

Expected Behavior

TopkDropoutStrategy should size buys with self.get_risk_degree(trade_step) (as WeightStrategyBase does), so that overriding get_risk_degree() actually enables market timing as documented:

value = cash * self.get_risk_degree(trade_step) / len(buy) if len(buy) > 0 else 0

Environment

  • Qlib version: 0.9.7 (qlib/contrib/strategy/signal_strategy.py (TopkDropoutStrategy.generate_trade_decision, line ~266)
  • Python version: 3.12

Additional context

Discovered while building a BTC-trend regime overlay (RegimeGatedTopkStrategy(TopkDropoutStrategy)) that gates gross exposure via get_risk_degree(). The overlay had no effect on backtests until we worked around it by pushing the gated value onto self.risk_degree per step before delegating to super().generate_trade_decision(). A two-line fix in TopkDropoutStrategy (use the getter) would remove the need for the workaround.

Lingua principale
Python
Stelle
49.5k
Fork
7.8k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/qlib

Tutte le issue di microsoft/qlib

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.