Skip to main content

traderbacktesteroptalpha

This Python script provides three main functionalities:

  1. Updating essential files from a server (update_files function).
  2. Utility functions for backtesting and trading strategies (TraderBackTesterUtils class).
  3. Data manipulation functions for backtesting and trading strategies (TraderBackTesterDM class).

Requirements

This script requires the following libraries:

  • swifter==1.3.4
  • openpyxl==3.1.2
  • ta==0.10.2
  • pandas==1.5.3
  • numpy==1.23.5

To install these dependencies, use the following command:

pip install swifter==1.3.4 openpyxl==3.1.2 ta==0.10.2 pandas==1.5.3 numpy==1.23.5  

Usage

1. File Updater (update_files function)

The update_files function downloads and saves three files required for backtesting:

  • nse_holidays.xlsx: A list of market holidays.
  • angel_tokens.csv: Token data for various trading instruments.
  • all.csv: A list of available instruments.

To update these files, call the function:

update_files(files_path='path/to/save/files/', file_server_url='http://your_server_url/')

2. TraderBackTesterUtils Class

This class provides multiple utility methods for trading and backtesting. Initialize it with the path where required files are stored.

Initialization

trader_backtester_utils = TraderBackTesterUtils(files_path='path/to/files/')

Methods

get_delta_strike_def(name: str) -> pd.DataFrame

Returns strike price details for a given instrument, calculating the differences between consecutive strikes.

round_to(row: Any, num_column: str = 'open', precision_column_val: Any = .05) -> float

Rounds a given value to the nearest tick size (default: 0.05).

get_strike(x: Any, num_column: str = 'open', precision_column_val: Any = .05) -> Any

Rounding method that applies round_to on a DataFrame using swifter for parallel processing.

exp_cal(row: Any, x_org: pd.DataFrame, dat: str = 'date', nxt_exp: Any = 0, montly: Any = False) -> str

Calculates the next expiry date for an instrument. Determines weekly or monthly expiry based on input parameters.

get_exp(x: Any, x_org: pd.DataFrame, dat: str = 'date', nxt_exp: Any = 0, montly: bool = False) -> Any

Uses exp_cal to calculate expiries for a DataFrame.

get_lot(name: str) -> pd.DataFrame

Fetches lot size for a specified instrument name.

add_n_lot_only(data: pd.DataFrame, ticker_column: str, exp_colummn_name: str, column_name_to_create: str) -> pd.DataFrame

Adds a new column with lot sizes based on the ticker and expiry date.

is_holiday(date: str = '') -> bool

Checks if a given date is a market holiday. Defaults to checking today's date.

Example Usage

# Initializing
trader_backtester_utils = TraderBackTesterUtils(files_path='path/to/files/')

# Getting delta strike definitions
delta_strike = trader_backtester_utils.get_delta_strike_def(name='NIFTY')

# Rounding example
rounded_value = trader_backtester_utils.round_to(12569.67)

# Calculating expiry
expiry_date = trader_backtester_utils.get_exp(x='2022-04-20', x_org=your_dataframe)

# Adding lot sizes to DataFrame
updated_data = trader_backtester_utils.add_n_lot_only(data=your_dataframe, ticker_column='ticker', exp_colummn_name='expiry', column_name_to_create='lot_size')

3. TraderBackTesterDM Class

This class provides multiple data manipulation methods for trading and backtesting

Initialization

trader_backtester_dm = TraderBackTesterDM()

Metadata

Release files for traderbacktesteroptalpha 1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for traderbacktesteroptalpha 1.7
File Size Uploaded Provenance Actions
traderbacktesteroptalpha-1.7.tar.gz 10.1 kB Without provenance Details for traderbacktesteroptalpha-1.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for traderbacktesteroptalpha 1.7
File Interpreter ABI Platform Actions
traderbacktesteroptalpha-1.7-py3-none-any.whl Python 3 none any Details for traderbacktesteroptalpha-1.7-py3-none-any.whl

Total release size: 20.1 kB

Release files / traderbacktesteroptalpha-1.7.tar.gz

Download URL traderbacktesteroptalpha-1.7.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f0dfdd41d7ebb4dcc4d5f0fd30125140a9eabb55c3e45d37b642423b14936a66
BLAKE2b-256 checksum
How to use checksums
6ff14d7765ac330670ffd8fb505a15bce181b44ca7946b009eb6db4a1d151235
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.7

Release files / traderbacktesteroptalpha-1.7-py3-none-any.whl

Download URL traderbacktesteroptalpha-1.7-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
afd02f81bd5a9624c86fcf3c2abf3ab070f300dd94b3c9310dbd06ddc69cab06
BLAKE2b-256 checksum
How to use checksums
438fcac04d7769ac9dc9e576e812f4294158538eb5040b1dcc7c7f2b02a5002b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.7

Security for traderbacktesteroptalpha 1.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page