Sub topic 3
Investing by Dollar Amount: Orders and Rounding
Assume you know what a share, stock, ETF, and brokerage account are. You should also be comfortable with division and percentages. This chapter focuses on how a dollar-based order becomes a share quantity.
From dollars to shares
A dollar-based order tells a broker how much money to invest instead of how many shares to buy. The basic calculation is:
\text{shares} = \frac{\text{dollar amount}}{\text{share price}}For example, investing $50 in a stock priced at $300 gives:
50 \div 300 = 0.166666\ldots \text{ shares}A whole-share order could buy zero shares because $50 is less than the $300 price. A fractional-share order can buy part of one share.
The price used in the calculation depends on the order type. A market order executes at available market prices, so the final quantity may differ slightly from your estimate. A limit order specifies the highest price you will pay, or the lowest price at which you will sell. It may not execute if the market does not reach that price.
Precision and rounding
Brokers usually support only a fixed number of decimal places for fractional shares. The broker may round down the quantity so that the purchase does not exceed the available dollar amount.
| Dollar amount | Share price | Exact quantity | Quantity at six decimals |
|---|---|---|---|
| $50.00 | $300.00 | 0.166666... | 0.166666 |
Rounding down leaves a small cash balance. In this example, buying 0.166666 shares at $300 costs $49.9998, leaving about $0.0002 before other adjustments. The broker may handle the remaining cash according to its own rules.
from decimal import Decimal, ROUND_DOWN
amount = Decimal("50.00")
price = Decimal("300.00")
shares = (amount / price).quantize(
Decimal("0.000001"),
rounding=ROUND_DOWN,
)
spent = shares * price
cash_left = amount - spent
print("shares:", shares)
print("spent:", spent)
print("cash left:", cash_left)Do not assume that every broker supports six decimal places. Some brokers restrict fractional trading to certain securities, order types, account types, or trading windows. Some accept dollar-based orders only during regular market hours. Check the broker's current rules before relying on a specific precision or execution method.
What happens when the price changes?
A dollar amount buys fewer shares when the price is high and more shares when the price is low. This is the mechanical reason regular dollar investing can accumulate different quantities over time.
Suppose you invest $100 at prices of $50, $40, $25, $40, and $50:
prices = [50, 40, 25, 40, 50]
contribution = 100
shares = [contribution / price for price in prices]
total_shares = sum(shares)
invested = contribution * len(prices)
average_cost = invested / total_shares
print(round(total_shares, 4))
print(round(average_cost, 2))
# 13.0
# 38.46The simple average of the five prices is $41. The average cost per share is about $38.46 because the same $100 contribution bought more shares at the lower prices. This result depends on equal dollar contributions, not equal numbers of shares.
Exercise
Exercise
A broker supports six decimal places. How many shares can a $75 order buy at a price of $128.40 if the broker rounds down?
Show answer
Calculate 75 ÷ 128.40 = 0.584112149...; rounded down to six decimal places, the order buys 0.584112 shares.