# finrl - Doramagic AI Context Pack

> 定位：安装前体验与判断资产。它帮助宿主 AI 有一个好的开始，但不代表已经安装、执行或验证目标项目。

## 充分原则

- **充分原则，不是压缩原则**：AI Context Pack 应该充分到让宿主 AI 在开工前理解项目价值、能力边界、使用入口、风险和证据来源；它可以分层组织，但不以最短摘要为目标。
- **压缩策略**：只压缩噪声和重复内容，不压缩会影响判断和开工质量的上下文。

## 给宿主 AI 的使用方式

你正在读取 Doramagic 为 finrl 编译的 AI Context Pack。请把它当作开工前上下文：帮助用户理解适合谁、能做什么、如何开始、哪些必须安装后验证、风险在哪里。不要声称你已经安装、运行或执行了目标项目。

## Claim 消费规则

- **事实来源**：Repo Evidence + Claim/Evidence Graph；Human Wiki 只提供显著性、术语和叙事结构。
- **事实最低状态**：`supported`
- `supported`：可以作为项目事实使用，但回答中必须引用 claim_id 和证据路径。
- `weak`：只能作为低置信度线索，必须要求用户继续核实。
- `inferred`：只能用于风险提示或待确认问题，不能包装成项目事实。
- `unverified`：不得作为事实使用，应明确说证据不足。
- `contradicted`：必须展示冲突来源，不得替用户强行选择一个版本。

## 它最适合谁

- **AI 研究者或研究型 Agent 构建者**：README 明确围绕研究、实验或论文工作流展开。 证据：`README.md` Claim：`clm_0002` supported 0.86

## 它能做什么

- **命令行启动或安装流程**（需要安装后验证）：项目文档中存在可执行命令，真实使用需要在本地或宿主环境中运行这些命令。 证据：`README.md` Claim：`clm_0001` supported 0.86

## 怎么开始

- `git clone https://github.com/AI4Finance-Foundation/FinRL.git` 证据：`README.md` Claim：`clm_0003` supported 0.86
- `pip install -e .` 证据：`README.md` Claim：`clm_0004` supported 0.86

## 继续前判断卡

- **当前建议**：先做研究框架试用
- **为什么**：这个项目面向研究工作流，核心风险是资料可信度和输出质量；先用 Prompt Preview 验证研究框架，再在隔离环境试装。

### 30 秒判断

- **现在怎么做**：先做研究框架试用
- **最小安全下一步**：先用 Prompt Preview 验证研究框架；满意后再隔离试装
- **先别相信**：研究结论、引用和实验结果不能在安装前相信。
- **继续会触碰**：研究判断、命令执行、本地环境或项目文件

### 现在可以相信

- **适合人群线索：AI 研究者或研究型 Agent 构建者**（supported）：有 supported claim 或项目证据支撑，但仍不等于真实安装效果。 证据：`README.md` Claim：`clm_0002` supported 0.86
- **能力存在：命令行启动或安装流程**（supported）：可以相信项目包含这类能力线索；是否适合你的具体任务仍要试用或安装后验证。 证据：`README.md` Claim：`clm_0001` supported 0.86
- **存在 Quick Start / 安装命令线索**（supported）：可以相信项目文档出现过启动或安装入口；不要因此直接在主力环境运行。 证据：`README.md` Claim：`clm_0003` supported 0.86

### 现在还不能相信

- **研究结论、引用和实验结果不能在安装前相信。**（unverified）：研究 Skill 可以组织问题和路径，但不能替代真实资料检索、论文核验和实验复现。
- **是否适合你的具体研究领域不能直接相信。**（unverified）：Skill 覆盖很多研究主题，不代表对你的领域、资料要求和可信度标准足够。
- **真实输出质量不能在安装前相信。**（unverified）：Prompt Preview 只能展示引导方式，不能证明真实项目中的结果质量。
- **宿主 AI 版本兼容性不能在安装前相信。**（unverified）：Claude、Cursor、Codex、Gemini 等宿主加载规则和版本差异必须在真实环境验证。
- **不会污染现有宿主 AI 行为，不能直接相信。**（inferred）：Skill、plugin、AGENTS/CLAUDE/GEMINI 指令可能改变宿主 AI 的默认行为。
- **可安全回滚不能默认相信。**（unverified）：除非项目明确提供卸载和恢复说明，否则必须先在隔离环境验证。
- **真实安装后是否与用户当前宿主 AI 版本兼容？**（unverified）：兼容性只能通过实际宿主环境验证。
- **项目输出质量是否满足用户具体任务？**（unverified）：安装前预览只能展示流程和边界，不能替代真实评测。

### 继续会触碰什么

- **研究判断**：问题拆解、资料路径、实验路径、结论结构和可信度判断。 原因：研究型 Skill 可能让输出看起来更专业，但不能替代真实证据核验。
- **命令执行**：包管理器、网络下载、本地插件目录、项目配置或用户主目录。 原因：运行第一条命令就可能产生环境改动；必须先判断是否值得跑。 证据：`README.md`
- **本地环境或项目文件**：安装结果、插件缓存、项目配置或本地依赖目录。 原因：安装前无法证明写入范围和回滚方式，需要隔离验证。 证据：`README.md`
- **宿主 AI 上下文**：AI Context Pack、Prompt Preview、Skill 路由、风险规则和项目事实。 原因：导入上下文会影响宿主 AI 后续判断，必须避免把未验证项包装成事实。

### 最小安全下一步

