This project enables users to describe what they want to do with a stock in natural language, and a fine-tuned DeepSeek LLM will translate that into Python code for backtesting. The model is trained to understand trading logic and output Python scripts that are ready for use in popular backtesting libraries.
Users receive both the code and instructions on how to run the strategy themselves.
- 🗣️ Natural Language Input: Describe your stock trading strategy in your own words.
- 🤖 LLM Code Generation: Our fine-tuned DeepSeek model on Hugging Face converts your text to Python code.
- 📉 Backtest-Ready: Output is structured for easy use in backtesting environments (like Backtrader).
- 🌐 Modern Web Interface: Built with React.js for a clean and intuitive user experience.
Make sure Python 3.8+ is installed. Then install the required dependencies:
pip install -r requirements.txtStart the backend service, which runs the fine-tuned DeepSeek model:
python3 TextToCodeModel.pyThis will launch a local API server that handles natural language input and returns Python code for strategy logic.
Make sure you have Node.js installed. In the project root or frontend directory:
npm install
npm run devThis will start the React development server at http://localhost:5173.
- You describe your stock strategy in natural language.
- The frontend sends this input to the backend API.
- The fine-tuned DeepSeek model processes your input and returns a Python script.
- You receive:
- 🐍 Generated Python code
- 📘 Instructions on how to run a backtest
Input:
“Short Tesla when RSI goes above 70 and exit when it drops below 50.”
Output:
from backtrader import Strategy, SignalStrategy, signals
class RSIStrategy(Strategy):
params = dict(
rsi_period=14,
upper=70,
lower=50
)
def __init__(self):
self.rsi = bt.ind.RSI(period=self.p.rsi_period)
def next(self):
if not self.position:
if self.rsi[0] > self.p.upper:
self.sell()
elif self.rsi[0] < self.p.lower:
self.close()Instructions:
-
Save the above code in a file called
rsi_strategy.py. -
Install Backtrader via:
pip install backtrader
-
Prepare a historical dataset or connect to a data source.
-
Run your backtest using:
python3 rsi_strategy.py
The model can generate different strategies including moving average crossovers, RSI triggers, Bollinger Band-based entries, and more!
- Python 3.8+
- Transformers (Hugging Face)
- Flask or FastAPI
- React.js (Frontend)
- Node.js and npm
Pull requests and feedback are welcome! Help us make this tool better for traders, developers, and anyone experimenting with algorithmic trading.
This project is licensed under the MIT License.