Getting started
Installation
Install backtide's newest release easily via pip:
pip install -U backtide
or via conda:
conda install -c conda-forge backtide
Latest source
Sometimes, new features and bug fixes are already implemented in the
development branch, but waiting for the next release to be made
available. If you can't wait for that, it's possible to install the
package directly from git.
pip install git+https://github.com/tvdboom/backtide.git@development#egg=backtide
Don't forget to include #egg=backtide to explicitly name the project,
this way pip can track metadata for it without having to have run the
setup.py script.
Optional dependencies
Some specific functionalities or configuration options require the installation of additional libraries. Install all optional dependencies with:
pip install -U backtide[full]
Contributing
If you are planning to contribute to the project, you'll need the development dependencies. Install them with:
pip install -U backtide[dev]
Click here for a complete list of package files for all versions published on PyPI.
Usage
There are three ways to use backtide:
Via the application
Backtide ships with an interactive Streamlit application. Launch it from the terminal with:
backtide launch
The app provides a graphical interface for configuring experiments, visualizing results and managing stored data. Read more in the user guide.
Via the CLI
The backtide command-line interface lets you download data, run backtests and
manage storage directly from the terminal.
backtide download AAPL MSFT --interval 1d
backtide run experiment.toml
Run backtide --help to see all available commands.
Via Python
Import backtide in any Python script or notebook for full programmatic control.
>>> from backtide.backtest import run_experiment
>>> from backtide.data import resolve_profiles, download_bars
>>> from backtide.storage import query_bars
>>> from backtide.strategies import MultiBollingerRotation
>>> profiles = resolve_profiles(["AAPL", "MSFT"], "stocks", ["1h", "1d"])
>>> result = download_bars(profiles)
>>> data = query_bars("AAPL")
>>> print(data.head())
symbol interval provider ... adj_close volume n_trades
0 AAPL 1d yahoo ... 0.098207 469033600.0 None
1 AAPL 1d yahoo ... 0.093083 175884800.0 None
2 AAPL 1d yahoo ... 0.086251 105728000.0 None
3 AAPL 1d yahoo ... 0.088386 86441600.0 None
4 AAPL 1d yahoo ... 0.090949 73449600.0 None
[5 rows x 13 columns]
>>> results = run_experiment(
... name="test experiment",
... symbols=["AAPL", "MSFT"],
... interval="1d",
... strategies=[MultiBollingerRotation()],
... )
>>> print(results)
ExperimentResult(id="d94eed792875472b", name="test experiment", status="Success", n_strategies=1)