- **先跑 Prompt Preview**：先验证它能否正确界定研究问题和证据边界，不要先相信研究输出。（适用：任何项目都适用，尤其是输出质量未知时。）
- **只在隔离目录或测试账号试装**：避免安装命令污染主力宿主 AI、真实项目或用户主目录。（适用：存在命令执行、插件配置或本地写入线索时。）
- **安装后只验证一个最小任务**：先验证加载、兼容、输出质量和回滚，再决定是否深用。（适用：准备从试用进入真实工作流时。）

### 退出方式

- **保留安装前状态**：记录原始宿主配置和项目状态，后续才能判断是否可恢复。
- **保留资料和结论核验清单**：如果后续发现引用或实验路径不可靠，可以回到证据边界阶段重新校验。
- **记录安装命令和写入路径**：没有明确卸载说明时，至少要知道哪些目录或配置需要手动清理。
- **如果没有回滚路径，不进入主力环境**：不可回滚是继续前阻断项，不应靠信任或运气继续。

## 哪些只能预览

- 解释项目适合谁和能做什么
- 基于项目文档演示典型对话流程
- 帮助用户判断是否值得安装或继续研究

## 哪些必须安装后验证

- 真实安装 Skill、插件或 CLI
- 执行脚本、修改本地文件或访问外部服务
- 验证真实输出质量、性能和兼容性

## 边界与风险判断卡

- **把安装前预览误认为真实运行**：用户可能高估项目已经完成的配置、权限和兼容性验证。 处理方式：明确区分 prompt_preview_can_do 与 runtime_required。 Claim：`clm_0005` inferred 0.45
- **命令执行会修改本地环境**：安装命令可能写入用户主目录、宿主插件目录或项目配置。 处理方式：先在隔离环境或测试账号中运行。 证据：`README.md` Claim：`clm_0006` supported 0.86
- **待确认**：真实安装后是否与用户当前宿主 AI 版本兼容？。原因：兼容性只能通过实际宿主环境验证。
- **待确认**：项目输出质量是否满足用户具体任务？。原因：安装前预览只能展示流程和边界，不能替代真实评测。
- **待确认**：安装命令是否需要网络、权限或全局写入？。原因：这影响企业环境和个人环境的安装风险。

## 开工前工作上下文

### 加载顺序

- 先读取 how_to_use.host_ai_instruction，建立安装前判断资产的边界。
- 读取 claim_graph_summary，确认事实来自 Claim/Evidence Graph，而不是 Human Wiki 叙事。
- 再读取 intended_users、capabilities 和 quick_start_candidates，判断用户是否匹配。
- 需要执行具体任务时，优先查 role_skill_index，再查 evidence_index。
- 遇到真实安装、文件修改、网络访问、性能或兼容性问题时，转入 risk_card 和 boundaries.runtime_required。

### 任务路由

- **命令行启动或安装流程**：先说明这是安装后验证能力，再给出安装前检查清单。 边界：必须真实安装或运行后验证。 证据：`README.md` Claim：`clm_0001` supported 0.86

### 上下文规模

- 文件总数：146
- 重要文件覆盖：40/146
- 证据索引条目：74
- 角色 / Skill 条目：9

### 证据不足时的处理

- **missing_evidence**：说明证据不足，要求用户提供目标文件、README 段落或安装后验证记录；不要补全事实。
- **out_of_scope_request**：说明该任务超出当前 AI Context Pack 证据范围，并建议用户先查看 Human Manual 或真实安装后验证。
- **runtime_request**：给出安装前检查清单和命令来源，但不要替用户执行命令或声称已执行。
- **source_conflict**：同时展示冲突来源，标记为待核实，不要强行选择一个版本。

## Prompt Recipes

### 适配判断

- 目标：判断这个项目是否适合用户当前任务。
- 预期输出：适配结论、关键理由、证据引用、安装前可预览内容、必须安装后验证内容、下一步建议。

```text
请基于 finrl 的 AI Context Pack，先问我 3 个必要问题，然后判断它是否适合我的任务。回答必须包含：适合谁、能做什么、不能做什么、是否值得安装、证据来自哪里。所有项目事实必须引用 evidence_refs、source_paths 或 claim_id。
```

### 安装前体验

- 目标：让用户在安装前感受核心工作流，同时避免把预览包装成真实能力或营销承诺。
- 预期输出：一段带边界标签的体验剧本、安装后验证清单和谨慎建议；不含真实运行承诺或强营销表述。

```text
请把 finrl 当作安装前体验资产，而不是已安装工具或真实运行环境。

请严格输出四段：
1. 先问我 3 个必要问题。
2. 给出一段“体验剧本”：用 [安装前可预览]、[必须安装后验证]、[证据不足] 三种标签展示它可能如何引导工作流。
3. 给出安装后验证清单：列出哪些能力只有真实安装、真实宿主加载、真实项目运行后才能确认。
4. 给出谨慎建议：只能说“值得继续研究/试装”“先补充信息后再判断”或“不建议继续”，不得替项目背书。

硬性边界：
- 不要声称已经安装、运行、执行测试、修改文件或产生真实结果。
- 不要写“自动适配”“确保通过”“完美适配”“强烈建议安装”等承诺性表达。
- 如果描述安装后的工作方式，必须使用“如果安装成功且宿主正确加载 Skill，它可能会……”这种条件句。
- 体验剧本只能写成“示例台词/假设流程”：使用“可能会询问/可能会建议/可能会展示”，不要写“已写入、已生成、已通过、正在运行、正在生成”。
- Prompt Preview 不负责给安装命令；如用户准备试装，只能提示先阅读 Quick Start 和 Risk Card，并在隔离环境验证。
- 所有项目事实必须来自 supported claim、evidence_refs 或 source_paths；inferred/unverified 只能作风险或待确认项。

```

