0Pricing
AI Prompt Engineering · บทเรียน

พรอมต์ด้านการเงินและเชิงปริมาณ

การวิเคราะห์ผลประกอบการ การให้คะแนนความเสี่ยง และพรอมต์ดึงข้อมูลจากเอกสารยื่น SEC

พรอมต์ด้านการเงินและเชิงปริมาณ เป็นบทเรียน AI Prompt Engineering ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน AI Prompt Engineering และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส AI Prompt Engineering มีบทเรียนทั้งหมด 4 บทเรียน

บริบทการเขียนพรอมต์ด้านการเงิน

การเขียนพรอมต์ในขอบเขตการเงินดึงข้อมูลแบบมีโครงสร้างจากเอกสารที่ไม่มีโครงสร้าง เช่น รายงานผลประกอบการ เอกสารที่ยื่นต่อ SEC และบันทึกของนักวิเคราะห์ ความแม่นยำมีความสำคัญ เพราะการอ่านตัวเลขรายได้ผิดหรือกลับทิศทางการเติบโตอาจทำให้เกิดข้อผิดพลาดร้ายแรงในขั้นตอนต่อ ๆ ไป

พรอมต์ดึงข้อมูลจากรายงานผลประกอบการ

รายงานผลประกอบการมีโครงสร้างกึ่งมาตรฐาน พรอมต์ดึงข้อมูลแบบเจาะจงช่วยดึงตัวชี้วัดทางการเงินที่สำคัญได้อย่างแม่นยำ โดยรองรับทั้งรูปแบบ GAAP และรูปแบบที่ไม่ใช่ GAAP

EARNINGS_EXTRACTION_PROMPT = '''Extract the following financial metrics from the earnings report below.
Return ONLY a JSON object with these exact keys.
If a value is not stated, use null.
Do not calculate or derive values — only extract explicitly stated figures.

Required fields:
- revenue_usd_millions: total net revenue (GAAP)
- revenue_yoy_pct: year-over-year revenue growth percentage
- gross_margin_pct: gross margin percentage (GAAP)
- operating_income_usd_millions: GAAP operating income/loss
- ebitda_usd_millions: Adjusted EBITDA (non-GAAP, if reported)
- net_income_usd_millions: GAAP net income/loss
- eps_diluted: diluted EPS (GAAP)
- eps_adj_diluted: adjusted diluted EPS (non-GAAP, if reported)
- guidance_next_quarter_revenue_low: low end of next quarter revenue guidance
- guidance_next_quarter_revenue_high: high end of next quarter revenue guidance
- fiscal_period: e.g. "Q3 FY2024"

Earnings Report:
{report_text}'''

import anthropic, json
client = anthropic.Anthropic(api_key='YOUR_API_KEY')

def extract_earnings(report_text):
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=1000,
        messages=[{'role': 'user', 'content':
            EARNINGS_EXTRACTION_PROMPT.format(report_text=report_text)}]
    )
    return json.loads(response.content[0].text)

พรอมต์คำนวณอัตราส่วนทางการเงิน

เมื่อต้องการให้โมเดลคำนวณอัตราส่วนทางการเงิน ควรระบุสูตรไว้อย่างชัดเจน อย่าสันนิษฐานว่าโมเดลรู้คำนิยามที่แน่นอน เพราะนักวิเคราะห์แต่ละรายอาจใช้สูตรที่แตกต่างกันเล็กน้อย

RATIO_PROMPT = '''Calculate the following financial ratios using the data provided.
Show your work: state the formula, plug in the numbers, and give the result.
Round all ratios to 2 decimal places.

Ratios to calculate:
1. Gross Margin = (Revenue - COGS) / Revenue * 100
2. Operating Margin = Operating Income / Revenue * 100
3. Net Margin = Net Income / Revenue * 100
4. Current Ratio = Current Assets / Current Liabilities
5. Quick Ratio = (Current Assets - Inventory) / Current Liabilities
6. Debt-to-Equity = Total Debt / Total Shareholders Equity
7. Return on Equity (ROE) = Net Income / Average Shareholders Equity * 100
8. EV/EBITDA = Enterprise Value / EBITDA (if EV is provided)

Financial Data:
{financial_data}'''

