Learn high-performance backtesting with VectorBT. Build, test, and optimize trading strategies for NSE stocks, NIFTY indices, and F&O segments with blazing-fast vectorized computations.
# Quick VectorBT Example - RELIANCE
import vectorbt as vbt
import yfinance as yf
# Download Indian stock data
data = vbt.YFData.download(
"RELIANCE.NS",
start="2023-01-01",
end="2024-01-01"
)
# Create RSI strategy
rsi = vbt.RSI.run(data.get('Close'))
entries = rsi.rsi_crossed_below(30)
exits = rsi.rsi_crossed_above(70)
# Backtest with Indian market parameters
portfolio = vbt.Portfolio.from_signals(
data.get('Close'),
entries, exits,
init_cash=1_00_000, # ₹1 Lakh
fees=0.0003, # NSE charges
slippage=0.0005
)
# Display results
print(f"Total Return: {portfolio.total_return():.2%}")
print(f"Sharpe Ratio: {portfolio.sharpe_ratio():.2f}")
Powerful features tailored for NSE, BSE, and MCX trading
Test thousands of strategies on NIFTY 50 stocks in seconds using NumPy vectorization and Numba JIT compilation.
Built-in support for NSE holidays, market hours, STT, brokerage, and other Indian market-specific parameters.
Comprehensive metrics including Sharpe ratio, maximum drawdown, and custom Indian market indicators.
From basics to advanced strategies for Indian markets
Installation, setup, and your first backtest with NIFTY 50 stocks
Technical indicators popular in Indian markets
Multi-asset strategies with NIFTY 50 stocks
F&O strategies for NIFTY and BANK NIFTY
Parameter optimization and walk-forward analysis
Deploy strategies with Indian brokers
# Install VectorBT with all dependencies
pip install vectorbt[full]
# Install Indian market data libraries
pip install yfinance nsepy
import vectorbt as vbt
import pandas as pd
import numpy as np
from datetime import datetime, timedelta
# Download HDFC Bank data
data = vbt.YFData.download(
"HDFCBANK.NS",
start="2023-01-01",
end="2024-01-01"
)
# Simple Moving Average Strategy
fast_ma = vbt.MA.run(data.get('Close'), 10)
slow_ma = vbt.MA.run(data.get('Close'), 50)
# Generate signals
entries = fast_ma.ma_crossed_above(slow_ma)
exits = fast_ma.ma_crossed_below(slow_ma)
# Run backtest
portfolio = vbt.Portfolio.from_signals(
data.get('Close'),
entries, exits,
init_cash=5_00_000, # ₹5 Lakhs
fees=0.0003 # NSE charges
)
# View results
print(portfolio.stats())
Top performing stocks rotation
Popular trend following system
HDFC Bank vs ICICI Bank
Bank NIFTY options selling
Built-in Indicators
Faster than Loops
NSE Stocks Supported
Community Support
Total Return
+127.45%
Sharpe Ratio
2.34
Max Drawdown
-18.76%
Win Rate
68.2%
Profit Factor
2.89
Total Trades
147