Trading costs on the stock market in practice

The original article appeared on AlgoHubb.com.

Understanding trading costs on the stock market can make or break your algorithmic trading business. Choosing a broker and managing transaction costs can be a real horror. I know this because I have used around 20 brokers in my career and I do not recommend the vast majority of them. At the same time, trading costs on the stock market are crucial for running a profitable algorithmic trading operation.

Fortunately, by choosing wisely, we have never had as easily accessible and cheap regulated brokerage services in the history of retail investors.

Trading costs on the stock market — broker comparison overview

I want to clarify right away that I have no ties with the brokers mentioned in this article. My writing is purely based on personal experience and research for my own purposes.

This article comprehensively discusses the issue of trading costs on the stock market, including deep-spread research, from a practical perspective.

What Makes an Ideal Broker for Low Trading Costs?

My expectations for the ideal broker operating in the stock market are:

  • Must be regulated by FINRA
  • My funds should be insured by SIPC ($500k+ insurance)
  • Should offer true 0% commission for users outside the US as well
  • Uses true market spreads (no markups)
  • Has low margin (borrowing money) costs
  • Offers all products (stocks, ETFs) from the US
  • Provides a free paper/demo account that accurately reflects real trading
  • Has a well-functioning API and lightning-fast order execution in conjunction with my platform (I use AlgoCloud)
  • Offers a user-friendly broker portal and integration with TradingView
  • Has a good manual, forum, and helpdesk

In 2022, I thought that unfortunately such an ideal does not exist, working without satisfaction with many brokers, until I tried Alpaca and — eureka! It turns out that you can meet all the above requirements at once. Since then, I have been convinced that it was one of the best fundamental choices in my business.

Because I like diversification, I also have several trading accounts with other brokers, including the largest one in IBKR, but Alpaca is my #1.

Hidden Trading Costs: Broker Manipulations

Many new traders, particularly those outside the USA, often overlook the significance of trading costs on the stock market. They may also not recognize the manipulations by brokers who claim to offer “real 0% commission.” Hidden costs often take the form of a high spread containing a so-called markup (a surcharge on the natural market spread) and/or price slippage when executing orders, causing a position to be “slightly” in loss after opening or closing at a worse price than it should.

How to Defend Against High Trading Costs on the Stock Market

  • Choose a broker that meets the criteria mentioned above.
  • Work on timeframes that make the issue of costs, including the natural market spread, insignificant in relation to price movements and profits you achieve. I highly recommend the D1 timeframe.
  • Avoid order types and entry points in the market that make your costs unpredictable.

Why Trading Costs Are Critical for Algorithmic Traders

Trading costs on the stock market are of huge importance mainly due to the large number of transactions executed. Currently, I am executing around 10-50 trades per day on my accounts, so for example, with a commission of around $5 per trade (example costs for Tradestation users outside the USA), the monthly amounts can be quite high, and for smaller accounts, such a cost could blow up even the best strategies. Fortunately, Alpaca has real $0 commissions, as well as negligible exchange fees like REG/TAF.

What Is the Real Spread on Stocks and How to Avoid Paying It?

I had the opportunity to work for almost a year in a trading room, trading in day trading mode on stocks. During that time, I experienced how high market spreads can be on some stocks, especially in the first few minutes after the market opens. That’s why I am sensitive to avoiding this unnecessary cost.

In 2023, I conducted a detailed analysis of spreads using the Sierra Chart platform and NASDAQ TotalView US stock data (Level2 data) as a data source.

I completed a study that compared Alpaca spreads with Nasdaq stock market data. In every case I checked, the prices fully matched, showing that Alpaca does not manipulate spreads.

The second study focused on the pure market spread for stocks belonging to the S&P 500. I analyzed bid/ask prices of multiple tickers every minute over a 30-day period in January–February 2023.

Here is an example table with recorded data:

Trading costs stock market — spread analysis data table

The chart below shows the average spread for each minute over the 30-day period. Here is an example spread for the IDXX ticker:

IDXX stock spread analysis — average spread per minute throughout trading day

The spread behavior over time for most stocks looks very similar. At the beginning of the market (first 15 minutes), the spread is very high, then it decreases, only to increase significantly in the last 1–2 minutes of trading.

The size of the spread will of course vary between different stocks — it will be completely different for AAPL (low relative spread) vs. BKNG (high relative spread), but the proportions of behavior over time are very similar.

Moving on to the details, the first 1.5 hours after the market opens for IDXX:

Trading costs — IDXX spread in first 1.5 hours after market open

Meanwhile, the last hour looked something like this:

Trading costs — IDXX spread in last hour before market close

I would like it to remain in your awareness that entering a position with a market order at the beginning of the market will regularly result in catching a spread of even a few percent! Something like this cannot be predicted and assumed in backtests.

Practical Solutions to Minimize Trading Costs on the Stock Market

