Skip to content

hany202507/finance-ai-skills / skills/표본sampling

표본sampling

Verified

매출 원장 · 세금계산서 목록 · 채권 명세 같은 계정 리스트 파일 하나로 감사 표본 조서(설계 · 표본 · 평가)를 엑셀로 만든다. 파일을 먼저 읽고 허용왜곡표시 · 위험 수준 · 결산일 · 계층화 · 시산표 금액 같은 판단만 한 번에 물은 뒤 바로 뽑는다. 금액 단위 표본(MUS)이 기본이고 무작위 · 체계적 · 특정 항목 선정도 된다. 같은 시드면 같은 표본이 나오고, 표본 크기 근거(모집단 금액 · 허용왜곡표시 · 위험 수준 · 신뢰계수 · 표본 간격)와 모집단 대사(시산표 금액과의 차이)를 조서에 남긴다. 감사인이 검사 결과 · 왜곡표시 금액을 적으면 상한 왜곡표시(기본 정밀도 + 투영 + 증분 허용)로 평가한다. "샘플링", "표본 뽑아줘", "이 파일로 샘플링", "매출 표본", "채권 표본", "MUS", "금액 단위 표본", "표본 크기", "신뢰계수", "표본 간격", "표본 평가", "왜곡표시 투영", "감사기준서 530", "거래처별로 뽑아", "계층화", "엑셀 줄게 표본 뽑아줘" 가 언급되면 트리거.

FileKindSize
README.mdmarkdown3.2 KB
SKILL.mdskill md13.1 KB
examples/모의자료/매출원장.xlsxbinary58.2 KB
requirements.txtmanifest89 B
scripts/audit/__init__.pyscript273 B
scripts/audit/cli_sample.pyscript13.3 KB
scripts/audit/dataset.pyscript8.6 KB
scripts/audit/errors.pyscript503 B
scripts/audit/figures.pyscript35.4 KB
scripts/audit/folder.pyscript27.1 KB
scripts/audit/params.pyscript15.3 KB
scripts/audit/prior.pyscript29.8 KB
scripts/audit/priorwp.pyscript33.6 KB
scripts/audit/reader.pyscript94.6 KB
scripts/audit/riskplan.pyscript9.5 KB
scripts/audit/sample_wp.pyscript46.2 KB
scripts/audit/style.pyscript7.9 KB
scripts/audit/workpapers/__init__.pyscript7.5 KB
scripts/audit/workpapers/banks.pyscript18.6 KB
scripts/audit/workpapers/common.pyscript33.1 KB
scripts/audit/workpapers/confirm.pyscript45.4 KB
scripts/audit/workpapers/fsrec.pyscript9.6 KB
scripts/audit/workpapers/issuedetail.pyscript9.7 KB
scripts/audit/workpapers/jet.pyscript98.3 KB
scripts/audit/workpapers/lead.pyscript75.0 KB
scripts/audit/workpapers/recalc.pyscript51.4 KB
scripts/audit/workpapers/sales.pyscript35.8 KB
scripts/audit/workpapers/sampling.pyscript8.2 KB
scripts/audit/workpapers/sampling_eval.pyscript9.9 KB
scripts/audit/workpapers/skeleton.pyscript15.7 KB
scripts/audit/workpapers/suggest.pyscript11.1 KB
scripts/audit/workpapers/tot.pyscript26.9 KB
scripts/audit/workpapers/vouch.pyscript27.8 KB
scripts/audit/workpapers/w3800.pyscript12.4 KB
scripts/audit/workpapers/xlcalc.pyscript11.6 KB
scripts/audit/wp.pyscript34.5 KB
scripts/definitions/folder_standard.yamlconfig15.0 KB
scripts/definitions/sampling.yamlconfig7.4 KB
scripts/run.pyscript2.6 KB
tests/excel_recalc.pyscript1.3 KB
tests/make_ledger.pyscript2.1 KB
tests/test_sample.pyscript12.9 KB
tests/test_sampling_eval.pyscript5.9 KB

