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.
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!