def calculate_ratios(financial_data):
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=2000,
        messages=[{'role': 'user', 'content':
            RATIO_PROMPT.format(financial_data=financial_data)}]
    )
    return response.content[0].text

การดึงข้อมูลการเติบโตแบบ YoY

การเติบโตแบบ YoY อาจรายงานเป็นการเปลี่ยนแปลงแบบค่าสัมบูรณ์ เป็นเปอร์เซ็นต์ หรือทั้งสองแบบ พรอมต์ต้องรองรับทุกกรณีและแยกความแตกต่างระหว่างการเติบโตที่รายงานกับการเติบโตตามสกุลเงินคงที่

YOY_PROMPT = '''From the financial document below, extract year-over-year growth metrics.

For each metric found, provide:
- metric_name: e.g. "Revenue", "Gross Profit", "Operating Income"
- current_period: value and period (e.g. "$4.2B, Q3 2024")
- prior_period: value and period (e.g. "$3.8B, Q3 2023")
- yoy_change_pct: percentage change (positive = growth, negative = decline)
- constant_currency_yoy_pct: if reported, the constant-currency growth rate (else null)
- commentary: any management commentary on drivers of the change

IMPORTANT:
- Do not mix GAAP and non-GAAP figures in the same row.
- Mark each row with gaap: true or false.
- If growth is reported only in narrative form (e.g. "revenue grew 15%"),
  still capture it but set current_period and prior_period to null.

Document:
{document_text}'''

def extract_yoy_growth(document_text):
    import json
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=2000,
        messages=[{'role': 'user', 'content':
            YOY_PROMPT.format(document_text=document_text)}]
    )
    return response.content[0].text

รูปแบบการดึงข้อมูลจากเอกสารยื่นต่อ SEC

เอกสารยื่นต่อ SEC (10-K, 10-Q) มีหัวข้อมาตรฐาน ควรเจาะจงส่วนที่ต้องการด้วยพรอมต์ดึงข้อมูลที่คำนึงถึงหัวข้อ เพื่อลดการใช้หน้าต่างบริบทและเพิ่มความแม่นยำ

SEC_EXTRACTION_PROMPT = '''You are analyzing a {filing_type} SEC filing.

From {section_name}, extract the following:
{extraction_targets}

Rules:
1. Quote exact figures as stated — do not round or reformat numbers.
2. Note the fiscal year end and reporting currency.
3. If the section uses tables, extract all rows of the table.
4. Flag any restatements: "[RESTATED from prior filing]".
5. Note any forward-looking statements with [FLS] tag.

Filing Section Text:
{section_text}'''

# Section targets by filing type
SECTION_TARGETS = {
    '10-K': {
        'Item 7 MD&A': 'Revenue breakdown by segment, key cost drivers, liquidity discussion',
        'Item 1A Risk Factors': 'Top 5 risks by category (operational, financial, regulatory, competitive)',
        'Item 8 Financial Statements': 'Consolidated income statement, balance sheet key line items'
    },
    '10-Q': {
        'Item 1 Financial Statements': 'Revenue, operating income, cash flow from operations',
        'Item 2 MD&A': 'Quarter-over-quarter and YoY comparisons'
    }
}

def extract_sec_section(filing_type, section_name, section_text):
    targets = SEC_EXTRACTION_TARGETS = SECTION_TARGETS[filing_type][section_name]
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=3000,
        messages=[{'role': 'user', 'content':
            SEC_EXTRACTION_PROMPT.format(
                filing_type=filing_type, section_name=section_name,
                extraction_targets=targets, section_text=section_text
            )}]
    )
    return response.content[0].text

การสรุปปัจจัยเสี่ยง

