Risk-Aware Trading Agents风险感知交易智能体

AI trading agents that check the macro calendar and the fear index before they buy先看宏观日历和恐慌指数,再决定买不买的 AI 交易智能体

An open-source, long-only system for US stocks. It buys pullbacks to EMA 50/100/200 and quality dips that pass an earnings check, follows trends when the market is healthy, holds instead of panic-selling when it is not, and always keeps 30% in cash or T-bills. Backtest it, paper trade it, then connect one of 10 brokers.开源的美股做多系统。回踩 EMA 50/100/200 时买入,财报过关的好公司大跌时抄底;行情好时顺势持有,行情不明朗时只持有、不恐慌卖出;现金加短期国债始终不低于 30%。先回测,再模拟盘,然后接入 10 家券商中的任意一家。

FOMC · CPI · NFPVIX · VIX3MFear & Greed EMA 50/100/200Finviz + RSSBacktesting Paper tradingBull / bear LLM debateMIT

What it does它能做什么

Every agent writes down why it said yes or no, so each trade comes with its reasons.每个智能体都会写下赞成或反对的理由,所以每笔交易都能看到依据。

Macro-aware regimes看宏观的市场状态

VIX and its term structure, sector breadth, credit appetite, a fear-and-greed gauge and the FOMC, CPI and jobs-report calendar decide one of four regimes.根据 VIX 及其期限结构、板块广度、信用利差、恐慌贪婪指数,以及 FOMC、CPI、非农日历,把市场分成四种状态。

Buy low, sell high低买高卖

Pullbacks to EMA 50/100/200, RSI(2) mean reversion, quality dips after an earnings check, breakouts in strong markets; trims winners when they are stretched.回踩 EMA 50/100/200、RSI(2) 均值回归、财报过关后抄底、强势行情做突破;涨得太远时减仓止盈。

Risk first风控优先

30% cash + T-bill floor, position, sector and speculative caps, volatility-scaled sizes, buying in tranches, Treasury sleeve, drawdown pause, kill switch.现金加短债 30% 底线,单票、板块、高波动仓位上限,按波动率定仓位,分批建仓,国债仓位,回撤暂停,一键停止。

No panic selling不恐慌卖出

In uncertain or risk-off markets the agent holds and only buys at strong support. Only confirmed disasters (fraud, bankruptcy) can force an exit.不确定或避险时只持有,只在强支撑位买入。只有经过确认的重大利空(造假、破产)才会强制卖出。

Cross-verified news交叉验证新闻

Finviz, Google News, Nasdaq, Seeking Alpha, Yahoo and SEC 8-K filings. A story counts only when two independent publishers or an SEC filing carry it, so one fake headline cannot move the agent.汇总 Finviz、Google News、Nasdaq、Seeking Alpha、Yahoo 和 SEC 8-K。只有两家独立媒体或 SEC 文件都报道才算确认,一条假新闻带不动它。

Your own strategies写你自己的策略

Write one Python method, then backtest, compare and paper trade it with the same risk engine. Optional bull / bear / judge LLM review with hard bounds.只要写一个 Python 方法,就能用同一套风控去回测、对比和模拟盘交易。可选的 LLM 多空辩论复核,影响有硬性上限。

How it works工作原理

The same objects run in backtests, paper trading and live trading.回测、模拟盘和实盘用的是同一套代码。

Data数据Yahoo · Finviz · RSS · Fed · BLS
→
Agents智能体macro · events · technical · earnings · news宏观 · 事件 · 技术 · 财报 · 新闻
→
Strategy策略built-in or yours内置或自定义
→
Risk manager风控floor · caps · regime rules底线 · 上限 · 状态规则
→
Safety guards安全开关paper by default默认模拟盘
→
Broker券商10 adapters

What the agent does in each regime不同市场状态下的做法

Regime状态Typical trigger典型触发条件Buys买入Sells卖出Size仓位
RISK-ONSPY above a rising EMA50 and EMA200, VIX < 20, most sectors above EMA200SPY 在上行的 EMA50 和 EMA200 之上,VIX < 20,多数板块站上 EMA200pullbacks, breakouts, dips回调、突破、抄底take profit, trend exits止盈、趋势破位减仓100%
NEUTRALnone of the others其余情况EMA support, mean reversion, quality dipsEMA 支撑、均值回归、优质股抄底take profit止盈75%
UNCERTAINFOMC / CPI / jobs-report window, VIX 20–30, fear gauge < 35, downtrendFOMC、CPI、非农前后,VIX 20–30,恐慌指数 < 35,下跌趋势EMA100 / EMA200 support only只在 EMA100 / EMA200 支撑买none (hold)不卖(持有)50%
RISK-OFFVIX ≥ 30, VIX backwardation below EMA200, credit stressVIX ≥ 30,跌破 EMA200 且 VIX 期限倒挂,信用紧张quality dips, broad ETFs, small tranches只抄优质股和宽基 ETF,小批量none (hold)不卖(持有)35%

