FinRLAgent<T>

Models & Types · AiDotNet.Finance.Trading.Agents

Unified FinRL-style agent that can switch between multiple RL algorithms.

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

Implements: IGeneratedParameterRegistrar<T>, IMaskableAgent<T>

For Beginners

FinRL is a unified framework for applying reinforcement learning to stock trading. It can switch between different RL algorithms (DQN, PPO, A2C, SAC) while providing a consistent trading interface. Think of it as a toolkit that lets you train an AI trader that learns buy/sell/hold strategies by practicing on historical market data, similar to how a game AI learns by playing thousands of games.

Example

// Define actor architecture for FinRL multi-algorithm trading (30 state features, 3 actions)
var actorArch = new NeuralNetworkArchitecture<double>(
    inputType: InputType.OneDimensional,
    taskType: NeuralNetworkTaskType.Regression,
    inputSize: 30, outputSize: 3);
            
// Create FinRL agent with PPO algorithm for stock trading
var options = new TradingAgentOptions<double>();
var model = new FinRLAgent<double>(actorArch, options, FinRLAlgorithm.PPO);

Constructors

Constructor Summary
FinRLAgent(NeuralNetworkArchitecture<T> primaryArchitecture, TradingAgentOptions<T> options, FinRLAlgorithm algorithm, NeuralNetworkArchitecture<T> secondaryArchitecture) Initializes a new instance of the FinRLAgent class.

Properties

Property Summary
FinRLAlgorithm Algorithm { get; } Gets the RL algorithm being used.
int FeatureCount { get; }

Methods

Method Summary
ModelMetadata<T> GetModelMetadata()
ModelOptions GetOptions()
T Train()
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 Deserialize(byte[] data) Auto-generated common model deserialization surface.
void Dispose() Disposes the wrapped algorithm agent, which owns every network this wrapper trains.
void LoadModel(string filepath) Executes LoadModel for the FinRLAgent.
void SaveModel(string filepath) Executes SaveModel for the FinRLAgent.
void StoreExperience(Vector<T> state, Vector<T> action, T reward, Vector<T> nextState, bool done)
void StoreExperience(Vector<T> state, Vector<T> action, T reward, Vector<T> nextState, bool done, bool[] nextLegalActions) Executes StoreExperience for the FinRLAgent.
void Train(Vector<T> state, Vector<T> target)