liveBook · Manning

Baseline

As explained in Investing for Programmers

A benchmark is a reference measure used to compare the performance or return of an investment.

A baseline is a reference result used to judge whether an investment strategy adds value. In backtesting, it commonly compares a strategy’s gain with buying a fixed number of shares at the start and selling them at the end, while accounting for transaction costs. section 11.3.1

A useful baseline establishes:

  • A fixed investment amount, which determines how many shares can be purchased at the starting price. section 11.3.1
  • A comparable buy-and-hold return, calculated from the starting and ending share prices. section 11.3.1
  • Trading costs deducted from strategy gains before deciding whether the strategy succeeds. section 11.3.1

Comparing an SMA strategy with holding shares

With $1,000, calculate the shares affordable on the first trading day. Compare an SMA crossover strategy’s final gain against the gain from buying those shares initially and selling them on the final day. Subtract transaction costs from the strategy result; only an excess over the baseline supports calling the strategy successful. NVIDIA provides a convenient starting case, but its strong historical performance can make the comparison unusually favorable. section 11.3.1

Listing 11.2 Executing a single backtest
def run_single_backtest(ticker: str, cash, start_date: str, end_date: str, 
transaction_costs = 1) -> pd.DataFrame:
    df = load_data(ticker, start_date, end_date)
    shares = round(cash / df["Close"][0])
    print(f"Shares: {shares}. start price: {df["Close"][0]}. end price: "
          f"{df["Close"].iloc[-1]}. to beat: {df["Close"].iloc[-1]*shares – 
                                                 df["Close"][0]*shares – 
                                                 transaction_costs}")
    df = add_sma(df, 10, 20)
    res = backtest(df, 10, 20, shares, True)
    gain = res['cash_movement'].sum()
    gain = gain - transaction_costs * len(res['cash_movement'])
    print(f"Gains: {gain})")
    return df
results_nvda
 = run_single_backtest("NVDA", 1000, "2015-01-01", "2025-01-01")

Run a single backtest that calculates shares, reports the return needed to beat the baseline, and subtracts transaction costs from strategy gains. section 11.3.1

How Investing for Programmers covers it

How deep it goes
Defines a reference return, share calculation, and cost adjustment, but does not develop statistical benchmark design.
Examples
Uses fixed-$1,000 investments, NVIDIA share prices, SMA crossovers, and comparisons across companies.
What it assumes
Assumes basic stock-price and return concepts while introducing unrealized gains, dividends, and benchmark yields separately.
What you can do after
Evaluate a trading strategy against a cost-adjusted buy-and-hold return.
How it connects
Connects backtesting with moving averages, transaction costs, and investment returns.

Also explained in

Compare how 16 books explain baseline →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Investing for Programmers. The section links point to the parts of the book it draws on.