agentleFS
ntaffziintaffzii/Skill-Agents/skills/trading/position-sizer/SKILL.md

position-sizer

Skill4 starsChanged 2 months agoMITView on GitHub

Use this skill to calculate a risk-based position size (how many shares to buy) from an account size, risk tolerance, entry price, and stop distance. Trigger on "how many shares should I buy", "position size", "risk per trade", "ATR-based stop", "Kelly criterion", "risk 1% of account". If the user hasn't given a stop-loss level or risk percentage, ask for those before calculating — sizing without a defined risk per trade isn't really position sizing.

3 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 3 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    No stop-loss level or risk percentage has been specified — ask for these first.

    line 23
  2. Very specific:

    ATR-based stop: instead of a fixed percentage stop, scale the stop distance to the security's own recent volatility: stop_price = …

    line 38
  3. Very specific:

    Run python3 size.py for the self-test.

    line 59
  4. Distinctive:

    Does not model fractional shares, lot-size minimums, or broker-specific constraints — output is whole shares only.

    line 63
  5. Distinctive:

    Does not account for commissions/slippage in the risk calculation.

    line 64

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Position Sizer

Overview

"How many shares should I buy?" only has a defensible answer once you know how much you're willing to lose if the stop is hit. This skill does the arithmetic — fixed-fractional risk sizing, ATR-based stop distance, and Kelly criterion — on numbers the user supplies. It does not fetch prices or recommend a trade.

Not financial advice. This calculates how many shares fit a chosen risk budget; it does not evaluate whether the trade itself is a good idea.

When to use

  • คำนวณจำนวนหุ้นที่ควรซื้อ ตามความเสี่ยงที่รับได้ต่อไม้
  • Sizing a position given account equity, entry price, and a stop-loss level
  • Converting ATR (Average True Range) into a volatility-scaled stop and matching position size
  • Estimating a Kelly-criterion fraction from historical win-rate/win-loss stats (as an upper bound, not a recommendation — see Known limitations)

When NOT to use

  • No stop-loss level or risk percentage has been specified — ask for these first; sizing "how many shares fit my account" without a risk budget is really just "how much can I afford," a different question
  • The user wants a signal on whether to take the trade at all — this skill only sizes a trade already decided on

Core knowledge

Fixed-fractional sizing: risk a fixed percentage of account equity per trade.

dollar_risk_per_share = |entry_price - stop_price|
total_risk_amount = account_equity × risk_pct
shares = floor(total_risk_amount / dollar_risk_per_share)

Shares are always rounded down so actual dollar risk never exceeds the budget. Common risk_pct defaults discussed in trading literature range roughly 0.5%-2% per trade — this skill doesn't assert a "correct" number; ask the user or use their stated tolerance.

ATR-based stop: instead of a fixed percentage stop, scale the stop distance to the security's own recent volatility: stop_price = entry_price - (ATR × multiplier), commonly multiplier 1.5-3×. Then size with the same fixed-fractional formula using this derived stop distance.

Kelly criterion: f = win_rate - (1 - win_rate) / b, where b = avg_win / avg_loss. This gives the theoretically optimal fraction of capital to risk given accurate win-rate/win-loss inputs — in practice those inputs are estimated from limited history and are often wrong, so full Kelly is aggressive and prone to large drawdowns from estimation error. Traders commonly use a fraction of it ("half Kelly" or less). This skill returns the raw fraction and does not apply that discount — treat it as an upper bound to discuss, not a size to use directly.

Common mistakes

  1. Sizing a position without a defined stop — there's no "risk per share" to base the calculation on.
  2. Rounding shares up instead of down — rounding up means actual dollar risk can exceed the stated budget.
  3. Using full Kelly fraction directly as a position size without acknowledging estimation-error risk.
  4. Treating ATR multiplier or risk percentage as fixed universal constants — both are user/strategy-specific choices this skill takes as parameters, not defaults to assert.
  5. Confusing dollar_risk_per_share (entry-to-stop distance) with position_value (entry price × shares) — a small risk-per-share doesn't mean a small total position value; report both.

Code

size.py — pure Decimal arithmetic, no dependencies:

  • fixed_fractional_size(account_equity, risk_pct, entry_price, stop_price) → SizeResult(shares, dollar_risk_per_share, total_risk_amount, actual_risk_amount, position_value)
  • atr_based_stop(entry_price, atr, multiplier=2.0) → stop price
  • atr_based_size(account_equity, risk_pct, entry_price, atr, multiplier=2.0) → SizeResult, derives the stop from ATR first
  • kelly_fraction(win_rate, avg_win, avg_loss) → raw Kelly fraction (see caveat above)

Run python3 size.py for the self-test.

Known limitations

  • Does not model fractional shares, lot-size minimums, or broker-specific constraints — output is whole shares only.
  • Does not account for commissions/slippage in the risk calculation.
  • Kelly fraction is highly sensitive to input estimation error — never present the raw output as a recommended size without flagging that.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.