ITradingAgent<T>
Interfaces · AiDotNet.Finance.Interfaces
Interface for financial trading agents using reinforcement learning.
Known implementations: TradingAgentBase<T>
For Beginners
Trading agents learn to make buy/sell decisions:
The Key Insight: Financial markets are complex environments where RL agents can learn optimal trading strategies through trial and error. Trading agents observe market state (prices, volumes, indicators) and learn to take actions (buy, sell, hold) that maximize risk-adjusted returns over time.
Key Components:
- State: Market observations (prices, volumes, technical indicators)
- Actions: Trading decisions (buy, sell, hold, position sizes)
- Rewards: Returns, risk-adjusted metrics (Sharpe ratio)
- Environment: Market simulator or live trading interface
Financial Metrics: Trading agents track specialized metrics not found in standard RL:
- Sharpe Ratio: Risk-adjusted return measure
- Maximum Drawdown: Largest peak-to-trough decline
- Win Rate: Percentage of profitable trades
- Cumulative Return: Total portfolio growth
How It Works
ITradingAgent extends standard RL agent capabilities with financial-specific functionality for trading, portfolio management, and risk assessment.
Properties
| Property | Summary |
|---|---|
T CumulativeReturn { get; } |
Gets the cumulative return since trading began. |
T InitialCapital { get; } |
Gets the initial capital when trading started. |
T MaxDrawdown { get; } |
Gets the maximum drawdown experienced during trading. |
T PortfolioValue { get; } |
Gets the current portfolio value. |
T SharpeRatio { get; } |
Gets the current Sharpe ratio of the trading strategy. |
T WinRate { get; } |
Gets the win rate (percentage of profitable trades). |
int TotalTrades { get; } |
Gets the total number of trades executed. |
Methods
| Method | Summary |
|---|---|
Dictionary<string, T> GetTradingMetrics() |
Gets comprehensive financial metrics for the trading strategy. |
ModelMetadata<T> GetModelMetadata() |
Gets the agent’s model metadata with financial context. |
T TrainOnExperiences() |
Performs one training step using stored experiences. |
Vector<T> ExecuteTradeWithRiskManagement(Vector<T> marketState, T riskBudget) |
Executes a trade with risk management constraints. |
Vector<T> SelectTradingAction(Vector<T> marketState, bool training) |
Selects a trading action given the current market state. |
void ResetTrading(T initialCapital) |
Resets the trading episode and portfolio state. |
void StoreTradingExperience(Vector<T> marketState, Vector<T> action, T reward, Vector<T> nextMarketState, bool done, T pnl) |
Stores a trading experience for learning. |