Repository navigation
Replies: 5 comments
|
---> This is for vectorbt stock universes. And it is for backtrader, but it helps for vectorbt also. |
def find_code () :
code_df = vbt.AQuantData.get_codes( market='KOSDAQ' )
df = []
for index in range(0, len(code_df)) :
row = code_df.iloc[index]
if (float(config['min_cap']) < row['marcap'] < float(config['max_cap'])) and (row['amount'] > 0) :
df.append(row)
|
|
@bsjung I had a quick look at the links you shared, and they don't address the question of a dynamic universe. I am not sure if this is possible in vbt but a workaround would be to get the data for all symbols that are going to be needed. Schematically, this is universe_mask = pd.DataFrame(False, index=dates, columns=all_symbols) for date in dates: You can then use the mask for your entries and exits |
|
any solution find yet? |
|
You can model this in vectorbt, but I would think of it as a point-in-time universe mask, not as instruments being dynamically loaded during the backtest. For weekly top-N liquidity rebalancing, the usual shape is: # close/volume/etc: DataFrames indexed by date, columns=symbols
liq = (close * volume).rolling(20).mean()
# Important: decide membership using data known before the rebalance bar
liq_rank = liq.shift(1).rank(axis=1, ascending=False, method="first")
universe = liq_rank <= 1000
# If membership changes only weekly, compute on rebalance dates and ffill
rebalance = close.index.to_series().dt.weekday == 0
weekly_universe = universe.where(rebalance).ffill().fillna(False)
entries = raw_entries & weekly_universe
exits = raw_exits | ~weekly_universeFor "top N% / bottom Y% / greater than threshold", the same idea works: build one boolean mask per condition from point-in-time ranks or thresholds, then combine it with entries/exits or with your target weight matrix. The harder part is not whether vectorbt can consume the mask; it is memory and lookahead control when you have the whole market plus 100+ rolling indicators. A few practical rules:
So yes, this type of strategy is possible in a vectorized style, but the clean design is: precompute point-in-time eligibility/score matrices -> combine into entries/weights -> run portfolio simulation. Avoid selecting today’s universe from future information, and avoid treating “currently top 1000” as the historical universe. |

Uh oh!
There was an error while loading. Please reload this page.
Wonder if vbt support dynamic universe and rebalance? For example, rebalance every weekend, when rebalancing, only trade top 1000 most liquid stocks.
All reactions