Skip to main content

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.

Release files for openengine 1.0.0

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

Source distribution (sdist)

Source distribution for openengine 1.0.0
File Size Uploaded
openengine-1.0.0.tar.gz 19.3 kB Details

Built distribution (wheel)

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

Total release size: 40.1 kB

Release files / openengine-1.0.0.tar.gz

Download URL openengine-1.0.0.tar.gz
Size 19.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d9eb9a5046a355ad3fdbd6d49a68dd0859a219ef94a2159551f065bbd21f975a
BLAKE2b-256 checksum
How to use checksums
bf31f8f22b5f091c204f8a4f6efd7c9f0c9614e046fe5cce366a6d52f3e0d0f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.8

Release files / openengine-1.0.0-py3-none-any.whl

Download URL openengine-1.0.0-py3-none-any.whl
Size 20.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8d470d5ff3bea8d67e8987fa01052953962c90829c57186a95645aaf0a1a94fc
BLAKE2b-256 checksum
How to use checksums
9ba8483f8e6e1a6e8b30fea64763c699808b6362535f259d28e976fb6754c1c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.8

Release history Release notifications | RSS feed

This release

1.0.0 This release

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