Skip to content
··閱讀時間2分鐘

S&P500 Agent MVP Launch咗:用SEC數據回答金融問題

我整咗一個AI agent用10年SEC數據回答金融問題——終於解決咗我嘅streaming挑戰,令佢real-time同可驗證。

更新(2026年): S&P 500 Agent已經retired。呢篇文為歷史紀錄記載原始MVP launch。Sydney而家專注於blog內容同Chandler嘅產品。試而家嘅Sydney →


Hi there,

我好開心同大家分享,自從我上一篇關於做S&P500 Agent嘅掙扎之後,MVP version準備好喇!:D 等我walk you through呢個minimum viable product可以做乜同佢點嚟。

呢個MVP可以做乜?

  1. 深入十年數據:Agent嘅database包含過去10年公司提交俾SEC EDGAR嘅facts。Pretty neat, right?
  2. 可靠嘅答案:因為佢grounded用實際提交俾SEC嘅facts,你可以trust答案嘅質素。
  3. 方便Fact-Check:Agent喺最終答案度永遠包含reference data。所以如果你feel skeptical,你可以自己check!
  4. Handle到Tricky Questions:佢可以tackle semi-complex queries好似「Compare the revenue of Apple and Microsoft between 2020 - 2022?」或者「How did Microsoft's operating margin change from 2020 to 2022?」點解呢啲係semi-complex?因為agent需要「reason」同break down呢啲broad questions成更細嘅,由database搵資料,然後piece it all together。
    • 例如,要回答第一個問題,agent需要知道每間公司2020、2021同2022年嘅individual revenue然後做comparison。
  5. 接近最新:Cut-off date係2024年8月。之後提交俾SEC嘅嘢唔喺呢個MVP version入面。
  6. HTML streaming:Streaming work喇!Yay!:D 原來DRF同React natively support streaming,所以配合langgraph,我哋有responsive嘅conversation flow,以易讀嘅format顯示。我struggle with html streaming咗好耐。

睇吓引擎蓋下面

如果你睇到呢度,你probably想知多啲我點build呢個MVP同overcome我之前提到嘅一啲challenges。咁我哋get a bit technical!

  1. 瘦身咗嘅Data:唔用完整嘅10-K或10-Q reports,我用提交俾SEC嘅「Facts」。呢意味住我哋嘅database significantly smaller——不到2GB!以下係上市公司提交俾SEC嘅一啲examples:
  "AccruedRoyaltiesCurrent": \{
    "label": "Accrued Royalties, Current"
  \},
  "AccumulatedDepreciationDepletionAndAmortizationPropertyPlantAndEquipment": \{
    "label": "Accumulated Depreciation, Depletion and Amortization, Property, Plant, and Equipment"
  \},
  "AccumulatedOtherComprehensiveIncomeLossNetOfTax": \{
    "label": "Accumulated Other Comprehensive Income (Loss), Net of Tax"
  \},
  "AccumulatedOtherComprehensiveIncomeLossOtherThanTemporaryImpairmentNotCreditLossNetOfTaxAvailableforsaleDebtSecurities": \{
    "label": "Accumulated Other Comprehensive Income (Loss), Other than Temporary Impairment, Not Credit Loss, Net of Tax, Available-for-sale, Debt Securities"
  \},
  "AdditionalPaidInCapitalCommonStock": {
    "label": "Additional Paid in Capital, Common Stock"

呢個亦意味住我唔需要用大規模、快速嘅vector store,嗰啲好貴($600-$700/月嘅range)

2. Cloud SQL postgreSQL作為main database:我用緊Cloud SQL PostgreSQL作為main database。因為我已經用緊GCP嘅Cloud Run CI/CD,stick with Google嘅offerings make sense。呢個對我嚟講係brand new concept,所以我要學database migration由local到cloud,然後點configure backend同Cloud SQL database用private IP work。GCP嘅documentation好helpful。

3. React配Django:呢個係我第一次成功deploy React frontend同Django Rest Framework(DRF)backend加Cloud SQL database。呢段旅程充滿trial and error,但ChatGPT嘅o1-preview同Anthropic Claude 3.5 Sonnet幫到好大忙。佢哋indeed非常powerful,特別係當你俾佢enough context of the problem you are solving。

4. Smart Agent:Agent用Langgraph建成。佢有兩個main tools:Google Search同Financial Question Answering tool。佢根據你嘅問題決定用邊個。

5. SQL queries係點generate嘅?

將generic/broad user question轉換成適合database嘅SQL queries唔係straight forward嘅。主要原因之一係公司向SEC提交financial facts時,佢哋用嘅financial concepts/terminologies對普通人嚟講唔intuitive。

例如,「revenue」可以由多個facts represent:

  • Revenue
  • Revenue from Contract with Customer, Excluding Assessed Tax
  • Revenue from related Parties
  • Deferred Revenue
  • 等等...

而唔同公司可以為同一個concept用唔同labels。例如,Apple用「Revenue from Contract with Customer, Excluding Assessed Tax」vs Tesla用「Revenue」。

或者當你問「operating margin」,嗰個可能唔係公司提交俾SEC嘅fact。相反,佢哋submit total revenue同Operating Income (Loss)。

另一個情況係公司隨時間改名,所以你要確保SQL queries包括舊名同新名。

咁我點instruct機器為particular broad question選啱嘅fact/label?

我用Weaviate嘅hybrid search搵最relevant嘅facts或labels,然後send返俾LLM model。

6. Break Down Testing係關鍵

Final deployment到production之前,我將過程break down成步驟同逐個test:

1. DRF backend嘅local test加local database。

2. Docker container backend test加local database。

3. 將PostgreSQL database migrate到Cloud SQL同test。

4. Docker container backend test加Cloud SQL。

5. React front end local test。

6. React front end加production backend同Cloud SQL。

7. React front end migrate到Wordpress in production。

8. End-to-end testing。

我係hard way學到呢個step-by-step approach。一開始我skip咗一啲steps同以bigger chunks test,但language models(LLM)冇辦法pinpoint exactly邊度出問題。

下一步?

  1. Fix cold start problem:而家agent回答第一個問題需要啲時間。我做緊cost-effective嘅solution。
  2. Show interim steps俾用戶:回答complex questions好似「Compare the revenue of Apple and Microsoft between 2020 and 2022」時,agent generate最終答案需要時間。Real-time show agent正在work through嘅steps可能improve user experience。
  3. Enrich 10-K/10-Q text content:我plan include更多相關嘅10-K同10-Q filings嘅textual content嚟提供更detailed嘅answers。

暫時就係咁。試吓MVP version同話我知你點睇!你有冇試過用financial data或SEC filings build嘢?我好想聽你嘅experience——喺下面留言或者直接email我(chandler@chandlernguyen.com)。

祝好,

Chandler

繼續閱讀

我嘅旅程
聯繫
語言
偏好設定