เอกสารยื่นต่อ SEC อาจมีปัจจัยเสี่ยงมากกว่า 50 หน้า พรอมต์สรุปที่จัดหมวดหมู่และจัดอันดับความเสี่ยงช่วยให้นักวิเคราะห์ระบุความเสี่ยงที่มีสาระสำคัญที่สุดได้อย่างรวดเร็ว

RISK_FACTOR_PROMPT = '''Summarize the risk factors from this SEC filing.

Categories to use:
1. Financial Risks (liquidity, debt, interest rate, FX)
2. Operational Risks (supply chain, technology, key personnel)
3. Regulatory / Legal Risks (compliance, litigation, government action)
4. Market / Competitive Risks (competition, market conditions, pricing)
5. Macroeconomic Risks (recession, inflation, geopolitical)

For each risk:
- Title: 5-8 word summary
- Category: one of the 5 above
- Materiality: HIGH / MEDIUM / LOW (based on language used: "could significantly...",
  "may adversely affect...", "could result in material...")
- Summary: 2-3 sentence description

Sort each category by Materiality descending.
Limit to top 3 risks per category (15 total max).

Risk Factors Section:
{risk_factors_text}'''

def summarize_risk_factors(risk_factors_text):
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=3000,
        messages=[{'role': 'user', 'content':
            RISK_FACTOR_PROMPT.format(risk_factors_text=risk_factors_text)}]
    )
    return response.content[0].text

การสร้างบันทึกของนักวิเคราะห์

หลังจากดึงข้อมูลและวิเคราะห์ข้อมูลทางการเงินแล้ว ให้สร้างบันทึกในรูปแบบของนักวิเคราะห์เพื่อสรุปข้อค้นพบ พรอมต์ต้องกำหนดให้ใช้โครงสร้างและน้ำเสียงที่เป็นกลางตามแบบงานวิจัยทางการเงินระดับมืออาชีพ

ANALYST_NOTE_PROMPT = '''Write an equity research analyst note for the earnings results below.

STRUCTURE (required sections):
1. Headline: one sentence (include ticker, period, key takeaway, and target price if updated)
2. Investment Thesis: 2-3 sentences on the core bull/bear case
3. Earnings Summary: revenue, gross margin, EPS vs consensus estimates
4. Key Positives: 3 bullet points
5. Key Risks/Concerns: 3 bullet points
6. Guidance Commentary: management outlook, consensus vs guidance delta
7. Valuation: brief note on current multiple vs historical and peers
8. Recommendation: OUTPERFORM / MARKET PERFORM / UNDERPERFORM with 12-month target

TONE: Professional, data-driven, third person. Attribute claims to the company
("Management guided...", "The company reported...").
Do not use vague language — state numbers.

DISCLAIMER: This is AI-generated analysis for informational purposes only.
It does not constitute investment advice. Past performance is not indicative
of future results.

Earnings Data:
{earnings_data}'''

รูปแบบข้อความปฏิเสธความรับผิดชอบทางการเงิน

เช่นเดียวกับเครื่องมือด้านกฎหมายและการแพทย์ เครื่องมือปัญญาประดิษฐ์ด้านการเงินต้องมีข้อความปฏิเสธความรับผิดชอบที่จำเป็นต้องแสดง ควรแทรกข้อความเหล่านี้ไว้ที่ชั้นแอปพลิเคชันเพื่อให้มั่นใจว่าจะไม่มีการละเว้น

FINANCIAL_DISCLAIMER = (
    '\n\n---\n'
    'DISCLAIMER: This content is generated by an AI system for informational '
    'and educational purposes only. It does not constitute investment advice, '
    'a solicitation to buy or sell any security, or a recommendation to invest. '
    'Financial data extracted by AI may contain errors — always verify against '
    'primary source filings. Past performance does not guarantee future results. '
    'Consult a licensed financial advisor before making investment decisions.'
)

def get_financial_analysis(prompt):
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=2000,
        messages=[{'role': 'user', 'content': prompt}]
    )
    raw = response.content[0].text
    return raw + FINANCIAL_DISCLAIMER

