Joinquant Strategy logo

Joinquant Strategy

Organization
lzwme
joinquant-strategy

聚宽(JoinQuant)官网策略开发指南,涵盖回测、模拟交易、数据 API、交易函数、因子与技术指标。当用户编写聚宽策略、回测、模拟盘、查询聚宽 API、get_price/order/run_daily、Alpha 因子、技术指标,或提及 joinquant、聚宽、jqdata 策略时使用。本地数据获取请用 jqdatasdk 技能。

Overview

Publisherlzwme
Repositoryfinance-quant-skills
Skill namejoinquant-strategy
Stars
461
Forks
85
Bundled files
19
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 19 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by lzwme on GitHub. Read the source before you install it.

Installation

Install the Joinquant Strategy AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/lzwme/finance-quant-skills/tree/main/skills/joinquant-strategy
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/lzwme/finance-quant-skills.git /tmp/finance-quant-skills
mkdir -p .claude/skills
cp -r /tmp/finance-quant-skills/skills/joinquant-strategy .claude/skills/joinquant-strategy
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Joinquant Strategy in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Joinquant Strategy on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Joinquant Strategy is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

聚宽策略开发

基于本目录离线文档,为聚宽官网(回测 / 模拟 / 研究)编写 Python 策略。回答 API 问题时必须先查阅本地文档,不得凭记忆编造函数签名或参数。

与 jqdatasdk 的区别:jqdata 在官网策略环境使用;jqdatasdk 是本地 Python 库,API 略有不同,且不能在官网回测/模拟/研究中使用。

