API Reference
Stock Data Management
alphagen_qlib.stock_data.StockData
Constructor:
__init__(self, instrument: Union[str, List[str]], start_time: str, end_time: str, ...)
- instrument: The stock pool (e.g.,
'csi300'). - start_time: Start date string (YYYY-MM-DD).
- end_time: End date string.
- device:
torch.device(CPU or CUDA).
Methods:
make_dataframe(data: torch.Tensor, columns): Converts the internal tensor representation back into a readable Pandas DataFrame with a MultiIndex (Date, Instrument).
Alpha Models
alphagen.models.linear_alpha_pool.LinearAlphaPool
Constructor:
__init__(self, capacity: int, calculator: AlphaCalculator, ...)
- capacity: Max number of alphas in the pool.
- calculator: Instance of
AlphaCalculatorused for evaluating new alphas.
Methods:
try_new_expr(expr: Expression) -> float: Tests a new expression. If it improves the pool, it is added (and potentially triggers a prune). Returns the improvement metric.optimize(): Recalculates weights for all alphas in the pool (usually via Ridge/Lasso regression).test_ensemble(calculator): Returns(IC, RankIC)tuple for the entire pool on a specific dataset.
RL Environment
alphagen.rl.env.wrapper.AlphaEnv
Wraps the core environment with OpenAI Gym/Farama Gymnasium interfaces.
step(action): Takes an integer action ID.reset(): Resets the expression builder.action_masks(): Returns a boolean array indicating which tokens are valid for the next step (crucial for MaskablePPO).