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.
- 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)
Install from PyPI:
pip install openengine
For development installation:
git clone https://github.com/marketcalls/openengine.git
cd openengine
pip install -e .
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", "2023-01-01", "2025-01-01")
strategy = SampleStrategy()
# Run backtest
backtester = Backtester(data, strategy, initial_capital=100000)
portfolio = backtester.run()
print(portfolio.tail())
Run the included example:
python -m openengine.main
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"
})
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
python -m pytest tests/
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the AGPLv3 License - see the LICENSE file for details.