### 角色 / Skill 选择

- 目标：从项目里的角色或 Skill 中挑选最匹配的资产。
- 预期输出：候选角色或 Skill 列表，每项包含适用场景、证据路径、风险边界和是否需要安装后验证。

```text
请读取 role_skill_index，根据我的目标任务推荐 3-5 个最相关的角色或 Skill。每个推荐都要说明适用场景、可能输出、风险边界和 evidence_refs。
```

### 风险预检

- 目标：安装或引入前识别环境、权限、规则冲突和质量风险。
- 预期输出：环境、权限、依赖、许可、宿主冲突、质量风险和未知项的检查清单。

```text
请基于 risk_card、boundaries 和 quick_start_candidates，给我一份安装前风险预检清单。不要替我执行命令，只说明我应该检查什么、为什么检查、失败会有什么影响。
```

### 宿主 AI 开工指令

- 目标：把项目上下文转成一次对话开始前的宿主 AI 指令。
- 预期输出：一段边界明确、证据引用明确、适合复制给宿主 AI 的开工前指令。

```text
请基于 finrl 的 AI Context Pack，生成一段我可以粘贴给宿主 AI 的开工前指令。这段指令必须遵守 not_runtime=true，不能声称项目已经安装、运行或产生真实结果。
```

## 角色 / Skill 索引

- 共索引 9 个角色 / Skill / 项目文档条目。

- **FinRL: Financial Reinforcement Learning → FinRL-X**（project_doc）：FinRL: Financial Reinforcement Learning → FinRL-X 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`README.md`
- **FinRL Stock Trading 2026 Tutorial**（project_doc）：Step 2: Create and Activate Virtual Environment 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`examples/README.md`
- **Readme**（project_doc）：This folder has three subfolders: + applications: trading tasks, + agents: DRL algorithms, from ElegantRL, RLlib, or Stable Baselines 3 SB3 . Users can plug in any DRL lib and play. + meta: market environments, we merge the stable ones from the active FinRL-Meta repo https://github.com/AI4Finance-Foundation/FinRL-Meta . 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`finrl/README.md`
- **Portfolio Optimization Agents**（project_doc）：This directory contains architectures and algorithms commonly used in portfolio optimization agents. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`finrl/agents/portfolio_optimization/README.md`
- **Usage**（project_doc）：We show a workflow of applying RL in algorithmic trading, which is a reproduction and improvement of the process in the NeurIPS 2018 paper https://arxiv.org/abs/1811.07522 . 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`finrl/applications/Stock_NeurIPS2018/README.md`
- **FinRL Imitation Learning**（project_doc）：A multi-stage machine learning approach is a promising approach for analyzing financial big data, especially when learning from alpha factors or smart investors. Here, we automate this workflow, starting with imitating these strategies, and then using reinforcement learning method to further refine the results. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`finrl/applications/imitation_learning/README.md`
- **PortfolioOptimizationEnv POE**（project_doc）：This environment simulates the effects of the market in a portfolio that is periodically rebalanced through a reinforcement learning agent. At every timestep $t$, the agent is responsible for determining a portfolio vector $W {t}$ which contains the percentage of money invested in each stock. The environment, then, utilizes data provided by the user to simulate the new portfolio value at time-step $t+1$. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`finrl/meta/env_portfolio_optimization/README.md`
- **Publications**（project_doc）：Papers by the Columbia research team can be found at Google Scholar https://scholar.google.com/citations?view op=list works&hl=en&hl=en&user=XsdPXocAAAAJ . 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/source/reference/publication.md`
- **External Sources**（project_doc）：The following contents are collected and referred by AI4Finance community during the development of FinRL and related projects. Some of them are educational and relatively easy while some others are professional and need advanced knowledge. We appreciate and respect the effort of all these contents' authors and developers. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/source/reference/reference.md`

## 证据索引

- 共索引 74 条证据。

