Portfolio Backtesting with Weight Files | by DolphinDB | MediumSitemapOpen in appSign up<br>Sign in
Medium Logo
Get app<br>Write
Search
Sign up<br>Sign in
Portfolio Backtesting with Weight Files
DolphinDB
9 min read·<br>Dec 30, 2025
Listen
Share
Press enter or click to view image in full size
In quantitative investment, portfolio backtesting is a core process for evaluating the stability of investment strategies and their return-risk characteristics. Whether for index enhancement strategies, dollar-cost averaging fund portfolio, or model portfolios used in institutional asset management, strategy performance depends on portfolio weight adjustments and execution efficiency across different market phases. Portfolio weights are typically generated by external strategy modules or research teams, often based on machine learning models, risk budgeting frameworks, sector allocation schemes, or factor scoring systems. Weight data is generally output and stored daily or at predetermined intervals to drive portfolio construction and rebalancing. Efficiently combining these weight files with market data to build a backtesting system that automatically rebalances at fixed intervals is a crucial foundation for portfolio strategy research.<br>This tutorial demonstrates a backtesting case of portfolio investment with daily rebalancing based on given weight files using the DolphinDB backtest plugin. By parsing daily weight files and simulating the actual portfolio position adjustment process at different time points, this case helps researchers systematically evaluate the historical performance and stability of portfolio strategies.<br>1. Background<br>This tutorial demonstrates how to construct a passive investment strategy that automatically rebalances a stock portfolio daily based on external portfolio weight files. The strategy takes predefined asset weights as the main input and dynamically adjusts portfolio positions according to daily (or specified periodic) target weight files during backtesting, thereby simulating the rebalancing process of actual portfolios in different market conditions.<br>This chapter briefly introduces the core concepts of stock portfolio management, passive rebalancing mechanisms based on weight files, and the application of DolphinDB’s high-performance backtesting framework in portfolio strategy research.<br>1.1 Stock Portfolio Management Strategy<br>This strategy aims to simulate the process of actual portfolio weight adjustments at specific intervals (daily, weekly, monthly, or quarterly) to evaluate the return and risk performance of different weight allocation schemes in historical market environments. The core idea is that, at the beginning of each rebalancing period, adjust the position ratio of each stock according to predefined or weight files to align portfolio positions with target weights, thereby achieving systematic asset allocation and risk control.<br>In stock portfolio management and index enhancement strategies, portfolio rebalancing at fixed frequencies is a common and critical investment management technique. Unlike active trading strategies based on real-time signals, such passive portfolio rebalancing strategies do not rely on immediate market predictions but focus on verifying the long-term stability and diversification effects of the weight allocation itself. Researchers can independently evaluate the performance differences of weight schemes generated by different factor scoring, sector rotation, or optimization algorithms over historical periods, thereby providing empirical validation for asset allocation models or quantitative stock selection models.<br>To achieve the above objectives, this tutorial uses DolphinDB’s high-performance backtesting engine to build a portfolio backtesting system. The system can efficiently load historical market data including multiple securities, parse external weight files, and execute rebalancing operations at specified frequencies. Through the engine’s event-driven framework, the strategy can compare differences between current positions and target weights daily or at specified intervals, automatically submit buy/sell orders, and record the trade execution process. Combined with backtesting results, users can further analyze portfolio net value changes, volatility, maximum drawdown, Sharpe ratio, and other performance indicators, providing quantitative evaluation basis for the effectiveness and stability of different rebalancing strategies.<br>1.2 DolphinDB’s High-Frequency Backtesting Solution<br>The implementation of medium-to-high-frequency quantitative trading strategy backtesting mainly includes three important components: sequential market data replay, order matching, and strategy development with backtesting performance evaluation. However, implementation often faces the following challenges:<br>First, massive medium-to-high-frequency trading data places extremely high demands on the query and computation performance of backtesting engines.<br>Second, to ensure...