Risk-Based Position Sizing with Portfolio and Trade History Adjustments
Summary
This document presents a library of trading functions for opening and closing positions and calculating trade size. Its sizing routine estimates the loss budget from account equity or balance and a user-specified risk percentage, then divides that budget by the estimated cost of a stop distance based on daily volatility. It also checks a portfolio-based size limit and can optionally adjust size using prior profit and loss history before applying broker constraints.
The code includes checks for connectivity and zero point cost, and accounts for instrument-specific tick values, point sizes, minimum lot sizes, and lot precision. The author reports use across multiple brokers and instruments, but provides no independent performance analysis or detailed validation. Because the position-risk estimate uses daily volatility to set stop distance, users would need to assess whether that assumption suits their strategy and instruments.
Key ideas
- The sizing routine converts a risk percentage into a position size using account value, daily volatility, and instrument point costs.
- The final size is capped by a portfolio-based calculation and may be adjusted using historical profit and loss.
- Broker-specific minimum sizes and lot precision are applied before returning the position size.
- The document provides code and an author-reported usage history, but no independent performance evidence.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.