tests/test_sampling_eval.py

View on GitHub
"""표본 평가 엔진(2026-11-09): 포아송 상한 계수, 금액 단위 표본 상한 왜곡표시(AICPA 감사 표본 지침 방식), 확장계수,
예상 왜곡표시를 넣은 표본 간격, 체계적 표본, 층 배분, 비통계 비율 투영, 특정 항목 선정."""
from __future__ import annotations

import sys
from pathlib import Path

import pytest

sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "scripts"))

from audit.workpapers import sampling
from audit.workpapers import sampling_eval as se


@pytest.mark.parametrize("k,want", [(0, 2.9957), (1, 4.7439), (2, 6.2958), (3, 7.7537), (4, 9.1535)])
def test_poisson_upper_95(k, want):
    assert se.upper(k, 0.95) == pytest.approx(want, abs=1e-4)


def test_poisson_upper_other_levels():
    assert se.upper(0, 0.90) == pytest.approx(2.3026, abs=1e-4)
    assert se.upper(1, 0.90) == pytest.approx(3.8897, abs=1e-4)
    assert se.upper(0, se.confidence_of(1.0)) == pytest.approx(1.0)
    t = se.factor_table(0.95, 3)
    assert [x[0] for x in t] == [1, 2, 3]
    assert t[0][2] == pytest.approx(4.7439 - 2.9957, abs=2e-4) and t[1][2] == pytest.approx(6.2958 - 4.7439, abs=2e-4)


def _row(amount, err, key=False, stratum="전체"):
    return {"amount": amount, "err": err, "key": key, "stratum": stratum, "done": True}


def test_mus_upper_limit_by_hand():
    """간격 100,000 · 신뢰계수 3.0(95%). 고액 1건 과대 5,000, 소액 과대 오염률 0.5 · 0.2, 소액 과소 오염률 0.2."""
    rows = [_row(250_000, 5_000), _row(10_000, 2_000), _row(50_000, 25_000), _row(20_000, -4_000), _row(30_000, None)]
    x = se.mus(rows, 100_000, 3.0, 0.95, tolerable=300_000)
    d1, d2 = 1.7481, 1.5519          # ΔF 는 F(k) 를 반올림 전에 빼고 넷째 자리로 반올림한 값(엑셀 계수 표와 같음)
    assert x["basic"] == pytest.approx(300_000)
    assert x["known_over"] == 5_000 and x["projected_over"] == pytest.approx(75_000)
    assert x["increment_over"] == pytest.approx(50_000 * (d1 - 1) + 20_000 * (d2 - 1), rel=1e-4)
    assert x["upper_over"] == pytest.approx(300_000 + 75_000 + 50_000 * (d1 - 1) + 20_000 * (d2 - 1), rel=1e-5)
    assert x["upper_under"] == pytest.approx(300_000 + 20_000 + 20_000 * (d1 - 1), rel=1e-5)
    assert x["estimate"] == pytest.approx(55_000)
    assert x["verdict"] == se.V_UPPER_OVER


def test_mus_verdicts():
    clean = [_row(10_000, None), _row(20_000, 0)]
    assert se.mus(clean, 100_000, 3.0, 0.95, tolerable=300_000)["verdict"] == se.V_NONE
    assert se.mus(clean, 100_000, 3.0, 0.95, tolerable=299_000)["verdict"] == se.V_UPPER_OVER     # 기본 정밀도만으로 넘는다
    # 예상 왜곡을 넣어 간격을 줄이면 작은 왜곡이 있어도 상한이 허용왜곡표시 안에 든다
    p = sampling.plan(10_000_000, 100, 1_000_000, "높음", expected=100_000)
    small = [_row(50_000, 500), _row(80_000, None)]
    x = se.mus(small, p["interval"], p["factor"], p["confidence"], tolerable=1_000_000)
    assert x["verdict"] == se.V_WITHIN
    pending = [dict(_row(10_000, None), done=False)]
    assert se.mus(pending, 100_000, 3.0, 0.95, tolerable=300_000)["verdict"] == se.V_PENDING
    nodiff = [dict(_row(10_000, None), nodiff=True)]
    assert se.mus(nodiff, 100_000, 3.0, 0.95, tolerable=300_000)["verdict"] == se.V_NODIFF
    big = [_row(400_000, 350_000, key=True)]
    assert se.mus(big, 100_000, 3.0, 0.95, tolerable=300_000)["verdict"] == se.V_EST_OVER
    an = se.mus(clean, 100_000, 1.0, None, anomaly=-50_000, tolerable=200_000)
    assert an["upper_under"] == pytest.approx(150_000) and an["estimate"] == pytest.approx(-50_000)


