FinancialDQNAgent<T>

Models & Types · AiDotNet.Finance.Trading.Agents

Financial Deep Q-Network (DQN) agent for discrete action trading.

Inheritance: ReinforcementLearningAgentBase<T> → TradingAgentBase<T> → FinancialDQNAgent<T>

Implements: IGeneratedParameterRegistrar<T>, IGradientComputable<T, Vector<T>, Vector<T>>, IMaskableAgent<T>

For Beginners

The DQN (Deep Q-Network) trading agent learns to make discrete trading decisions (buy, sell, or hold) by estimating the long-term value of each action. It maintains a “memory” of past experiences and learns from random samples of those memories. A separate target network prevents the learning from becoming unstable. DQN is best suited for trading scenarios with a fixed set of possible actions.

Example

// Define Q-network architecture for discrete trading (10 state features, 3 actions: buy/hold/sell)
var architecture = new NeuralNetworkArchitecture<double>(
    inputType: InputType.OneDimensional,
    taskType: NeuralNetworkTaskType.Regression,
    inputSize: 10, outputSize: 3);
            
// Create DQN agent for discrete action stock trading
var options = new TradingAgentOptions<double>();
var model = new FinancialDQNAgent<double>(architecture, options);
            
// Parameterless constructor with default 10-feature, 3-action architecture
var defaultModel = new FinancialDQNAgent<double>();

Constructors

Constructor Summary
FinancialDQNAgent() Initializes a new instance of the FinancialDQNAgent class.
FinancialDQNAgent(NeuralNetworkArchitecture<T> architecture, TradingAgentOptions<T> options)

Properties

Property Summary
double CurrentEpsilon { get; } Current exploration rate: max(EpsilonEnd, EpsilonStart * EpsilonDecay^updates), where updates counts the gradient updates applied so far (the same per-update multiplicative schedule as the library’s DQNAgent).
int FeatureCount { get; }

Methods

Method Summary
Dictionary<string, T> GetMetrics() Trading metrics plus the CURRENT exploration rate.
Dictionary<string, T> GetTradingMetrics()
ModelMetadata<T> GetModelMetadata()
ModelOptions GetOptions() The CURRENT exploration rate, annealed from EpsilonStart toward EpsilonEnd by EpsilonDecay.
T Train()
Vector<T> ComputeGradients(Vector<T> input, Vector<T> target, ILossFunction<T> lossFunction)
Vector<T> SelectAction(Vector<T> state, bool training)
Vector<T> SelectAction(Vector<T> state, bool training, bool[] legalActions)
byte[] Serialize() Auto-generated common model serialization surface.
void ApplyGradients(Vector<T> gradients, T learningRate)
void Deserialize(byte[] data) Auto-generated common model deserialization surface.
void LoadModel(string filepath) Executes LoadModel for the FinancialDQNAgent.
void SaveModel(string filepath) Executes SaveModel for the FinancialDQNAgent.
void StoreExperience(Vector<T> state, Vector<T> action, T reward, Vector<T> nextState, bool done) Executes StoreExperience for the FinancialDQNAgent.
void StoreExperience(Vector<T> state, Vector<T> action, T reward, Vector<T> nextState, bool done, bool[] nextLegalActions)