Build a portfolio environment in which an agent observes market features and current holdings, chooses target weights, and receives a reward based on net portfolio growth or a stated utility. The environment must enforce trading constraints, apply costs and update positions after returns. Validate the resulting policy chronologically against simple allocations and under changed execution assumptions.
Specify the state, action and reward as a trading problem
An agent starts at 60% stock and 40% cash. It targets 80% stock and 20% cash. It trades 20% of equity in the stock, so a 10-basis-point fee per dollar of risky-asset turnover costs 2 basis points of equity. If the stock then gains 1% and cash earns zero, portfolio value is multiplied by . The new stock weight drifts to . The next decision must use this drifted weight.
If it instead stays at 60% stock, the next portfolio value is 1.006 times starting equity with no trading fee. One favourable episode does not settle whether the rebalance is sensible. A policy needs to make that decision repeatedly under the distribution of outcomes and costs it will face.
Include the existing holdings in the state because they affect the cost of the next action. Two agents can observe the same prices and forecasts yet face different trades to reach the same target weights. Apply prices and costs in the order they would occur after the decision, then carry post-move weights into the next state. If every episode starts from cash, check that the reset does not conveniently erase risky positions or avoid a liquidation cost. A simple periodic rebalance provides a baseline under the same execution model.
References and next steps
- Liu et al., FinRL describes an educational financial RL library with trading constraints, costs and portfolio-allocation examples.
- How to Build and Plot an Efficient Frontier in Python