microsoft / microsoft/qlib

Portfolio strategy: TopkDropoutStrategy

Open
#809 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
48.7k
Forks
7.7k
PR merge metrics
No merged PRs in 30d

Description

Hello, thanks for the great effort for the qlib project.

My issue

I found some wried behaviors when using TopkDropoutStrategy strategy.
I expected that the number of portfolio instruments in each day be equal to the top k number.
However, due to the tradable check in the current implementation, the portfolio number changed each day.

The reasons may cause that.
  1. The tradable check is inconsistent in the get_first_n, get_last_n function and the dealing process. Even we set the only_tradable as False, we also check the instruments can be tradable or not.
  2. The buy list should be yielded after we get the true sell list.
  • current implementation:
# Get the stock list we really want to buy
buy = today[: len(sell) + self.topk - len(last)]
for code in current_stock_list:
    if not self.trade_exchange.is_stock_tradable(
        stock_id=code, start_time=trade_start_time, end_time=trade_end_time
    ):
  • the updated implementation:
buy = today[: len(sell_order_list) + self.topk - len(last)] # note that len(sell) -> len(seller_order_list)
current_stock_list = current_temp.get_stock_list()
value = cash * self.risk_degree / len(buy) if len(buy) > 0 else 0

# open_cost should be considered in the real trading environment, while the backtest in evaluate.py does not
# consider it as the aim of demo is to accomplish same strategy as evaluate.py, so comment out this line
# value = value / (1+self.trade_exchange.open_cost) # set open_cost limit
for code in buy:
    # check is stock suspended
    if not self.trade_exchange.is_stock_tradable(
        stock_id=code, start_time=trade_start_time, end_time=trade_end_time
    ):
        continue
  1. Some other problems:
  • I find that the behavior of risk_degree may be different from our common sense. Maybe the risk_degree depends on the total amount value rather than the cash value.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with TopkDropoutStrategy, especially its get_first_n and get_last_n logic and the dealing process shown in the issue; compare these with the trading behavior in evaluate.py. Done means resolving the inconsistent tradable checks, determining the correct buy-list sizing, and clarifying risk_degree behavior without changing the intended backtest strategy.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
fintech-quant
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.