Risk & position-sizing checksIntermediate#position-sizing#checklist#python

Check position size and portfolio heat before you trade

Run a local Python script on your planned entry, stop and positions CSV, and paste only its stdout. The agent checks size, heat, theme concentration and, when present, correlation against your limits, and leaves the decision to you.

How it works

  1. Prepare your files (positions CSV with columns ticker, theme, entry, stop, shares, market_value plus any return series for correlation; limits file with your numeric thresholds). Correlation is read from a matrix or return series already in your files (no live fetch); reserve symbol for the planned trade only. Google Sheets is only for editing before CSV export; never upload real portfolio files to any AI.
  2. You run the sizing script locally with the planned symbol, entry, stop, account equity and risk percent as inputs; it computes the size that risks your chosen percentage of the account at that stop.
  3. The script adds total open heat across existing positions, theme concentration from the tags in the file, and, if the file has return history, correlation; otherwise it omits correlation.
  4. You paste only the planned symbol, entry, stop, theme, the full script stdout, and the numeric limits into the prompt. Do not paste the positions CSV, a positions data summary, or any return series.
  5. The agent reads the pasted stdout, explains the numbers and flags anything over your written limits.
  6. You decide; the agent has no connection to any order system.

Copy-paste prompt

You are my sizing calculator. You have no order access and you do not recommend whether to take a trade.
Inputs I will paste: symbol={{symbol}}, entry={{entry}}, stop={{stop}}, theme={{theme}}, stdout from running {{sizing_script}} locally, and the numeric limits from {{limits_file}}. Do not ask for {{positions_csv}}.
Long-only only. If stop >= entry, stop and say risk per share is undefined.
1. Do not run code, do not open my files, and do not ask me to paste the positions CSV. Report only these figures from the pasted stdout: shares, dollar risk, percent risk, heat after the trade, theme concentration, correlation. Do not recompute any number. If stdout is missing, stop and ask for it.
2. Flag any figure above the numeric limits I pasted from {{limits_file}}.
3. Do not comment on whether the trade is good.

Guardrails

  • The agent has no order access.
  • Limits come from your written file, not from the model.
  • Numbers computed in code.
  • Run the Python script entirely locally on your machine; never upload positions.csv, returns data or real/anonymized brokerage files to any AI service. Paste only the script stdout into the prompt. This prevents data leakage, API cost surprises and the hallucinated numbers documented in what_failed.

What can go wrong

A 20-day correlation after a market-wide drop marked two unrelated holdings as highly correlated and the check talked you out of a valid long. And when the script path was wrong the model invented a share count. Theme concentration is only as good as the tags in your positions file, and heat goes stale if you do not refresh the file after fills.

Why it helps

Consistent risk per trade is the one habit almost every trading book agrees on. A calculator that also shows total heat keeps you honest. You need a local sizing script, a positions file with theme tags, and a written limits file. The agent does not place orders and does not judge the setup; it only reads the pasted script output and explains it against your limits.

The script must use these formulas, with risk_pct as a decimal (0.01 = 1%): risk per share = entry − stop; shares = floor(account_equity × risk_pct / risk per share); dollar risk = shares × risk per share; heat = sum of open dollar risk including this trade, divided by equity; theme concentration = market value of that theme including this trade (entry × shares), divided by equity; correlation = maximum pairwise Pearson correlation of 20-session daily returns between the planned symbol and each open position, from a series or matrix already in your files. If that series has fewer rows than the window, omit correlation. Do not correlate closing prices and do not fetch data. Compare heat and theme concentration to limits only after converting those ratios to percent.

Setup notes

Create positions.csv with columns: ticker,theme,entry,stop,shares,market_value. limits_file.txt lists max_risk_pct, max_heat_pct, max_theme_pct and max_pairwise_corr (for example max_heat_pct=6 and max_theme_pct=25; give max_risk_pct as a percent and max_pairwise_corr as a decimal from -1 to 1, using your own numbers). sizing_script is a short local Python function (pandas is enough) that applies those formulas to your CSVs. It does not pull prices from public sources, makes no live fetches or public API calls, and runs entirely on your machine.

Source and references

Original write-up by Agents for Traders. Background reading is linked below.

Spotted an error, or want your post removed? Email hello@agentsfortraders.com.

Educational content only. Not investment advice or a personal recommendation. No tickers, signals or trade alerts. Trading involves risk of loss.

Conteúdo exclusivamente educativo. Não constitui aconselhamento nem recomendação de investimento. Sem tickers, sinais ou alertas de negociação. Negociar envolve risco de perda.

Related use cases