Implementation:51bitquant Ai hedge fund crypto MyStrategy call
| Knowledge Sources | |
|---|---|
| Domains | Signal_Generation, Extensibility |
| Last Updated | 2026-10-28 14:00 GMT |
Overview
Concrete example of a custom strategy implementing a simple SMA(10)/SMA(30) crossover, provided as a template by the `MyStrategy` class.
Description
MyStrategy is a BaseNode subclass included as a user-facing template. Its `__call__` iterates tickers × intervals, computes `sma_fast = close.rolling(10).mean()` and `sma_slow = close.rolling(30).mean()`, and produces a `bullish` signal when `sma_fast > sma_slow` (confidence 70), `bearish` when below, and `neutral` otherwise (confidence 50). Results are written to `analyst_signals["my_strategy_agent"]` with an emitted `HumanMessage(name="my_strategy_agent")`.
Usage
Use this as a starting point for custom strategies. Copy the file, rename the class and agent name, implement your logic, register it in `src/strategies/__init__.py`, and add the class name to `config.yaml`'s `signals.strategies`. Note: downstream `PortfolioManagementNode` reads the `technical_analyst_agent` key specifically; a custom agent name may require updating the consumer or aligning to that key.
Code Reference
Source Location
- Repository: ai-hedge-fund-crypto
- File: src/strategies/my_strategy.py
Signature
class MyStrategy(BaseNode):
def __call__(self, state: AgentState) -> Dict[str, Any]:
# For each ticker/interval:
# df['sma_fast'] = df['close'].rolling(10).mean()
# df['sma_slow'] = df['close'].rolling(30).mean()
# signal = bullish/bearish/neutral based on crossover
# technical_analysis[ticker][interval.value] = {signal, confidence, strategy_signals{...}}
# state["data"]["analyst_signals"]["my_strategy_agent"] = technical_analysis
# return {"messages": [HumanMessage(name="my_strategy_agent")], "data": data}
Import
from src.strategies.my_strategy import MyStrategy
# Or dynamically via import_strategy_class("src.strategies.MyStrategy")
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| state | AgentState | Yes | Reads `data["tickers"]`, `data["intervals"]`, `data[f"{ticker}_{interval.value}"]` |
Outputs
| Name | Type | Description |
|---|---|---|
| return | Dict[str, Any] | `{"messages": [HumanMessage(name="my_strategy_agent")], "data": data}` |
| analyst_signals | Dict | `data["analyst_signals"]["my_strategy_agent"]` = ticker → interval → `{signal, confidence, strategy_signals{...}}` |
Usage Examples
Enable in config.yaml
# config.yaml
signals:
strategies: ["MyStrategy"]
Custom Template
# Copy and adapt the template
class RsiStrategy(BaseNode):
def __call__(self, state: AgentState) -> Dict[str, Any]:
data = state["data"]
for ticker in data["tickers"]:
for interval in data["intervals"]:
df = data.get(f"{ticker}_{interval.value}", pd.DataFrame())
rsi = df["close"].diff().rolling(14).mean() # simplified
# ... build analysis dict
# Emit HumanMessage and write analyst_signals
Related Pages
Implements Principle
- Principle:51bitquant_Ai_hedge_fund_crypto_Strategy_Plugin_Architecture
- Principle:51bitquant_Ai_hedge_fund_crypto_Ensemble_Signal_Generation