Skip to content
All library documents

Using Bid and Ask Data in VectorBT Backtests

Article Quant Q&A · Author: arkon

Summary

The document asks how to replace close prices with bid and ask prices in a VectorBT signal backtest. Using separate bid and ask observations can represent trade-side prices more realistically than a single close, but the answer says that a convenient built-in route is not apparent. It points to historical order-book data as a possible source for users with access to the VectorBT Pro data connection described in the discussion.

The practical approach may require obtaining the relevant Nasdaq data and writing custom Python extensions to expose it in a usable structure. The answer notes two constraints: documentation for this workflow is lacking, and the data may be costly. It does not provide implementation steps, evaluate alternative data vendors, or explain how to model execution against the spread, so the specific backtest setup remains unresolved.

Key ideas

  • Close prices do not supply the separate bid and ask observations needed to model trade-side pricing.
  • Historical order-book data is suggested as a possible source for bid and ask prices.
  • Accessing such data through the described platform may require custom integration work.
  • Data availability, limited documentation, and potentially high cost can make this approach difficult.

Tags

Full text
# Using bid and ask prices with VectorBT library


# Using bid and ask prices with VectorBT library












I am creating a backtest using vectorbt library. This is my function for all the portfolio metrics:

```
pf = vbt.Portfolio.from_signals(
    signal_data['close'],
    entries,
    exits,
    init_cash=10_000_000,
    freq='D'
)
```

Now, instead of using the close price I want to switch to bid and ask prices for my trades.

Is there a convenient way to do this?

## Answer by Adam Cataldo (score 0)

https://quant.stackexchange.com/a/76242

There doesn't seem to be a convenient way to get this data, but it should be theoretically possible if you're using vectorbtpro (https://vectorbt.pro/), which allows you to pull data form Nasdaq Data Link (https://data.nasdaq.com/). It looks like Nasdaq provides historic order book data through Nasdaq Data-on-Demand (https://www.nasdaq.com/solutions/nasdaq-data-on-demand).

I doubt this is convenient, since there's no documentation on vectorbtpro's site about how to do this. Expect to need to write your own Python extensions to expose the relevant bid/ask data in a convenient data structure. Also, depending on your budget, paying for the relevant data from Nasdaq may be cost prohibitive. (They don't list the price on their site if you don't already have an account, and I'm inclined to think the price is quite high: https://data.nasdaq.com/databases/NDOD/pricing/plans)

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.