Skip to main content

About project

A small wrapper over smartapi to backtest basic trading strategies. Easy installation and usage

Installation

pip install alphatools_jv

Usage

Creating and running a strategy

from alphatools.backtesting_app import BackTestingApp
from datetime import datetime

class TestSmartApiApp(BackTestingApp):

    def on_md(self, data_row):
        # your strat code goes here
        print("New row found: {}".format(data_row))


app = TestSmartApiApp('/Users/jaskiratsingh/projects/smart-api-creds.ini')
app.set_start_date(datetime.strptime('2022-12-20 11:39:00+05:30', '%Y-%m-%d %H:%M:%S%z'))
app.set_end_date(datetime.strptime('2022-12-29 11:39:00+05:30', '%Y-%m-%d %H:%M:%S%z'))
app.set_interval('ONE_MINUTE')
app.add_instrument(53825, "NFO")
app.add_instrument(48756, "NFO")
app.load_data()                     # Loads the data into a dataframe
app.get_candle_info_df()            # Returns the entire simulation dataframe
app.simulate()                      # Starts simulation from the beginning

# To place a trade, use trade api to send the orders to the pnl calculator. 
# Pnl calculator uses last tick prices to calculate the observed Pnl
app.trade(53825, 1)     # Buys 1 unit for token 53825
app.trade(53825, -3)    # Sells 3 units for token 53825
app.get_total_pnl()     # Returns pnl after all trades are made

Helper for instruments

from alphatools.utils.token_manager import TokenManager

tok = TokenManager()

# Refer documentation for more overrides
info = tok.get_instrument(53825) # Returns instrument info
info = tok.get_instrument('NIFTY23FEB23FUT') # Returns instrument info

Release files for alphatools-jv 3.4.1

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

Source distribution (sdist)

Source distribution for alphatools-jv 3.4.1
File Size Uploaded
alphatools_jv-3.4.1.tar.gz 11.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for alphatools-jv 3.4.1
File Interpreter ABI Platform
alphatools_jv-3.4.1-py3-none-any.whl Python 3 none any Details

Total release size:26.1 kB

Release files / alphatools_jv-3.4.1.tar.gz

Download URL alphatools_jv-3.4.1.tar.gz
Size 11.3 kB
Tags Source
SHA-256 checksum
How to use checksums
72484d43ebe8c4b56b7b0b9664300c49695f942b75d0ef5eebe6d3715b63704b
BLAKE2b-256 checksum
How to use checksums
ee3cd52ba8e78352533f64d560231b33c5a82dd4829ad1175ffc7c152dc6ec51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.9.6 readme-renderer/40.0 requests/2.28.2 requests-toolbelt/1.0.0 urllib3/1.26.16 tqdm/4.65.0 importlib-metadata/6.8.0 keyring/24.2.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.11.4

Release files / alphatools_jv-3.4.1-py3-none-any.whl

Download URL alphatools_jv-3.4.1-py3-none-any.whl
Size 14.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
edb12b5ec254119c9b31daa651bd472b689ac6e7a517e293d336b2b042fd93fe
BLAKE2b-256 checksum
How to use checksums
b194a695b8074432146d0a4dad3f76279e20e67dee2fbce311ee975ae57907ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.9.6 readme-renderer/40.0 requests/2.28.2 requests-toolbelt/1.0.0 urllib3/1.26.16 tqdm/4.65.0 importlib-metadata/6.8.0 keyring/24.2.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.11.4

Release history Release notifications | RSS feed

This release

3.4.1 This release

2 release files

3.4.0

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.2.0

2 release files

2.1.1

2 release files

2.0.0

2 release files

1.2

2 release files

1.1

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0

2 release files

0.0.7.2

1 release file

0.0.7.1

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5.2

1 release file

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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