# Always use get_financial_analysis() rather than calling the API directly
# to ensure disclaimer is never accidentally omitted

การแยกความแตกต่างระหว่าง GAAP กับตัวเลขที่ไม่ใช่ GAAP

ข้อผิดพลาดที่พบบ่อยที่สุดอย่างหนึ่งในการดึงข้อมูลทางการเงินคือการปะปนตัวเลข GAAP กับตัวเลขที่ไม่ใช่ GAAP พรอมต์ต้องกำหนดอย่างชัดเจนให้โมเดลระบุประเภทของตัวเลขทุกตัวและแจ้งความคลาดเคลื่อน

GAAP_PROMPT = '''Extract all income statement figures from the text below.
For every number:
- Label it as GAAP or Non-GAAP (Adjusted/Pro Forma)
- If the company reports both, show both on separate rows
- Never combine GAAP and Non-GAAP in a single calculation

Common non-GAAP labels to watch for:
"Adjusted", "Non-GAAP", "Pro Forma", "Normalized", "Underlying",
"Core", "Recurring", "Organic" (for revenue)

Output as a table:
| Metric | GAAP Value | Non-GAAP Value | Period |
|--------|------------|----------------|--------|

Also note in a separate section any reconciliation items between GAAP and Non-GAAP:
- Stock-based compensation
- Amortization of acquired intangibles
- Restructuring charges
- Any other adjustments

Document:
{document_text}'''

print('Always verify GAAP/Non-GAAP labels against the company\'s own reconciliation tables.')

การวิเคราะห์แนวโน้มหลายช่วงเวลา

การดึงข้อมูลจากช่วงเวลาเดียวให้ภาพรวม ณ ช่วงเวลาหนึ่งเท่านั้น พรอมต์วิเคราะห์แนวโน้มจะเปรียบเทียบตัวชี้วัดในหลายช่วงเวลา เพื่อแสดงแนวทางการเปลี่ยนแปลงและรูปแบบการเร่งตัวหรือชะลอตัว

TREND_PROMPT = '''Analyze the financial trend for {company_name} using the multi-period data below.

1. Create a summary table with these columns:
   | Period | Revenue | Rev Growth YoY | Gross Margin | Op Margin | Net Margin |

2. Identify trends:
   - Is revenue growth accelerating, decelerating, or stable?
   - Margin expansion or compression trend?
   - Any notable inflection points (period where trend changed direction)?

3. Key observations (5 bullet points max):
   - Focus on directional changes, not just absolute numbers
   - Note any seasonality patterns if visible in quarterly data

4. Risks in the trend:
   - Flag any deterioration that management has not addressed
   - Note if guidance implies trend continuation or reversal

Data ({num_periods} periods):
{multi_period_data}'''

def analyze_trend(company_name, multi_period_data, num_periods):
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=2000,
        messages=[{'role': 'user', 'content':
            TREND_PROMPT.format(
                company_name=company_name,
                multi_period_data=multi_period_data,
                num_periods=num_periods
            )}]
    )
    return response.content[0].text

การตรวจสอบความถูกต้อง: ตรวจทานตัวเลขที่ดึงข้อมูล

ข้อผิดพลาดในการดึงข้อมูลทางการเงินอาจก่อให้เกิดอันตราย ควรสร้างขั้นตอนตรวจสอบความถูกต้องที่ตรวจสอบตัวเลขที่ดึงมาเทียบกับอัตลักษณ์ทางบัญชี (เช่น กำไรขั้นต้น = รายได้ - COGS) เพื่อค้นหาการแต่งข้อมูลขึ้นเองหรือข้อผิดพลาดในการดึงข้อมูล

