Skip to content
Wildflower
Join free
Backtesting in Python (optional)

Free Trading School · Level 7 · Course 7.5

Costs, tick values and contract size

Lesson 9 of 15 in Backtesting in Python (optional)Module 2: Building a test

Advanced · Backtesting in Python

Costs, tick values and contract size

Wildflower Trading School · Lesson 7.5.2.4

Wildflower

So far our test measures trades in points and R. A real futures trade moves in ticks, is worth dollars per contract, and pays costs on every trade. By the end of this lesson, you'll have put all three into the code, and you'll see how costs change each result.

1 of 10

What you'll learn

  • Round to real prices. Stops and targets go on tradable prices, rounded the same way.
  • Name your settings once. Point value, contracts, fees and slippage go in capitals.
  • Turn points into dollars. Multiply points by the point value and the number of contracts.
  • Take off costs. Fees and slippage come off every trade. Net is what you keep.
  • Test another contract. Change the settings and check its specs with the exchange.

Exercise

  1. Add the tick rounding and the cost settings to your own test, using your broker's real fees.
  2. Work one trade out by hand, gross to net, and check the code gives the same answer.

Next: Avoiding look-ahead bugs.

Quick check

  1. 1. On MES, what is one tick worth per contract?

  2. 2. Why put the point value and fees in settings at the top?

  3. 3. Costs are a fixed $8 a trade. Which trades do they hurt most, in R?

0 of 3 answered.

Finished this lesson?

Tick it off and keep your place

Make a free account and we'll remember where you are, so “Avoiding look-ahead bugs” is waiting next time.

Read the full notes

To match a futures contract, the code rounds and onto real , turns points into dollars with the and contract count, and takes fees and off every trade to give the net result.

  • On the , a is 0.25 of a point and each is worth $5 per contract, so a is worth $1.25 (Ticks and tick values).
  • Ticks: after import math, math.floor(price / TICK) * TICK rounds down to a tick; math.ceil rounds up. Round the stop and target onto real prices, one way, written down.
  • Settings in capitals: POINT_VALUE = 5.0, CONTRACTS = 2, FEES = 1.50 (made up, per contract in and out), SLIP_TICKS = 1 (made up, each way). Use your broker's real .
  • Dollars: = points × POINT_VALUE × CONTRACTS; costs = (slippage in dollars + FEES) × CONTRACTS; net = gross − costs. Only is what you keep (Gross and net results). Net R = net ÷ risk in dollars.
  • Another contract: change the settings, not the code. The is $50 a point. Check each contract's specs with the exchange. More: Slippage and commissions in a backtest.

Worked example

Made-up numbers

One trade, gross to net

Made-up numbers · long 2 MES · in 5,010.25 · out 5,022.75 · fees $1.50 per contract · 1 tick slippage each way

  1. 12.50 points × $5 × 2 = $125.00 gross
  2. Fees: $1.50 × 2 = $3.00
  3. Slippage: 2 ticks × $1.25 × 2 = $5.00
  4. $125.00 − $3.00 − $5.00 = $117.00 net

The code should give the same number for the same trade.

Your turn

Drill

Made-up numbers · long 3 MES · up 8 points · fees $1.50 per contract · 1 tick slippage each way

Trading is risky. You can lose money. Test results are hypothetical, and a test can't tell you what will happen next. This lesson explains how testing works. It isn't advice.