How to backtest a trading strategy on your own data: uploading a CSV

Upload price bars, signals or sentiment as a CSV, let the platform check it, and load it into a Python backtest or notebook with one line. Format, limits and pitfalls.

  • Data
  • Backtesting
  • Python
How to backtest on your own data: cover with a pixel data table

The built-in datasets cover fundamentals, positioning, rates and prices. But many strategies run on something of your own: a signal you compute elsewhere, sentiment scores, an alternative data feed you bought, prices from a venue the catalog doesn't have. On MarketsCoder you can upload it as a CSV and use it in backtests and notebooks like any other dataset.

Uploading your own data: a CSV is uploaded, checked for times and columns, turned into a clean sorted copy, and loaded with add_data(UserData, name) in backtests and notebooks
The file is checked and cleaned once, on upload. Backtests then read the clean copy.

Two kinds of dataset

  • Price bars: open, high, low and close (volume optional), for an instrument you want to trade or chart.
  • Custom: any columns, numbers or text, such as a signal, a score or an indicator from another tool.

Preparing the file

A header row, then one row per time:

time,score,mentions
2024-01-02 14:30:00,0.42,1830
2024-01-02 14:31:00,0.47,1912
2024-01-02 14:32:00,0.31,2104
  • The time column is the one named time, timestamp, date or similar, else the first column.
  • Times may be YYYY-MM-DD HH:MM:SS (taken as UTC), ISO 8601 with an offset, or Unix seconds or milliseconds.
  • Price bars need open, high, low and close (common short names like o, h, l, c work too).
  • Up to 500 MB, 5 million rows and 50 columns a file. Commas, semicolons and tabs are all fine.

Uploading

  1. Open Datasets in the app and choose Upload your own.
  2. Pick the file, give the dataset a short name such as my-signals, and say whether it's price bars or custom.
  3. Wait for the check. It finds the time column, sorts the rows, keeps the last of any duplicate times, and stops at the first problem with the line and what to fix.
  4. Copy the code it shows you.

Using it in a backtest

One line in initialize subscribes to it, and its rows arrive in on_data at their times:

from AlgorithmImports import *
from lean_platform_data import UserData


class SentimentAlgorithm(QCAlgorithm):
    def initialize(self):
        self.set_start_date(2024, 1, 1)
        self.set_end_date(2024, 6, 30)
        self.spy = self.add_equity("SPY", Resolution.MINUTE).symbol
        self.signals = self.add_data(UserData, "my-signals", Resolution.MINUTE, TimeZones.UTC).symbol

    def on_data(self, slice):
        if self.signals in slice:
            row = slice[self.signals]
            if row["score"] > 0.4:
                self.set_holdings(self.spy, 1)
            elif row["score"] < 0:
                self.liquidate(self.spy)

Custom columns are read by name, as in row["score"]; price bars have row.open to row.close. The same line works in a research notebook, and the AI assistant knows your datasets and can write the code for you.

Privacy and cost

Your datasets are private to your account. A backtest only receives the datasets its code names, and only yours. The first 1 GB of storage is free; beyond it, storage is $0.10 per GB a month, charged daily. You can rename, replace or delete a dataset at any time.

Large files and long histories can need more memory than the standard machine has. If a backtest on a big dataset fails, pick a bigger machine.

Frequently asked questions

Can I backtest on my own data?

Yes. Upload a CSV on the My datasets page; it's checked and converted, then one add_data line loads it into a backtest or a notebook.

What format does the CSV need?

A header row, then one row per time. The time column is the one named time, timestamp, date or similar, else the first column, in YYYY-MM-DD HH:MM:SS (UTC), ISO 8601 with an offset, or Unix seconds or milliseconds. Price bars also need open, high, low and close columns.

How big can an uploaded dataset be?

Up to 500 MB a file, 5 million rows and 50 columns. The first 1 GB of storage is free; beyond it, storage is $0.10 per GB a month.

Share on XLinkedIn

Test your own idea on point-in-time data.

Write a strategy in Python or describe it to the AI assistant, and see a full backtest report in minutes.

Get started