Python Dev
Python Dev
Backtesting Task
Objective:
This task will focus on handling large historical datasets with multiple option expiries across various derivatives
(e.g., Nifty, BankNifty, FinNifty, BankEx). You are expected to develop a robust strategy to efficiently manage this
data, implement strategies or signal generation (including buy/sell signals with stop-loss), and run a backtest
using an open-source backtesting framework.
Task Outline:
The first part of the task is to design a plan for managing large historical datasets that contain multiple
option expiries for different derivatives such as Nifty, BankNifty, FinNifty, and BankEx. You need to consider the
following challenges:
Sample Data: The script should fetch data either from the provided Telegram channel
https://2ly.link/1ztTU make sure you are able to extract .feather files and nested zip files or use an
alternative open-source source like ICICI Breeze API for historical options/futures data.
Large Data Volume: Data can span several years with multiple expiries, and each expiry may have
different strike prices for options.
Efficient Data Handling: You need to design a solution that efficiently loads and processes data to
avoid performance bottlenecks.
Option Expiry Management: For options trading strategies, the data must be filtered based on the
expiry date and associated with the correct derivative.
Multiple Derivatives: Handle data for different indices and contracts simultaneously.
Your task:
Come up with a strategy to handle this data efficiently (using techniques like data partitioning, chunk
loading, and expiry-based filtering).
Describe how you would store and retrieve this data (e.g., using relational databases, data lakes,
Parquet/Feather formats, or cloud storage).
Explain how you will process the data dynamically based on different expiries and strategies (e.g.,
selecting the correct expiry contracts for BankNifty, Nifty, etc.).
Things to consider:
How will you structure the data for different indices and derivatives?
How will you handle rolling options contracts or futures?
How will you ensure that the system is efficient when dealing with large volumes of data?
Derivative Type: Which derivative data to work with (e.g., Nifty, BankNifty, FinNifty, BankEx).
Timeframes: Choose multiple timeframes for the backtest (e.g., 1 minute, 5 minutes, 1 hour, 1 day).
Expiry Date: If the segment is options or futures, prompt the user to specify the expiry date (for filtering
relevant contracts).
Strategy: Ask the user to choose or define a trading strategy (e.g., Moving Average Crossover, RSI,
Bollinger Bands, custom strategies based on signal generation).
Implement a trading strategy based on the user’s input. The strategy should:
Generate buy/sell signals based on predefined rules (e.g., moving averages, RSI, etc.).
Include logic for stop-loss orders to minimize risk.
Ensure the strategy can dynamically handle the data for the selected timeframe and derivative.
Example Strategies:
Buy when the short-term moving average crosses above the long-term moving average.
Sell when the short-term moving average crosses below the long-term moving average.
Implement stop-loss logic to minimize losses.
The strategy should work for multiple expiries and multiple derivatives, and the signal generation should
take into account different expiry dates for options contracts.
After implementing the strategy, backtest it on the resampled data for different timeframes (1 minute, 5
minutes, 1 hour, daily).
The script should generate results for each timeframe, such as:
Number of trades.
Total profit/loss.
Win rate (percentage of profitable trades).
Risk-adjusted metrics (Sharpe ratio, maximum drawdown).
The results should vary based on the timeframe and derivative.
Sample Workflow
Design your approach to handle large datasets for different derivatives with multiple expiries, including
options and futures. Here's an example structure:
Data Storage: Use a combination of Parquet or Feather formats to store historical data
efficiently, partitioned by expiry and derivative (e.g., Nifty, BankNifty).
Data Loading: Use a chunk-based approach where only the relevant data for a specific derivative
and expiry is loaded into memory.
Filtering: Filter the data dynamically based on the expiry date chosen by the user to ensure that
only relevant options contracts or futures data are loaded for backtesting.
Implement a Moving Average Crossover or RSI strategy with stop-loss logic, tailored to the chosen
derivative and expiry
Backtest the strategy across multiple timeframes and generate output for each
Evaluation Criteria:
1. Data Management:
Efficient handling of large historical datasets with multiple expiries and different derivatives.
A clear strategy for partitioning and filtering data based on expiries and derivatives (e.g., Nifty,
BankNifty).
Ability to take multiple user inputs (timeframes, expiry dates, strategies) and dynamically adjust the
backtesting accordingly.
3. Strategy Implementation:
Accurate implementation of a trading strategy that generates buy/sell signals and integrates stop-
loss logic.
Ability to handle different derivatives and expiries in the strategy.
4. Backtest Results:
The output should include metrics like total profit/loss, number of trades, win rate, and risk-
adjusted performance metrics (e.g., Sharpe ratio).
Results should differ based on the chosen timeframe and derivative.
5. Code Quality:
Clean and well-documented code with a focus on modularity, efficiency, and readability.