Sub topic 12
Sizing your first position
This chapter assumes you can read a quote (bid, ask, spread), you know how a limit order differs from a market order, and you are comfortable with percentages and simple division. The code is plain Python with no libraries. This is educational material, not investment advice.
Position size and risk are different numbers
Beginners often ask "how much should I buy?" and answer with a dollar amount: "I'll put in $1,000." That number is the position size, the total money you hold in one stock. It does not tell you how much you can lose.
Risk is the amount you lose if the trade goes against you and you exit. Two $1,000 positions can carry very different risk:
- Stock A is calm. You would exit if it fell $0.50 per share.
- Stock B is jumpy. You would exit only if it fell $5 per share.
At the same $1,000 position, Stock B puts ten times more money at stake. The better approach is to pick the amount you are willing to lose first, then let that amount decide how many shares to buy.
The core formula
Three inputs produce the share count:
- Risk amount. The most you accept losing on this trade, usually a small percentage of your account. Many people use 1% or less on early trades.
- Entry price. The price you expect to pay. For a limit buy, use your limit price. For a market buy, use the current ask, and add a little for slippage.
- Exit price. The price where you would decide the idea was wrong and sell. Call it the stop level. It is a decision you make before you buy. It does not have to be a stop order, which a later chapter previews.
The loss per share is the entry price minus the exit price. Then:
risk per share = entry - exit
shares = risk amount / risk per share (round DOWN)Always round down to whole shares, because rounding up quietly raises your risk above your chosen amount.
A worked example
You have a $5,000 account and accept a 1% risk, which is $50. You plan a limit buy of XYZ at $50.00 and would exit at $48.00.
- Risk per share: 50.00 − 48.00 = $2.00
- Shares by risk: 50 / 2.00 = 25
- Cost of 25 shares: 25 × 50.00 = $1,250, which is 25% of the account
Twenty-five shares keep the loss near $50, but the position is a quarter of your account in one stock. That is why a second limit exists.
Three limits, and the smallest one wins
Risk is only one cap on size. Check all three and take the smallest share count.
| Limit | What it protects | How to compute shares |
|---|---|---|
| Risk limit | Your loss if the exit price is hit | risk amount / (entry − exit) |
| Position cap | Concentration in one stock | account × max percent / entry |
| Buying power | What the broker lets you spend | buying power / entry |
A position cap of 20% to 25% of the account is a common guardrail for beginners. It limits the damage when your exit does not work as planned.
import math
def size_position(account, risk_pct, entry, stop,
max_position_pct, buying_power):
risk_per_share = entry - stop
if risk_per_share <= 0:
raise ValueError("For a buy, the stop must be below the entry price.")
limits = {
"risk": math.floor(account * risk_pct / risk_per_share),
"position cap": math.floor(account * max_position_pct / entry),
"buying power": math.floor(buying_power / entry),
}
limited_by = min(limits, key=limits.get)
qty = limits[limited_by]
return {
"qty": qty,
"cost": round(qty * entry, 2),
"max_loss": round(qty * risk_per_share, 2),
"limited_by": limited_by,
}
print(size_position(5000, 0.01, 50.00, 48.00, 0.20, 5000))
print(size_position(5000, 0.01, 50.00, 45.00, 0.20, 5000))
print(size_position(5000, 0.01, 50.00, 49.50, 0.20, 5000))The three calls print:
{'qty': 20, 'cost': 1000.0, 'max_loss': 40.0, 'limited_by': 'position cap'}
{'qty': 10, 'cost': 500.0, 'max_loss': 50.0, 'limited_by': 'risk'}
{'qty': 20, 'cost': 1000.0, 'max_loss': 10.0, 'limited_by': 'position cap'}The function returns limited_by so you can see which rule shaped the answer. The first call is the example above with a 20% cap, so the cap cuts 25 shares to 20. The second call uses a wide exit at $45, so risk is the binding limit and you buy only 10 shares. The third call uses a very tight exit at $49.50. The risk formula would allow 100 shares, but the cap holds you at 20.
Connecting the size to your order ticket
The sizing output feeds straight into the ticket from the earlier chapter. With 20 shares and a limit price of $50.00, the ticket's estimated cost is 20 × 50.00 = $1,000.00 at most, plus fees. The limit price caps what a buy can pay, so your worst-case cost is known before you submit.
A market order is less predictable. You would estimate the cost at the ask, and the average fill can be higher if the order walks up the book. If you size from the ask alone, add a small buffer, for example one spread or a few cents per share, to your entry price before computing risk per share. The loss per share is then slightly larger and the share count slightly smaller, which is the safer direction.
Edge cases and common errors
- Zero shares. If one share costs more than your risk or cap allows, the formula returns 0. Do not force a one-share trade that breaks your own rules. Skip it, choose a cheaper stock, or use fractional shares if your broker offers them.
- Fractional shares. They let you hit a dollar target exactly, but the risk formula still applies. Divide, then round to the precision your broker allows, never up.
- Gaps. A stock can open far below your exit price after bad news overnight. Your real loss is then larger than planned. The formula describes the loss if you exit near your level, not a guarantee. This is one reason to keep position caps and small risk percentages.
- Costs. Commissions, regulatory fees and the spread add to your loss. Subtract expected fees from your risk amount before dividing, or accept that the real loss will run a little above the figure.
- Moving the exit afterward. If you widen the exit because the price is falling, you have raised your risk without changing the size. Decide the exit before you buy, and change it only to reduce risk.
- Sizing from buying power. Margin accounts may show buying power larger than your cash. Buying power is a ceiling set by the broker. It is not a target.
- Confusing the percentages. A 1% risk is not a 1% position. In the example, risking 1% of the account ($50) led to a position of 20% of the account ($1,000).
A short pre-order routine
- Write down the risk amount in dollars.
- Write down entry and exit prices, based on your limit price or the ask.
- Compute shares under all three limits and take the smallest, rounded down.
- Multiply shares by entry to get the cost, and shares by loss per share to get the maximum loss.
- Check that the cost fits inside buying power and the maximum loss matches what you wrote in step 1.
If any step surprises you, change the plan before you open the ticket, not after.
Exercise
Your account is $2,000. You accept a 1.5% risk and plan a limit buy at $20.00 with an exit at $18.50. Your position cap is 25% of the account, and your buying power is $2,000. How many shares do you buy, what is the cost, and which limit decided the answer?
Show answer
Risk amount = 2,000 × 0.015 = $30. Risk per share = 20.00 − 18.50 = $1.50, so shares by risk = 30 / 1.50 = 20. The position cap allows 2,000 × 0.25 = $500, or 500 / 20 = 25 shares. Buying power allows 100 shares. The smallest is 20, so risk decided the answer. Cost = 20 × 20.00 = $400, and the maximum loss is 20 × 1.50 = $30.
Exercise
A stock trades with a bid of 49.98 and an ask of 50.02. You plan a market buy and want to size from a $50 risk amount with an exit at $48.00. Why is it safer to use the ask, or the ask plus a small buffer, as your entry than the last price?
Show answer
A market buy pays the ask or higher, not the last price. Using 50.02 gives a risk per share of 2.02, so shares = floor(50 / 2.02) = 24. Using a last price of 50.00 would give 25 shares, which would risk about 25 × 2.02 = $50.50 and exceed your limit. A buffer for slippage keeps the real loss at or below the amount you chose.