Backtest, 2018 – 2026回测:2018 – 2026

Built-in strategy, balanced profile, 55 large caps, $100k, signals at the close and fills the next day. Shading shows the regime.内置策略、平衡档、55 只大盘股、10 万美元,收盘出信号、次日成交。底色表示市场状态。

Equity curve of the risk-aware strategy versus SPY 风险感知策略与 SPY 的净值曲线
risk_awareSPY buy & hold
CAGR年化收益10.4%14.1%
Volatility波动率9.3%19.0%
Sharpe夏普比率0.840.66
Max drawdown最大回撤-18.2%-33.7%
Worst calendar year最差年份-3.7%-18.2%
Average stocks / cash + T-bills平均股票 / 现金加短债57% / 39%100% / 0%

Read this honestly: it earns less than the index in a long bull market and loses about half as much in the bad stretches. The list is today's large caps (survivorship bias), news and fundamentals are not used in backtests, and past results do not predict future ones. Reproduce it with riskaware backtest --compare buy_and_hold.要客观地看:在长牛市里它赚得比指数少,跌的时候亏得大约只有指数的一半。股票池是今天的大盘股(有幸存者偏差),回测没有用新闻和财报数据,过去的表现也不代表未来。用 riskaware backtest --compare buy_and_hold 可以自己复现。

Quick start快速开始

Python 3.10+. No account or API key needed for the first four commands.需要 Python 3.10+。前四条命令不需要券商账户或 API key。

git clone https://github.com/jackson-cmd/risk-aware-trading-agents
cd risk-aware-trading-agents
pip install -e ".[dashboard]"

riskaware init                 # 2-minute wizard / 两分钟配置向导
riskaware regime               # market regime, VIX, fear & greed, FOMC countdown
riskaware scan                 # today's signals with reasons
riskaware backtest --compare buy_and_hold,ema_bounce
riskaware run                  # paper trading (built-in paper account)
riskaware dashboard            # web UI, English / 中文

Bring your own strategy写你自己的策略

from riskaware.strategy import Strategy, Signal, Action

class Rsi2Dip(Strategy):
    name = "rsi2_dip"
    def on_bar(self, ctx):
        out = []
        for sym in ctx.universe:
            row = ctx.row(sym)
            if row and row["close"] > row["ema200"] and row["rsi2"] < 10:
                out.append(Signal(sym, Action.BUY, strength=0.7, reason="RSI2 dip"))
        return out

# riskaware backtest --strategy my_strategy.py --compare risk_aware

Brokers支持的券商

Paper trading is the default. Live orders need three explicit switches.默认是模拟盘。实盘下单需要同时打开三个开关。

Built-in paperno account needed无需账户
Alpacapaper (tested) + live模拟盘已实测 + 实盘
Interactive BrokersTWS / IB Gateway
Public.comlive only仅实盘
Charles SchwabTrader API
tastytradesandbox + live沙盒 + 实盘
Tradiersandbox + live沙盒 + 实盘
Futu / moomoosimulate + real (OpenD)富途牛牛 模拟 + 实盘
Tiger Brokerspaper + live老虎证券 模拟 + 实盘
Longbridgepaper + live长桥 模拟 + 实盘

FAQ

Will it place real trades by itself?它会自己下实盘单吗?

No. It starts in paper mode. A live order needs execution.mode: live in the config, the --live flag and a confirmation (or --yes). riskaware halt stops all orders.不会。默认是模拟盘。实盘需要配置文件里写 execution.mode: live、命令加 --live,并手动确认(或加 --yes)。riskaware halt 可以一键停止所有下单。

Do I need paid data?需要付费数据吗?

No. Prices come from Yahoo Finance, news from Finviz and public RSS feeds, calendars from the Federal Reserve, BLS and BEA. You can also load your own CSV files.不需要。价格来自 Yahoo Finance,新闻来自 Finviz 和公开 RSS,宏观日历来自美联储、BLS 和 BEA。也可以导入自己的 CSV 数据。

Why not sell when the market is scary?市场吓人的时候为什么不卖?

Panic selling at the bottom is how long-term investors lose most. Losses are bounded up front by diversification, position caps and the cash floor; the agent uses fear to buy quality at support instead.长期投资者最大的损失,往往来自在底部恐慌卖出。这个系统事先用分散持仓、仓位上限和现金底线控制住亏损,市场恐慌时反而在支撑位买入优质股。

Is this investment advice?这是投资建议吗?

No. It is software for research and education. Markets are risky; trade at your own risk.不是。这是用于研究和学习的软件。市场有风险,交易后果自负。