Solutions to the spread problem are very simple and effective. I use them in all of my strategies. These solutions apply to trading on a daily interval using AlgoCloud.

  1. LIMIT order at market open: If you want to open a position at the beginning of the market, use a LIMIT order (preferably below the Open price), which ensures you do not pay the spread. Equally important, your backtest will be reliable in terms of entry prices.
  2. MARKET order at close only: If you want to open with a MARKET order, do it only at the end of the market! AlgoCloud opens such positions about 5 minutes before the end of the session, during the period of the lowest spread throughout the day.
  3. Careful with STOP orders: If you trade Breakout using a STOP order, place your order away from the OPEN price to avoid getting caught in an unpredictable spread. This type of order is more suitable for ETFs or highly liquid stocks with low spreads.
  4. Exit with Market on Bar Close: When exiting positions based on rules, I only use a Market order ON BAR CLOSE. You can use SL or TP, but you’ll be exposed to price gaps and sometimes high spreads at market open.

Volume vs. Spread: Does High Volume Guarantee Low Trading Costs?

The idea for potential defense against a high spread should be a filter that selects only stocks with high volume. These frequently traded stocks should have a guaranteed low spread, right? From my many observations, it’s not so straightforward. I have often observed stocks with very high volumes and at the same time unnaturally high spreads. It’s probably more of a mix of volume and volatility rather than just volume itself. A volume filter certainly won’t hurt, but it may not be enough.

What Transaction Costs Should I Assume in Backtests?

If we close a position with a MARKET order 5 minutes before the market closes, and we conduct a backtest over 30 years on the Close price from daily bars, how does the last 5 minutes affect result consistency?

I dedicated a completely separate study to answer it, and the results were very surprising. My study was based on 1,074 transactions closed ON BAR CLOSE, on a real account using Alpaca broker and AlgoCloud platform, in the period 11.2023–07.2024.

I compared the real closing price recorded in AlgoCloud with the official exchange closing price of the respective ticker on that day.

Trading costs stock market — real vs backtest price comparison spreadsheet

The results are much better than expected. The average spread/slippage of the last 5 minutes was only -0.005%! This cost was an order of magnitude lower than I had previously assumed. For more detail, see our follow-up study on transaction costs in historical tests.

Safe Cost Assumptions for Backtesting

Below are the trading costs I assume in backtests, which are 10 times higher than the average achieved in the study above. Due to this accepted margin, I consider such settings to be safe.

Standard backtest setting with ENTRY – Limit (On Bar Open) / EXIT – Market (On Bar Close):

Trading costs stock market — safe backtest cost settings for Limit entry

And for ENTRY – Market (On Bar Close) / EXIT – Market (On Bar Close):

Trading costs stock market — safe backtest cost settings for Market entry

REG/TAF Fees in Practice

There is another category of fees for regulators such as the SEC and FINRA. Fortunately, their impact should be minimal. More on this topic: Alpaca REG/TAF fee guide.

In practice, the REG/TAF costs are completely marginal for me — around $0.06 per trade. I even skip them in backtest settings.

Margin and Short Selling Costs

If you are using Margin, factor in the cost of this credit from the broker in your backtests. At the time of writing, the cost of borrowing capital from Alpaca is 8.5% annually (for comparison, IBKR charges 6.83% during the same period). See Alpaca margin documentation for calculation details.

Short selling on stocks and the associated trading costs deserve another article. I believe that shorting stocks is not necessary to achieve success — it is associated with a number of challenges, limitations, and costs, so short strategies on stocks are more suitable for advanced users.

Summary: Managing Trading Costs on the Stock Market

In summary, choosing the right broker and understanding trading costs on the stock market are key elements to success in algorithmic trading. I hope my experiences will be helpful. Remember, even the best strategy can be undermined by high fees, so I’m rooting for your good choices in this matter!

Bonus Tip: How to Make Money with Free Capital Every Night

If at the end of the day you have some free capital and 3 minutes to manually execute a buy or sell operation, you can buy BIL overnight. BIL is an ETF that practically accrues interest on treasury bonds daily (at the time of writing, it was 5.3% annually). The next day, the purchase of new shares will be financed from the broker’s free margin, and by the end of the day, you can sell BIL to balance the lack of cash.

This requires a few minutes once a day. Profits generated from such a “deposit” can successfully cover the costs of margin and other fees for platforms like AlgoCloud.

BIL chart (taking into account dividends paid out once a month):

BIL ETF chart with dividends — overnight capital strategy

Don’t be surprised that on the first day of each new month, the price of BIL drops by the amount of interest paid to you a few days later as a dividend. Therefore, the chart of BIL without considering dividends:

BIL ETF chart without dividends — price movement pattern

Leverage this simple yet effective strategy to enhance your investment portfolio and make the most of your free capital every night.

Related Articles