Open-Source P123 Skill for AI Coding Agents (Claude Code, Cursor, Codex)

Hi everyone,

I've built an open-source Agent Skill that teaches AI coding agents (Claude Code, Cursor, Codex, Gemini CLI) how to write correct P123 formulas, ranking systems, screen rules, and API calls.

The problem it solves

If you've tried asking ChatGPT, Claude, or any LLM to write P123 formulas, you've probably noticed they hallucinate function names constantly. They'll write LTDebt() instead of DbtLT(), High() instead of Hi(), OpCashFl() instead of OperCashFl(), MACDHist() instead of MACDD(), and so on. The P123 formula language has its own conventions and the models simply don't know them.

This skill fixes that. I cross-referenced every function name and parameter against the official 528-page P123 Syntax Reference and the Factor Browser (all 464 functions and 4,456 factors) to make sure everything is accurate.

What's included

  • Complete formula language reference (syntax, operators, SetVar, Eval, FRank, ZScore, FHist, Loop, Regression)
  • All fundamental data functions (balance sheet, income statement, cash flow) with correct P123 names
  • Technical analysis functions (OHLCV, moving averages, MACD, RSI, volatility, trend indicators)
  • Full p123api Python wrapper documentation with code examples for every endpoint
  • FRED macro constants, universe IDs, FX rates, S&P 500 aggregates
  • Common factor investing patterns (value, momentum, quality, low-vol, BAB, Piotroski)
  • A mapping table of 30+ common hallucination mistakes and their correct P123 equivalents

Around 2,900 lines of verified reference material across 7 files.

How to install

It follows the open Agent Skills standard. For Claude Code:

git clone https://github.com/cmoralesm/P123-Claude-Skill.git cp -r P123-Claude-Skill ~/.claude/skills/portfolio123/

For Cursor, same idea but into ~/.cursor/skills/. Details in the README.

GitHub repo: GitHub - cmoralesm/P123-Claude-Skill: Agent Skill for Portfolio123 (P123): 464 functions, 4456 factors, verified line-by-line against official docs. Factor investing, screening, ranking systems, backtesting, and p123api Python wrapper. Works with Claude Code, Cursor, and Codex. · GitHub

Looking for collaborators

I'd like to keep improving this skill and expand it further. If you're a P123 power user who also works with Claude Code or Cursor and you'd be interested in contributing to the project, send me a private message. Would love to work together on this.

Feedback, bug reports, and pull requests are all welcome. Hope this is useful to the community!

13 Likes

Great stuff, thank you!

I’ll drop you a line re a few other bits that might be helpful.

To save anyone else interested in this the work - security review (AI only!) looks all OK:
“Scan for prompt-injection and exfiltration-style language: I did not find explicit prompt injection, jailbreak instructions, attempts to override system/developer rules, requests to reveal secrets, or embedded credentials.”

3 Likes

FYI I was using the skill and Claude suggested this correction

The correction needed is on line 162, changing:

| `HiValue(bars [, offset, series])` | Highest value over N bars |

to:

| `HighVal(bars [, offset, series])` | Highest value over N bars |

And line 163:

| `LoValue(bars [, offset, series])` | Lowest value over N bars |

EDIT: Not sure but I think should be minvalue instead of LoValue.