文档查阅流程

  1. 确定问题类型,按 reference.md 定位文件
  2. 用 Grep/Read 搜索目标函数名或中文关键词(如 get_price、order_target、市盈率)
  3. 交叉验证:API 行为查 api.md,字段/表结构查 data/*.md,踩坑查 faq.md
  4. 给出答案时引用文档中的调用方法、参数、返回值与示例代码
需要写策略框架?     → api.md「开始写策略」「策略程序架构」
需要查数据 API?      → api.md「数据获取函数」+ data/ 对应品种文档
需要下单/持仓?      → api.md「交易函数」「对象」
需要财务/估值数据?  → data/Stock.md(run_query + valuation/fundamentals 表)
需要行业/概念选股?  → data/plateData.md + api.md get_industry_stocks 等
需要技术指标?       → data/technicalanalysis.md(from jqlib.technical_analysis import *)
需要 Alpha 因子?    → data/Alpha101.md、data/Alpha191.md
需要自定义因子?     → fator.md(jqfactor.Factor、calc_factors)
需要因子看板数据?   → data/factor_values.md

策略骨架

最小可运行结构:

python
# 导入聚宽函数库
import jqdata

def initialize(context):
    g.security = '000001.XSHE'
    set_benchmark('000300.XSHG')
    set_option('use_real_price', True)  # 开启动态复权(真实价格),建议开启
    run_daily(trade, time='open')       # 或 time='every_bar' / '9:30'

def trade(context):
    security = g.security
    close_data = attribute_history(security, 5, '1d', ['close'])
    MA5 = close_data['close'].mean()
    current_price = close_data['close'][-1]
    cash = context.portfolio.available_cash

    if current_price > 1.01 * MA5:
        order_value(security, cash)
    elif current_price < MA5 and context.portfolio.positions[security].closeable_amount > 0:
        order_target(security, 0)

生命周期函数

函数说明
initialize(context)全局初始化,仅运行一次;用 g 存全局变量
run_daily/weekly/monthly(func, ...)定时任务;func 必须是全局函数,不能是类方法
handle_data(context, data)按回测频率驱动;不建议与 run_daily 混用
before_trading_start开盘前(9:00)
after_trading_end收盘后(15:30)

带 ♠ 标识的 API 仅支持回测/模拟,不能在研究模块调用。jqdata 模块在研究与回测环境均可使用。

证券代码规范

市场后缀示例
上海证券交易所.XSHG600519.XSHG
深圳证券交易所.XSHE000001.XSHE
中金所.CCFXIC9999.CCFX
大商所.XDCEA9999.XDCE
上期所.XSGEAU9999.XSGE
郑商所.XZCECY8888.XZCE
场外基金.OF519671.OF

期货策略需将 run_daily 的 reference_security 设为对应主力合约(如 IF9999.CCFX),以匹配夜盘开盘时间。

常用 API 速查

行情与历史

python
get_price(security, start_date, end_date, frequency='daily', fields=None, fq='pre')
attribute_history(security, count, unit, fields)  # 回测环境,不含当天
history(count, unit, field, security_list, df=True)
get_bars(security, count, unit, fields, include_now=True)

标的池与板块

python
get_all_securities(types=['stock'], date=None)   # date 防未来函数
get_index_stocks('000300.XSHG', date=None)
get_industry_stocks('C15', date=None)
get_concept_stocks('GN036', date=None)
set_universe([...])  # 设置后 history 可不传 security_list

财务数据(SQL 查询)

python
from jqdata import *
q = query(valuation).filter(valuation.code == '000001.XSHE')
df = get_fundamentals(q, date='2015-10-15')

# 或 run_query(单次最多 4000 行,不可连表)
df = finance.run_query(query(finance.STK_XXX).filter(...).limit(4000))

交易

python
order(security, amount)              # 按股数,正买负卖
order_value(security, value)       # 按金额
order_target(security, amount)       # 调到目标股数
order_target_value(security, value)  # 调到目标市值
order_target_percent(security, percent)  # 调到目标仓位比例

A 股买入数量须为 100 整数倍(科创板 200 起);卖光持仓时不受限。每日最多 10000 笔订单。

技术指标

python
from jqlib.technical_analysis import *
# check_date 策略中建议用 context.current_dt,避免盘中取当日收盘指标产生未来数据
result = MACD(security_list, check_date=context.current_dt, SHORT=12, LONG=26, MID=9)

自定义因子

python
from jqfactor import Factor, calc_factors

class MyFactor(Factor):
    name = 'my_factor'
    max_window = 5
    dependencies = ['close']
    def calc(self, data):
        return data['close'].mean()

factors = calc_factors(securities, [MyFactor()], start_date, end_date)

详见 fator.md 与 data/Alpha101.md、data/Alpha191.md。

关键注意事项

防止未来函数

  • get_all_securities(date=...)、get_index_stocks(..., date=...) 等必须传入历史时点的 date,不能用未来日期
  • history / attribute_history 取天数据时不包含当天;要当天数据需取分钟级
  • 技术指标 check_date 只精确到日期时返回收盘值,盘中调用当天会产生未来数据
  • 财务数据默认按公告日期处理,注意 get_fundamentals 的 date 参数含义

运行频率

  • 优先使用 run_daily,避免与 handle_data 混用
  • run_daily(func, time='every_bar') 频率与回测设置一致
  • run_weekly/monthly 的 force=False 可避免晚注册时的就近执行

数据查询限制

  • run_query / get_fundamentals 单次最多返回 4000 行
  • run_query 不支持连表查询
  • 默认行情为前复权;fq=None 为不复权

环境与产品区分

产品使用场景
jqdata(官网)回测、模拟、研究
jqdatasdk(本地)本地量化研究,不能在官网策略中 import

按场景选文档

场景首先阅读深入查阅
新手写第一个策略api.md「开始写策略」api.md「策略程序架构」
股票选股 + 财务data/Stock.mdapi.md get_fundamentals
指数成分股策略data/index.mdapi.md get_index_stocks
行业/概念轮动data/plateData.mdapi.md get_industry_stocks
期货策略data/Future.mdapi.md「期货策略专用函数」
期权策略data/Option.mdapi.md 期权相关
基金/ETFdata/fund.mddata/OTCfund.md
可转债data/bond.md—
宏观数据data/macroData.md—
技术分析指标data/technicalanalysis.md—
因子选股fator.md + data/factor_values.mddata/Alpha101.md
融资融券data/Stock.md 融资融券章节api.md 融资融券专用函数
报错/数据疑问faq.mdapi.md「注意事项」

策略示例

完整示例见 api.md 末尾「策略示例」:均线策略、多股票持仓、追涨策略、万圣节效应等。

文档更新

本地数据字典由脚本从官网同步:

bash
bun scripts/get-joinquant-docs.ts
# 强制覆盖已有 md:FORCE_UPDATE=1 bun scripts/get-joinquant-docs.ts

附加资源

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Joinquant Strategy AI skill do?

聚宽(JoinQuant)官网策略开发指南,涵盖回测、模拟交易、数据 API、交易函数、因子与技术指标。当用户编写聚宽策略、回测、模拟盘、查询聚宽 API、get_price/order/run_daily、Alpha 因子、技术指标,或提及 joinquant、聚宽、jqdata 策略时使用。本地数据获取请用 jqdatasdk 技能。

Why use Joinquant Strategy on TypingMind?

Because you install it once and use it with any model. Joinquant Strategy is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Joinquant Strategy in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/lzwme/finance-quant-skills/tree/main/skills/joinquant-strategy. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Joinquant Strategy?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Joinquant Strategy?

As many as you like. As long as a model supports skills, you can use Joinquant Strategy with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Joinquant Strategy AI skill free?

It is published on GitHub by lzwme. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