def test_key_threshold_below_interval():
    """고액 기준을 간격보다 낮추면 그 사이 항목은 투영하지 않고 그대로 더한다."""
    rows = [_row(60_000, 6_000)]
    assert se.mus(rows, 100_000, 3.0, 0.95)["projected_over"] == pytest.approx(10_000)
    assert se.mus(rows, 100_000, 3.0, 0.95, key=50_000)["projected_over"] == pytest.approx(6_000)


def test_expansion_factor_and_plan():
    assert sampling.expansion_factor(0.95) == pytest.approx(1.6)
    assert sampling.expansion_factor(0.90) == pytest.approx(1.5)
    assert sampling.expansion_factor(0.925) == pytest.approx(1.55)
    assert sampling.expansion_factor(0.999) == pytest.approx(1.9)
    p = sampling.plan(10_000_000, 100, 1_000_000, "높음", expected=100_000)
    assert p["ef"] == pytest.approx(1.6) and p["interval"] == pytest.approx((1_000_000 - 160_000) / 3.0)
    assert sampling.plan(10_000_000, 100, 1_000_000, "높음")["interval"] == pytest.approx(1_000_000 / 3.0)
    with pytest.raises(ValueError):
        sampling.plan(10_000_000, 100, 1_000_000, "높음", expected=700_000)


def test_systematic_and_allocate():
    items = [(f"k{i}", 1000 + i) for i in range(100)]
    a = sampling.systematic(items, 10, 11)
    b = sampling.systematic(items, 10, 11)
    assert a["selected"] == b["selected"] and a["size"] == 10 and a["step"] == 10
    idx = [int(r["key"][1:]) for r in a["selected"]]
    assert all(y - x == 10 for x, y in zip(idx, idx[1:]))
    assert sampling.allocate(10, [5, 3, 2]) == [5, 3, 2]
    assert sampling.allocate(4, [100, 1, 1]) == [2, 1, 1]
    assert sampling.allocate(2, [0, 0]) == [0, 0]


def test_ratio_and_specific():
    rows = [_row(1_000, 100, stratum="A"), _row(1_000, None, stratum="A"), _row(500, -50, stratum="B"),
            _row(9_000, 900, key=True, stratum="A")]
    x = se.ratio(rows, {"A": 20_000, "B": 5_000}, tolerable=2_000)
    assert x["strata"]["A"]["proj_over"] == pytest.approx(100 / 2_000 * 20_000)
    assert x["projected_over"] == pytest.approx(1_000 + 900)
    assert x["projected_under"] == pytest.approx(50 / 500 * 5_000)
    assert x["verdict"] == se.V_R_WITHIN
    assert se.ratio(rows, {"A": 20_000, "B": 5_000}, tolerable=1_500)["verdict"] == se.V_R_OVER
    s = se.specific(rows, 100_000, tolerable=50_000)
    assert s["rest"] == pytest.approx(100_000 - 11_500) and s["verdict"] == se.V_S_REST
    assert se.specific(rows, 20_000, tolerable=50_000)["verdict"] == se.V_S_OK
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 196kUpdated Claude CodeCodexVerifiedInstall