Skip to main content

A backtesting and live trading engine library for Indian markets

Project description

OpenEngine

OpenEngine is a Python library for backtesting and live trading in Indian markets. It features an event-driven architecture and integrates with the OpenAlgo PlaceOrder API for live execution.

Features

  • Event-driven backtesting engine
  • Live trading support
  • Integration with Yahoo Finance for historical data
  • Moving average crossover strategy included as example
  • Modular design for easy extension
  • Support for Indian markets (NSE)

Installation

Install from PyPI:

pip install openengine

For development installation:

git clone https://github.com/yourusername/openengine.git
cd openengine
pip install -e .

Quick Start

from openengine.data.yahoo_connector import YahooFinanceConnector
from openengine.strategies.sample_strategy import SampleStrategy
from openengine.engine.backtester import Backtester

# Initialize components
data_connector = YahooFinanceConnector()
data = data_connector.fetch_data("RELIANCE.NS", "2022-01-01", "2023-01-01")
strategy = SampleStrategy()

# Run backtest
backtester = Backtester(data, strategy, initial_capital=100000)
portfolio = backtester.run()
print(portfolio.tail())

Usage

Backtesting

Run the included example:

python -m openengine.main

Live Trading

from openengine.engine.live_trader import LiveTrader
from openengine.execution.broker_interface import BrokerInterface
from openengine.strategies.sample_strategy import SampleStrategy

# Initialize components
broker = BrokerInterface("http://your-broker-api", "your-api-key")
strategy = SampleStrategy()
trader = LiveTrader(strategy, broker)

# Process market data
trader.on_new_data({
    "symbol": "RELIANCE.NS",
    "price": 2500.0,
    "timestamp": "2025-02-06 09:15:00"
})

Development

Adding New Strategies

Create a new strategy by inheriting from BaseStrategy:

from openengine.strategies.base_strategy import BaseStrategy

class MyStrategy(BaseStrategy):
    def generate_signals(self, data):
        # Your strategy logic here
        return signals

Running Tests

python -m pytest tests/

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openengine-1.0.0.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openengine-1.0.0-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file openengine-1.0.0.tar.gz.

File metadata

  • Download URL: openengine-1.0.0.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for openengine-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d9eb9a5046a355ad3fdbd6d49a68dd0859a219ef94a2159551f065bbd21f975a
MD5 f49ccdf2c6e1f2321670fc7a35738dac
BLAKE2b-256 bf31f8f22b5f091c204f8a4f6efd7c9f0c9614e046fe5cce366a6d52f3e0d0f2

See more details on using hashes here.

File details

Details for the file openengine-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: openengine-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for openengine-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d470d5ff3bea8d67e8987fa01052953962c90829c57186a95645aaf0a1a94fc
MD5 e11ad880efbf5b69df84ee05573c3831
BLAKE2b-256 9ba8483f8e6e1a6e8b30fea64763c699808b6362535f259d28e976fb6754c1c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page