def validate_financials(extracted):
    errors = []

    # Check revenue consistency
    if extracted.get('revenue_usd_millions') and extracted.get('cogs_usd_millions'):
        calc_gp = extracted['revenue_usd_millions'] - extracted['cogs_usd_millions']
        stated_gp = extracted.get('gross_profit_usd_millions')
        if stated_gp and abs(calc_gp - stated_gp) > 1:  # $1M tolerance
            errors.append(
                f'Gross profit mismatch: calculated {calc_gp:.1f}M '
                f'vs stated {stated_gp:.1f}M'
            )

    # Check gross margin consistency
    if extracted.get('revenue_usd_millions') and extracted.get('gross_profit_usd_millions'):
        calc_gm = (extracted['gross_profit_usd_millions'] /
                   extracted['revenue_usd_millions']) * 100
        stated_gm = extracted.get('gross_margin_pct')
        if stated_gm and abs(calc_gm - stated_gm) > 0.5:  # 0.5 pp tolerance
            errors.append(
                f'Gross margin mismatch: calculated {calc_gm:.1f}% '
                f'vs stated {stated_gm:.1f}%'
            )

    return errors

# Always run validation after extraction
errors = validate_financials(extracted_data)
if errors:
    print('Validation errors — manually verify:', errors)
else:
    print('Validation passed')

ตรวจสอบความเข้าใจ

เมื่อต้องดึงข้อมูลตัวชี้วัดทางการเงินจากรายงานผลประกอบการ โมเดลคืนค่าอัตรากำไรขั้นต้นเป็น 45% แต่ตัวเลขรายได้และ COGS บ่งชี้ว่าอัตรากำไรขั้นต้นเป็น 51% คุณควรทำอย่างไร

สรุปการเขียนพรอมต์ด้านการเงิน

การเขียนพรอมต์กับข้อมูลทางการเงินและข้อมูลเชิงปริมาณต้องอาศัยความแม่นยำ การระบุประเภท และการตรวจสอบความถูกต้อง:

  • พรอมต์ดึงข้อมูล: ระบุชื่อฟิลด์ที่แน่นอนและส่งคืนข้อมูลในรูปแบบเจสันเพื่อประมวลผลด้วยเครื่อง
  • ระบุสูตรอย่างชัดเจน: ให้สูตรที่แน่นอนเสมอสำหรับการคำนวณอัตราส่วน
  • GAAP กับตัวเลขที่ไม่ใช่ GAAP: ระบุประเภทของตัวเลขทุกตัว — ห้ามปะปนกันในการคำนวณ
  • ส่วนต่าง ๆ ของ SEC: เจาะจงหัวข้อรายการที่ต้องการเพื่อลดข้อมูลรบกวน
  • การตรวจสอบความถูกต้อง: ตรวจสอบเทียบกับอัตลักษณ์ทางบัญชีเพื่อค้นหาข้อผิดพลาดในการดึงข้อมูล
  • ข้อความปฏิเสธความรับผิดชอบ: แทรกข้อความปฏิเสธความรับผิดชอบด้านการลงทุนเสมอที่ชั้นแอปพลิเคชัน

คำถามที่พบบ่อย

บทเรียน “พรอมต์ด้านการเงินและเชิงปริมาณ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “พรอมต์ด้านการเงินและเชิงปริมาณ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส AI Prompt Engineering ให้อัปเกรดเป็น CoddyKit PRO คอร์ส AI Prompt Engineering มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “พรอมต์ด้านการเงินและเชิงปริมาณ”

การวิเคราะห์ผลประกอบการ การให้คะแนนความเสี่ยง และพรอมต์ดึงข้อมูลจากเอกสารยื่น SEC คุณปฏิบัติ AI Prompt Engineering ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน AI Prompt Engineering หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน AI Prompt Engineering บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน

บทเรียน “พรอมต์ด้านการเงินและเชิงปริมาณ” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน AI Prompt Engineering นี้ได้ไหม

ได้ บทเรียน AI Prompt Engineering ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. รูปแบบพรอมต์สำหรับงานกฎหมาย
  2. การเขียนพรอมต์ด้านการแพทย์และคลินิก
  3. พรอมต์ด้านการเงินและเชิงปริมาณ
  4. การแทรกอภิธานศัพท์และภววิทยาเฉพาะโดเมน
← กลับไปที่ AI Prompt Engineering