$npx -y skills add marketcalls/vectorbt-backtesting-skills --skill setupSet up the Python backtesting environment. Detects OS, creates virtual environment, installs dependencies (openalgo, ta-lib, vectorbt, plotly), and creates the backtesting folder structure.
| 1 | Set up the complete Python backtesting environment for VectorBT + OpenAlgo. |
| 2 | |
| 3 | ## Arguments |
| 4 | |
| 5 | - `$0` = Python version (optional, default: `python3`). Examples: `python3.12`, `python3.13` |
| 6 | |
| 7 | ## Steps |
| 8 | |
| 9 | ### Step 1: Detect Operating System |
| 10 | |
| 11 | Run the following to detect the OS: |
| 12 | |
| 13 | ```bash |
| 14 | uname -s 2>/dev/null || echo "Windows" |
| 15 | ``` |
| 16 | |
| 17 | Map the result: |
| 18 | - `Darwin` = macOS |
| 19 | - `Linux` = Linux |
| 20 | - `MINGW*` or `CYGWIN*` or `Windows` = Windows |
| 21 | |
| 22 | Print the detected OS to the user. |
| 23 | |
| 24 | ### Step 2: Create Virtual Environment |
| 25 | |
| 26 | Create a Python virtual environment in the current working directory: |
| 27 | |
| 28 | **macOS / Linux:** |
| 29 | ```bash |
| 30 | python3 -m venv venv |
| 31 | source venv/bin/activate |
| 32 | pip install --upgrade pip |
| 33 | ``` |
| 34 | |
| 35 | **Windows:** |
| 36 | ```bash |
| 37 | python -m venv venv |
| 38 | venv\Scripts\activate |
| 39 | pip install --upgrade pip |
| 40 | ``` |
| 41 | |
| 42 | If the user specified a Python version argument, use that instead of `python3`: |
| 43 | ```bash |
| 44 | $PYTHON_VERSION -m venv venv |
| 45 | ``` |
| 46 | |
| 47 | ### Step 3: TA-Lib System Dependency (Optional) |
| 48 | |
| 49 | **OpenAlgo ta (`from openalgo import ta`) is the default indicator library for this project - it ships 100+ indicators and needs no separate system dependency.** TA-Lib is only needed if the user wants to be able to say "use talib" for a specific backtest. |
| 50 | |
| 51 | Ask the user with AskUserQuestion: |
| 52 | - "Do you also want TA-Lib installed for when you explicitly request it in a backtest? (Optional - OpenAlgo ta already covers the same indicators plus 90+ more)" |
| 53 | - Yes, install TA-Lib too |
| 54 | - No, skip it (recommended - install it later if ever needed) |
| 55 | |
| 56 | If the user skips it, skip this entire step and omit `ta-lib` from the Step 4 pip install. If the user wants it, TA-Lib requires a C library installed at the OS level BEFORE `pip install ta-lib`. |
| 57 | |
| 58 | **macOS:** |
| 59 | ```bash |
| 60 | brew install ta-lib |
| 61 | ``` |
| 62 | |
| 63 | **Linux (Debian/Ubuntu):** |
| 64 | ```bash |
| 65 | sudo apt-get update |
| 66 | sudo apt-get install -y build-essential wget |
| 67 | wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz |
| 68 | tar -xzf ta-lib-0.4.0-src.tar.gz |
| 69 | cd ta-lib/ |
| 70 | ./configure --prefix=/usr |
| 71 | make |
| 72 | sudo make install |
| 73 | cd .. |
| 74 | rm -rf ta-lib ta-lib-0.4.0-src.tar.gz |
| 75 | ``` |
| 76 | |
| 77 | **Linux (RHEL/CentOS/Fedora):** |
| 78 | ```bash |
| 79 | sudo yum groupinstall -y "Development Tools" |
| 80 | wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz |
| 81 | tar -xzf ta-lib-0.4.0-src.tar.gz |
| 82 | cd ta-lib/ |
| 83 | ./configure --prefix=/usr |
| 84 | make |
| 85 | sudo make install |
| 86 | cd .. |
| 87 | rm -rf ta-lib ta-lib-0.4.0-src.tar.gz |
| 88 | ``` |
| 89 | |
| 90 | **Windows:** |
| 91 | ``` |
| 92 | pip install ta-lib |
| 93 | ``` |
| 94 | If that fails, download the appropriate .whl file from https://github.com/cgohlke/talib-build/releases and install with: |
| 95 | ```bash |
| 96 | pip install TA_Lib-0.4.32-cp312-cp312-win_amd64.whl |
| 97 | ``` |
| 98 | |
| 99 | ### Step 4: Install Python Packages |
| 100 | |
| 101 | Install all required packages (latest versions). `openstatz` replaces QuantStats for tearsheets - always install it, never `quantstats`: |
| 102 | |
| 103 | ```bash |
| 104 | pip install openalgo vectorbt plotly anywidget nbformat pandas numpy yfinance python-dotenv tqdm scipy numba nbformat ipywidgets openstatz ccxt duckdb psutil |
| 105 | ``` |
| 106 | |
| 107 | If the user opted into TA-Lib in Step 3, append `ta-lib` to this install command (after the C library is installed). |
| 108 | |
| 109 | ### Step 5: Create Backtesting Folder |
| 110 | |
| 111 | Create only the top-level backtesting directory. Strategy subfolders are created on-demand when a backtest script is generated (by the `/backtest` skill). |
| 112 | |
| 113 | ```bash |
| 114 | mkdir -p backtesting |
| 115 | ``` |
| 116 | |
| 117 | Do NOT pre-create strategy subfolders. |
| 118 | |
| 119 | ### Step 6: Configure .env File |
| 120 | |
| 121 | **6a. Check if `.env.sample` exists at the project root.** If it does, use it as a template. |
| 122 | |
| 123 | **6b. Ask the user which markets they will be backtesting** using AskUserQuestion: |
| 124 | - Indian Markets (OpenAlgo) — requires OpenAlgo API key |
| 125 | - Indian Markets (DuckDB) — direct database loading, no API needed |
| 126 | - US Markets (yfinance) — no API key needed |
| 127 | - Crypto Markets (CCXT) — optional API key for private data |
| 128 | |
| 129 | **6c. If the user selected Indian Markets**, ask for their OpenAlgo API key: |
| 130 | - Ask: "Enter your OpenAlgo API key (from the OpenAlgo dashboard):" |
| 131 | - If the user provides a key, store it in `.env` |
| 132 | - If the user skips, write a placeholder |
| 133 | |
| 134 | **6d. If the user selected Indian Markets (DuckDB)**, ask for the DuckDB database path: |
| 135 | - Ask: "Enter the path to your DuckDB database file (e.g., D:/data/market_data.duckdb):" |
| 136 | - Auto-detect format: If the database has a `market_data` table with `symbol, exchange, interval, timestamp` columns, it is OpenAlgo Historify format (store as `HISTORIFY_DB_PATH`). Otherwise store as `DUCKDB_PATH`. |
| 137 | - If the user also has OpenAlgo Historify, ask: "Is this an OpenAlgo Historify database? (y/n)" |
| 138 | |
| 139 | **6e. If the user selected Crypto Markets**, ask if they want to configure exchange API keys: |
| 140 | - Ask: "Do you have exchange API keys for authenticated data? (Optional — public OHLCV data works without keys)" |
| 141 | - If yes, ask for |