- **FinRL: Financial Reinforcement Learning → FinRL-X**（documentation）：FinRL: Financial Reinforcement Learning → FinRL-X 证据：`README.md`
- **FinRL Stock Trading 2026 Tutorial**（documentation）：Step 2: Create and Activate Virtual Environment 证据：`examples/README.md`
- **Readme**（documentation）：This folder has three subfolders: + applications: trading tasks, + agents: DRL algorithms, from ElegantRL, RLlib, or Stable Baselines 3 SB3 . Users can plug in any DRL lib and play. + meta: market environments, we merge the stable ones from the active FinRL-Meta repo https://github.com/AI4Finance-Foundation/FinRL-Meta . 证据：`finrl/README.md`
- **Portfolio Optimization Agents**（documentation）：This directory contains architectures and algorithms commonly used in portfolio optimization agents. 证据：`finrl/agents/portfolio_optimization/README.md`
- **Usage**（documentation）：We show a workflow of applying RL in algorithmic trading, which is a reproduction and improvement of the process in the NeurIPS 2018 paper https://arxiv.org/abs/1811.07522 . 证据：`finrl/applications/Stock_NeurIPS2018/README.md`
- **FinRL Imitation Learning**（documentation）：A multi-stage machine learning approach is a promising approach for analyzing financial big data, especially when learning from alpha factors or smart investors. Here, we automate this workflow, starting with imitating these strategies, and then using reinforcement learning method to further refine the results. 证据：`finrl/applications/imitation_learning/README.md`
- **PortfolioOptimizationEnv POE**（documentation）：This environment simulates the effects of the market in a portfolio that is periodically rebalanced through a reinforcement learning agent. At every timestep $t$, the agent is responsible for determining a portfolio vector $W {t}$ which contains the percentage of money invested in each stock. The environment, then, utilizes data provided by the user to simulate the new portfolio value at time-step $t+1$. 证据：`finrl/meta/env_portfolio_optimization/README.md`
- **License**（source_file）：Copyright c 2024 AI4Finance Foundation Inc. 证据：`LICENSE`
- **Publications**（documentation）：Papers by the Columbia research team can be found at Google Scholar https://scholar.google.com/citations?view op=list works&hl=en&hl=en&user=XsdPXocAAAAJ . 证据：`docs/source/reference/publication.md`
- **External Sources**（documentation）：The following contents are collected and referred by AI4Finance community during the development of FinRL and related projects. Some of them are educational and relatively easy while some others are professional and need advanced knowledge. We appreciate and respect the effort of all these contents' authors and developers. 证据：`docs/source/reference/reference.md`
- **Custom config**（source_file）：Byte-compiled / optimized / DLL files pycache / .py cod $py.class 证据：`.gitignore`
- **.Pre Commit Config**（source_file）：exclude: 'Stock NeurIPS2018.py' ci: skip: flake8 repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v6.0.0 hooks: - id: check-docstring-first - id: check-yaml - id: end-of-file-fixer - id: requirements-txt-fixer - id: trailing-whitespace - repo: https://github.com/asottile/reorder-python-imports rev: v3.15.0 hooks: - id: reorder-python-imports args: --py37-plus, --add-import, "from future import annotations" - repo: https://github.com/asottile/pyupgrade rev: v3.20.0 hooks: - id: pyupgrade args: --py37-plus - repo: https://github.com/psf/black rev: 25.1.0 hooks: - id: black - repo: https://github.com/PyCQA/flake8 rev: 7.3.0 hooks: - id: flake8 证据：`.pre-commit-config.yaml`
- **1.66**（source_file）：Collecting package metadata current repodata.json : ...working... done Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve. Collecting package metadata repodata.json : ...working... done Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve. 证据：`1.66.32`
- **Add Tini. Tini operates as a process subreaper for jupyter. This prevents kernel crashes.**（source_file）：FROM stablebaselines/rl-baselines3-zoo 证据：`docker/Dockerfile`
- **.Readthdocs**（source_file）：python: setup py install: true 证据：`docs/.readthdocs.yaml`
- **Minimal makefile for Sphinx documentation**（source_file）：Minimal makefile for Sphinx documentation Run using make html. 证据：`docs/Makefile`
- **Make**（source_file）：REM Command file for Sphinx documentation. Run using .\make.bat html. 证据：`docs/make.bat`
- **Finrl Ensemble Stocktrading Icaif 2020**（source_file）：{ "cells": { "cell type": "markdown", "metadata": { "id": "Lb9q2 QZgdNk" }, "source": " \n", " \n", " " }, { "cell type": "markdown", "metadata": { "id": "gXaoZs2lh1hi" }, "source": " Deep Reinforcement Learning for Stock Trading from Scratch: Multiple Stock Trading Using Ensemble Strategy\n", "\n", "Tutorials to use OpenAI DRL to trade multiple stocks using ensemble strategy in one Jupyter Notebook Presented at ICAIF 2020\n", "\n", " This notebook is the reimplementation of our paper: Deep Reinforcement Learning for Automated Stock Trading: An Ensemble Strategy, using FinRL.\n", " Check out medium blog for detailed explanations: https://medium.com/@ai4finance/deep-reinforcement-learning-fo… 证据：`examples/FinRL_Ensemble_StockTrading_ICAIF_2020.ipynb`
- **Finrl Gpm Demo**（source_file）：{ "cells": { "cell type": "markdown", "metadata": { "id": "3xt6fIDownZs" }, "source": " GPM: A graph convolutional network based reinforcement learning framework for portfolio management\n", "\n", "In this document, we will make use of a graph neural network architecture called GPM, introduced in the following paper:\n", "\n", "- Si Shi, Jianjun Li, Guohui Li, Peng Pan, Qi Chen & Qing Sun. 2022 . GPM: A graph convolutional network based reinforcement learning framework for portfolio management. https://doi.org/10.1016/j.neucom.2022.04.105.\n", "\n", " Note\n", "If you're using the portfolio optimization environment, consider citing the following paper in adittion to FinRL references :\n", "… 证据：`examples/FinRL_GPM_Demo.ipynb`
- **Finrl Papertrading Demo**（source_file）：{ "cells": { "cell type": "markdown", "metadata": { "id": "V1ofncK2cYhs" }, "source": "Disclaimer: Nothing herein is financial advice, and NOT a recommendation to trade real money. Many platforms exist for simulated trading paper trading which can be used for building and developing the methods discussed. Please use common sense and always first consult a professional before trading or investing." }, { "cell type": "markdown", "metadata": {}, "source": " " }, { "cell type": "markdown", "metadata": { "id": "j3mbRu3s1YlD" }, "source": " Part 1: Install FinRL" }, { "cell type": "code", "execution count": null, "metadata": { "id": "0gkmsPgbvNf6" }, "outputs": , "source": " install finrl library… 证据：`examples/FinRL_PaperTrading_Demo.ipynb`
- **Finrl Papertrading Demo Refactored**（source_file）：parser = argparse.ArgumentParser ⋮---- args = parser.parse args DATA API KEY = args.data key DATA API SECRET = args.data secret DATA API BASE URL = args.data url TRADING API KEY = args.trading key TRADING API SECRET = args.trading secret TRADING API BASE URL = args.trading url ⋮---- ticker list = DOW 30 TICKER env = StockTradingEnv ERL PARAMS = { ⋮---- today = datetime.datetime.today TEST END DATE = today - BDay 1 .to pydatetime .date TEST START DATE = TEST END DATE - BDay 1 .to pydatetime .date TRAIN END DATE = TEST START DATE - BDay 1 .to pydatetime .date TRAIN START DATE = TRAIN END DATE - BDay 5 .to pydatetime .date TRAINFULL START DATE = TRAIN START DATE TRAINFULL END DATE = TEST END D… 证据：`examples/FinRL_PaperTrading_Demo_refactored.py`
- **Finrl Portfoliooptimizationenv Demo**（source_file）：{ "cells": { "cell type": "markdown", "metadata": { "id": "3xt6fIDownZs" }, "source": " A guide Portfolio Optimization Environment\n", "\n", "This notebook aims to provide an example of using PortfolioOptimizationEnv or POE to train a reinforcement learning model that learns to solve the portfolio optimization problem.\n", "\n", "In this document, we will reproduce a famous architecture called EIIE ensemble of identical independent evaluators , introduced in the following paper:\n", "\n", "- Zhengyao Jiang, Dixing Xu, & Jinjun Liang. 2017 . A Deep Reinforcement Learning Framework for the Financial Portfolio Management Problem. https://doi.org/10.48550/arXiv.1706.10059.\n", "\n", "It's advis… 证据：`examples/FinRL_PortfolioOptimizationEnv_Demo.ipynb`
- **Finrl Stocktrading 2026 1 Data**（source_file）：aapl df yf = yf.download tickers="aapl", start="2020-01-01", end="2020-01-31" ⋮---- aapl df finrl = YahooDownloader ⋮---- df raw = YahooDownloader ⋮---- fe = FeatureEngineer processed = fe.preprocess data df raw list ticker = processed "tic" .unique .tolist list date = list combination = list itertools.product list date, list ticker processed full = pd.DataFrame combination, columns= "date", "tic" .merge processed full = processed full processed full "date" .isin processed "date" processed full = processed full.sort values "date", "tic" processed full = processed full.fillna 0 ⋮---- train = data split processed full, TRAIN START DATE, TRAIN END DATE trade = data split processed full, TRADE… 证据：`examples/FinRL_StockTrading_2026_1_data.py`
- **Finrl Stocktrading 2026 2 Train**（source_file）：train = pd.read csv "train data.csv" train = train.set index train.columns 0 ⋮---- stock dimension = len train.tic.unique state space = 1 + 2 stock dimension + len INDICATORS stock dimension ⋮---- buy cost list = sell cost list = 0.001 stock dimension num stock shares = 0 stock dimension env kwargs = { e train gym = StockTradingEnv df=train, env kwargs ⋮---- if using a2c = True if using ddpg = True if using ppo = True if using td3 = True if using sac = True agent = DRLAgent env=env train model a2c = agent.get model "a2c" ⋮---- tmp path = RESULTS DIR + "/a2c" new logger a2c = configure tmp path, "stdout", "csv", "tensorboard" ⋮---- trained a2c = ⋮---- model ddpg = agent.get model "ddpg" ⋮---… 证据：`examples/FinRL_StockTrading_2026_2_train.py`
- **%% Part 2. Load trained agents**（source_file）：train = pd.read csv "train data.csv" trade = pd.read csv "trade data.csv" train = train.set index train.columns 0 ⋮---- trade = trade.set index trade.columns 0 ⋮---- %% Part 2. Load trained agents if using a2c = True if using ddpg = True if using ppo = True if using td3 = True if using sac = True trained a2c = A2C.load TRAINED MODEL DIR + "/agent a2c" if if using a2c else None trained ddpg = DDPG.load TRAINED MODEL DIR + "/agent ddpg" if if using ddpg else None trained ppo = PPO.load TRAINED MODEL DIR + "/agent ppo" if if using ppo else None trained td3 = TD3.load TRAINED MODEL DIR + "/agent td3" if if using td3 else None trained sac = SAC.load TRAINED MODEL DIR + "/agent sac" if if using s… 证据：`examples/FinRL_StockTrading_2026_3_Backtest.py`
- **Config**（source_file）：DATA SAVE DIR = "datasets" TRAINED MODEL DIR = "trained models" TENSORBOARD LOG DIR = "tensorboard log" RESULTS DIR = "results" TRAIN START DATE = "2014-01-06" TRAIN END DATE = "2025-12-31" TEST START DATE = "2026-01-01" TEST END DATE = "2026-03-20" TRADE START DATE = "2026-01-01" TRADE END DATE = "2026-03-20" INDICATORS = A2C PARAMS = {"n steps": 5, "ent coef": 0.01, "learning rate": 0.0007} PPO PARAMS = { DDPG PARAMS = {"batch size": 128, "buffer size": 50000, "learning rate": 0.001} TD3 PARAMS = {"batch size": 100, "buffer size": 1000000, "learning rate": 0.001} SAC PARAMS = { ERL PARAMS = { RLlib PARAMS = {"lr": 5e-5, "train batch size": 500, "gamma": 0.99} TIME ZONE SHANGHAI = "Asia/Sh… 证据：`finrl/config.py`
- **Config Tickers**（source_file）：SINGLE TICKER = "AAPL" DOW 30 TICKER = NAS 100 TICKER = SP 500 TICKER = HSI 50 TICKER = SSE 50 TICKER = CSI 300 TICKER = CAC 40 TICKER = DAX 30 TICKER = TECDAX TICKER = MDAX 50 TICKER = SDAX 50 TICKER = LQ45 TICKER = SRI KEHATI TICKER = FX TICKER = TAI 0050 TICKER = 证据：`finrl/config_tickers.py`
- **Main**（source_file）：def build parser ⋮---- parser = ArgumentParser ⋮---- def check and make directories directories: list str def main - int ⋮---- parser = build parser options = parser.parse args ⋮---- env = StockTradingEnv kwargs = ⋮---- kwargs = {} account value erl = test 证据：`finrl/main.py`
- **Plot**（source_file）：def get daily return df, value col name="account value" ⋮---- df = deepcopy df ⋮---- def convert daily return to pyfolio ts df ⋮---- strategy ret = df.copy ⋮---- def backtest stats account value, value col name="account value" ⋮---- dr test = get daily return account value, value col name=value col name perf stats all = timeseries.perf stats ⋮---- df = deepcopy account value ⋮---- test returns = get daily return df, value col name=value col name baseline df = get baseline ⋮---- baseline df = pd.merge df "date" , baseline df, how="left", on="date" baseline df = baseline df.fillna method="ffill" .fillna method="bfill" baseline returns = get daily return baseline df, value col name="close" ⋮--… 证据：`finrl/plot.py`
- **Trade**（source_file）：net dim = kwargs.get "net dimension", 2 7 cwd = kwargs.get "cwd", "./" + str model name state dim = kwargs.get "state dim" action dim = kwargs.get "action dim" ⋮---- paper trading = AlpacaPaperTrading 证据：`finrl/trade.py`
- **Train**（source_file）：dp = DataProcessor data source, kwargs data = dp.download data ticker list, start date, end date, time interval data = dp.clean data data data = dp.add technical indicator data, technical indicator list ⋮---- data = dp.add vix data ⋮---- env config = { env instance = env config=env config cwd = kwargs.get "cwd", "./" + str model name ⋮---- break step = kwargs.get "break step", 1e6 erl params = kwargs.get "erl params" agent = DRLAgent erl model = agent.get model model name, model kwargs=erl params trained model = agent.train model ⋮---- total episodes = kwargs.get "total episodes", 100 rllib params = kwargs.get "rllib params" ⋮---- agent rllib = DRLAgent rllib ⋮---- trained model = agent rll… 证据：`finrl/train.py`
- **Trove classifiers**（source_file）：tool.poetry name = "finrl" version = "0.3.8" 证据：`pyproject.toml`
- **plot**（source_file）：alpaca-py alpaca trade api =2.1.0 ccxt =1.66.32 elegantrl 证据：`requirements.txt`
- **https://github.com/googleapis/python-api-common-protos/issues/23**（source_file）：flake8 count = True statistics = True max-line-length = 127 extend-exclude = .venv, .pyc ignore=F401,W503,E203 证据：`setup.cfg`
- **Setup**（source_file）：REQUIRES = list f = open "requirements.txt", "rb" ⋮---- line = line.strip ⋮---- line = line : line.find " " .strip 证据：`setup.py`
- **Build Container**（source_file）：docker build -f docker/Dockerfile -t finrl . 证据：`docker/bin/build_container.sh`
- **Start Notebook**（source_file）：docker run -it --rm -p 8887:8888 finrl 证据：`docker/bin/start_notebook.sh`
- **The full version, including alpha/beta/rc tags**（source_file）：project = "FinRL" copyright = "2021, FinRL" author = "FinRL" version = "" The full version, including alpha/beta/rc tags release = "0.3.1" extensions = autodoc mock imports = pygments style = "sphinx" templates path = " templates" source suffix = ".rst" master doc = "index" language = None exclude patterns = pygments style = None html theme = "sphinx rtd theme" html theme path = sphinx rtd theme.get html theme path html logo = "./image/logo transparent background.png" html theme options = { html static path = " static" htmlhelp basename = "FinRLdoc" latex elements = { latex documents = man pages = master doc, "finrl", "FinRL Documentation", author , 1 texinfo documents = epub title = projec… 证据：`docs/source/conf.py`
- **If you see something, say something!**（source_file）：:github url: https://github.com/AI4Finance-Foundation/FinRL 证据：`docs/source/developer_guide/contributing.rst`
- **Development Setup**（source_file）：:github url: https://github.com/AI4Finance-Foundation/FinRL 证据：`docs/source/developer_guide/development_setup.rst`
- **File Architecture**（source_file）：:github url: https://github.com/AI4Finance-Foundation/FinRL 证据：`docs/source/developer_guide/file_architecture.rst`
- **Faq**（source_file）：:github url: https://github.com/AI4Finance-LLC/FinRL-Library 证据：`docs/source/faq.rst`
- **Benchmark**（source_file）：:github url: https://github.com/AI4Finance-Foundation/FinRL 证据：`docs/source/finrl_meta/Benchmark.rst`
- **Data Layer**（source_file）：:github url: https://github.com/AI4Finance-Foundation/FinRL 证据：`docs/source/finrl_meta/Data_layer.rst`
- **Environment Layer**（source_file）：:github url: https://github.com/AI4Finance-Foundation/FinRL 证据：`docs/source/finrl_meta/Environment_layer.rst`
- **Background**（source_file）：:github url: https://github.com/AI4Finance-Foundation/FinRL 证据：`docs/source/finrl_meta/background.rst`
- **Overview**（source_file）：:github url: https://github.com/AI4Finance-Foundation/FinRL 证据：`docs/source/finrl_meta/overview.rst`
- **Index**（source_file）：.. Finrl Library documentation master file, created by sphinx-quickstart on Wed Nov 18 08:14:32 2020. You can adapt this file completely to your liking, but it should at least contain the root toctree directive. 证据：`docs/source/index.rst`
- **Publication**（source_file）：Papers by the Columbia research team can be found at Google Scholar . 证据：`docs/source/reference/publication.rst`
- **First Glance**（source_file）：:github url: https://github.com/AI4Finance-Foundation/FinRL 证据：`docs/source/start/first_glance.rst`
- **Installation**（source_file）：:github url: https://github.com/AI4Finance-Foundation/FinRL 证据：`docs/source/start/installation.rst`
- **Introduction**（source_file）：:github url: https://github.com/AI4Finance-Foundation/FinRL 证据：`docs/source/start/introduction.rst`
- **construct environment**（source_file）：:github url: https://github.com/AI4Finance-Foundation/FinRL 证据：`docs/source/start/quick_start.rst`
- **Three Layer**（source_file）：:github url: https://github.com/AI4Finance-Foundation/FinRL 证据：`docs/source/start/three_layer.rst`
- **Agents**（source_file）：:github url: https://github.com/AI4Finance-Foundation/FinRL 证据：`docs/source/start/three_layer/agents.rst`
- **Applications**（source_file）：:github url: https://github.com/AI4Finance-Foundation/FinRL 证据：`docs/source/start/three_layer/applications.rst`
- **Environments**（source_file）：:github url: https://github.com/AI4Finance-Foundation/FinRL 证据：`docs/source/start/three_layer/environments.rst`
- **1 Introduction**（source_file）：:github url: https://github.com/AI4Finance-Foundation/FinRL 证据：`docs/source/tutorial/1-Introduction.rst`
- **2 Advance**（source_file）：:github url: https://github.com/AI4Finance-Foundation/FinRL 证据：`docs/source/tutorial/2-Advance.rst`
- **3 Practical**（source_file）：:github url: https://github.com/AI4Finance-Foundation/FinRL 证据：`docs/source/tutorial/3-Practical.rst`
- 其余 14 条证据见 `AI_CONTEXT_PACK.json` 或 `EVIDENCE_INDEX.json`。

## 宿主 AI 必须遵守的规则

- **把本资产当作开工前上下文，而不是运行环境。**：AI Context Pack 只包含证据化项目理解，不包含目标项目的可执行状态。 证据：`README.md`, `examples/README.md`, `finrl/README.md`
- **回答用户时区分可预览内容与必须安装后才能验证的内容。**：安装前体验的消费者价值来自降低误装和误判，而不是伪装成真实运行。 证据：`README.md`, `examples/README.md`, `finrl/README.md`

## 用户开工前应该回答的问题

- 你准备在哪个宿主 AI 或本地环境中使用它？
- 你只是想先体验工作流，还是准备真实安装？
- 你最在意的是安装成本、输出质量、还是和现有规则的冲突？

## 验收标准

- 所有能力声明都能回指到 evidence_refs 中的文件路径。
- AI_CONTEXT_PACK.md 没有把预览包装成真实运行。
- 用户能在 3 分钟内看懂适合谁、能做什么、如何开始和风险边界。

---

## Doramagic Context Augmentation

下面内容用于强化 Repomix/AI Context Pack 主体。Human Manual 只提供阅读骨架；踩坑日志会被转成宿主 AI 必须遵守的工作约束。

## Human Manual 骨架

使用规则：这里只是项目阅读路线和显著性信号，不是事实权威。具体事实仍必须回到 repo evidence / Claim Graph。

宿主 AI 硬性规则：
- 不得把页标题、章节顺序、摘要或 importance 当作项目事实证据。
- 解释 Human Manual 骨架时，必须明确说它只是阅读路线/显著性信号。
- 能力、安装、兼容性、运行状态和风险判断必须引用 repo evidence、source path 或 Claim Graph。

- **Project Overview and Three-Layer Architecture**：importance `high`
  - source_paths: README.md, finrl/main.py, finrl/train.py, finrl/test.py, finrl/trade.py
- **Market Environments: Stock, Crypto, Portfolio, and HFT Gyms**：importance `high`
  - source_paths: finrl/meta/env_stock_trading/env_stocktrading.py, finrl/meta/env_stock_trading/env_stocktrading_cashpenalty.py, finrl/meta/env_stock_trading/env_stocktrading_stoploss.py, finrl/meta/env_stock_trading/env_stocktrading_np.py, finrl/meta/env_stock_trading/env_stock_papertrading.py
- **DRL Agent Integrations: Stable Baselines 3, ElegantRL, RLlib, and Portfolio Agents**：importance `high`
  - source_paths: finrl/agents/stablebaselines3/models.py, finrl/agents/stablebaselines3/hyperparams_opt.py, finrl/agents/stablebaselines3/tune_sb3.py, finrl/agents/elegantrl/models.py, finrl/agents/rllib/models.py
- **Data Sources, Tutorials, Paper Trading, and Common Failures**：importance `high`
  - source_paths: finrl/meta/data_processor.py, finrl/meta/data_processors/processor_alpaca.py, finrl/meta/data_processors/processor_ccxt.py, finrl/meta/data_processors/processor_eodhd.py, finrl/meta/data_processors/processor_joinquant.py

## Repo Inspection Evidence / 源码检查证据

- repo_clone_verified: true
- repo_inspection_verified: true
- repo_commit: `220f9e490996a6e5c84cfad914ff14f2e0c42d22`
- inspected_files: `README.md`, `pyproject.toml`, `requirements.txt`, `docs/.readthdocs.yaml`, `docs/source/conf.py`, `docs/source/reference/publication.md`, `docs/source/reference/reference.md`, `examples/FinRL_PaperTrading_Demo_refactored.py`, `examples/FinRL_StockTrading_2026_1_data.py`, `examples/FinRL_StockTrading_2026_2_train.py`, `examples/FinRL_StockTrading_2026_3_Backtest.py`, `examples/README.md`

宿主 AI 硬性规则：
- 没有 repo_clone_verified=true 时，不得声称已经读过源码。
- 没有 repo_inspection_verified=true 时，不得把 README/docs/package 文件判断写成事实。
- 没有 quick_start_verified=true 时，不得声称 Quick Start 已跑通。

## Doramagic Pitfall Constraints / 踩坑约束

这些规则来自 Doramagic 发现、验证或编译过程中的项目专属坑点。宿主 AI 必须把它们当作工作约束，而不是普通说明文字。

### Constraint 1: 来源证据：DDPG / off-policy algorithms fail due to rollout_buffer logging in FinRL 0.3.8

- Trigger: GitHub 社区证据显示该项目存在一个运行相关的待验证问题：DDPG / off-policy algorithms fail due to rollout_buffer logging in FinRL 0.3.8
- Why it matters: 可能增加新用户试用和生产接入成本。
- Evidence: community_evidence:github | https://github.com/AI4Finance-Foundation/FinRL/issues/1395 | 来源类型 github_issue 暴露的待验证使用条件。
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

### Constraint 2: 来源证据：paper_trading/alpaca.py: submitOrder response list never read after thread joins

- Trigger: GitHub 社区证据显示该项目存在一个运行相关的待验证问题：paper_trading/alpaca.py: submitOrder response list never read after thread joins
- Why it matters: 可能增加新用户试用和生产接入成本。
- Evidence: community_evidence:github | https://github.com/AI4Finance-Foundation/FinRL/issues/1414 | 来源讨论提到 python 相关条件，需在安装/试用前复核。
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

### Constraint 3: 来源证据：Add pre-trade market state verification to StockTradingEnv

- Trigger: GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：Add pre-trade market state verification to StockTradingEnv
- Why it matters: 可能影响授权、密钥配置或安全边界。
- Evidence: community_evidence:github | https://github.com/AI4Finance-Foundation/FinRL/issues/1412 | 来源讨论提到 python 相关条件，需在安装/试用前复核。
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

### Constraint 4: 来源证据：AttributeError when running "python main.py --mode=train" command

- Trigger: GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：AttributeError when running "python main.py --mode=train" command
- Why it matters: 可能影响授权、密钥配置或安全边界。
- Evidence: community_evidence:github | https://github.com/AI4Finance-Foundation/FinRL/issues/671 | 来源讨论提到 python 相关条件，需在安装/试用前复核。
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

### Constraint 5: 来源证据：Google colab Stock_NeurIPS2018_SB3.ipynb StockTradingEnv.reset() got an unexpected keyword argument 'seed'

- Trigger: GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：Google colab Stock_NeurIPS2018_SB3.ipynb StockTradingEnv.reset() got an unexpected keyword argument 'seed'
- Why it matters: 可能影响授权、密钥配置或安全边界。
- Evidence: community_evidence:github | https://github.com/AI4Finance-Foundation/FinRL/issues/1013 | 来源讨论提到 python 相关条件，需在安装/试用前复核。
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

### Constraint 6: 涉及密钥、隐私或敏感领域

- Trigger: 项目文本出现 secret/private key/privacy/trading/finance 等敏感关键词。
- Host AI rule: 补敏感数据流、密钥存储和权限边界审查。
- Why it matters: 金融、交易、隐私和密钥场景必须比普通工具更保守。
- Evidence: packet_text.keyword_scan | https://github.com/AI4Finance-Foundation/FinRL | matched secret / private key / privacy / trading / finance keyword
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

### Constraint 7: 能力判断依赖假设

- Trigger: README/documentation is current enough for a first validation pass.
- Host AI rule: 将假设转成下游验证清单。
- Why it matters: 假设不成立时，用户拿不到承诺的能力。
- Evidence: capability.assumptions | https://github.com/AI4Finance-Foundation/FinRL | README/documentation is current enough for a first validation pass.
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

### Constraint 8: 维护活跃度未知

- Trigger: 未记录 last_activity_observed。
- Host AI rule: 补 GitHub 最近 commit、release、issue/PR 响应信号。
- Why it matters: 新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。
- Evidence: evidence.maintainer_signals | https://github.com/AI4Finance-Foundation/FinRL | last_activity_observed missing
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

- Trigger: no_demo
- Evidence: downstream_validation.risk_items | https://github.com/AI4Finance-Foundation/FinRL | no_demo; severity=medium
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

### Constraint 10: 存在评分风险

- Trigger: no_demo
- Why it matters: 风险会影响是否适合普通用户安装。
- Evidence: risks.scoring_risks | https://github.com/AI4Finance-Foundation/FinRL | no_demo; severity=medium
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。
