1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Python3ではじめるシステムトレード:事象(集合演算)に関する確率の基礎問題

1
Last updated at Posted at 2025-10-16

最小のσ加法族と原子分割

  • 有限個の事象 $E_1,\dots,E_n$ が与えられたら,$\Omega$ を
    $$\bigcap_{i=1}^n E_i^{\varepsilon_i},\quad\varepsilon_i\in\lbrace 1,c\rbrace$$
    の形の原子(atom)へ分割する(空集合は除外)。これは $\sigma(E_1,\dots,E_n)$ を生成する原子分割(最小可測分割)だ。

  • 以後は各原子の確率を変数に置き,

    1. 非負性,2) 総和 $=1$,3) 周辺確率や独立の制約
      を線形制約として課す——これで Fréchet 境界や独立時の値が機械的に導ける。

注意:

  • 「まずは $\sigma$加法族が最小となる素な空間に分割」→用語を整えると
    「$\sigma(E_1,\dots,E_n)$ が生成される最小の可測分割(原子分割)に切る」が適切。
  • 事象が無限族だと原子は無限になり得て,実務上は有限部分族で扱う。

Fréchet(フレーシェ)境界:

与えられた周辺確率だけから,積(∩)や和(∪)の確率が取りうる最小–最大を与える鋭い(達成可能な)境界だ。独立は不要。

一般 $n$ 事象 $E_1,\dots,E_n$

\max\Bigl\{0, \sum_{i=1}^n P(E_i)-(n-1)\Bigr\} \le\ P\Bigl(\bigcap_{i=1}^n E_i\Bigr)\ \le\ \min_i P(E_i),
\max_i P(E_i) \le\ P\Bigl(\bigcup_{i=1}^n E_i\Bigr) \le \min\Bigl\{1,\ \sum_{i=1}^n P(E_i)\Bigr\}.

導出の要点(最短)

  • 下限は補集合と union bound:
    $$P(\cap E_i)=1-P(\cup E_i^c)\ge 1-\sum P(E_i^c)=\sum P(E_i)-(n-1).$$
  • 上限は包含:$\cap E_i\subset E_j$(任意の $j$),$\cup E_i\supset E_j$。

達成可能性

境界は鋭い(tight)。適切な原子分割の配置で上下端が実現可能。

例:$P(A)=P(B)=P(C)=\tfrac34$

$$
\tfrac14\ \le\ P(ABC)\ \le\ \tfrac34,\qquad
\tfrac34\ \le\ P(A\cup B\cup C)\ \le\ 1.
$$

(用語メモ:Fréchet–Hoeffding 境界とも。)

2事象の例

$$
\max \lbrace 0,\ P(A)+P(B)-1 \rbrace \le\ P(A\cap B)\ \le\ \min\lbrace P(A),P(B)\rbrace,
$$
$$
\max\lbrace P(A),P(B)\rbrace\ \le\ P(A\cup B)\ \le\ \min\lbrace 1,\ P(A)+P(B)\rbrace.
$$

二事象 $A,B$ に対する Fréchet 境界を,$\Omega$ の原子分割で証明する。

原子分割

$$
\begin{aligned}
E_1&=A\cap B,\quad
E_2=A\cap B^c,
E_3&=A^c\cap B,\quad
E_4=A^c\cap B^c.
\end{aligned}
$$
互いに素で $\Omega=E_1\cup E_2\cup E_3\cup E_4$。各確率を $p_i=P(E_i)\ (\ge0)$ とおく。

このとき
$$
P(A)=p_1+p_2,\quad
P(B)=p_1+p_3,\quad
P(A\cap B)=p_1,\quad
1=p_1+p_2+p_3+p_4.
$$

上限

$A\cap B\subset A$ および $A\cap B\subset B$ より
$$
P(A\cap B)=p_1\le p_1+p_2=P(A),\qquad
P(A\cap B)=p_1\le p_1+p_3=P(B).
$$
ゆえに
$$
P(A\cap B)\le \min{P(A),P(B)}.
$$

下限

$$
\begin{aligned}
1&=p_1+p_2+p_3+p_4\
&=(p_1+p_2)+(p_1+p_3)-p_1+p_4\
&=P(A)+P(B)-P(A\cap B)+p_4
\end{aligned}
$$
(加算加法性+互いに素)

より $p_4\ge0$ を用いて
$$
P(A\cap B)\ge P(A)+P(B)-1.
$$

結論

$$
P(A)+P(B)-1\ \le\ P(A\cap B)\ \le\ \min\lbrace P(A),P(B)\rbrace.
$$

鋭さ(達成可能性)

  • 上限達成:$A\subset B$(すなわち $p_2=0$)なら $P(A\cap B)=P(A)$。
  • 下限達成:$A$ と $B$ を可能な限り離して $P(A\cup B)=1$(すなわち $p_4=0$)にすると $P(A\cap B)=P(A)+P(B)-1$。

統計検定一級2022数理 問1

確率空間の事象 $A, B, C$ の確率がそれぞれ

$$ P(A) = P(B) = P(C) = \frac{3}{4} \tag{1} $$

であるとする。以下の各問に答えよ。

[1] 事象 $A, B, C$ が互いに独立なとき、$P(A \cap B)$ および $P(A \cap B \cap C)$ をそれぞれ求めよ。

[2] 事象 $A$ と $B$ が互いに独立とは限らないとき、$P(A \cap B)$ の取り得る値の範囲を求めよ。

[3] 事象 $A, B, C$ が互いに独立とは限らないとき、$P(A \cap B \cap C)$ の取り得る値の範囲を求めよ。

[4] 条件 (1) に加え、さらに条件

$$ P(A \cap B) = P(A)P(B), P(A \cap C) = P(A)P(C), P(B \cap C) = P(B)P(C) $$

を追加したとき、$P(A \cap B \cap C)$ の取り得る値の範囲を求めよ。

[1] 略

[2]

二事象 $A,B$ の原子分割
$$
\begin{align*}
&E_1=AB,\quad\
&E_2=AB^c,\quad\
&E_3=A^cB,\quad\
&E_4=A^cB^c
\end{align*}
$$
$p_i=P(E_i)\ (\ge0)$ とおく。すると
$$
P(A)=p_1+p_2,\quad P(B)=p_1+p_3,\quad P(AB)=p_1,\quad 1=p_1+p_2+p_3+p_4.
$$

非負性より
$$
p_1\le p_1+p_2=P(A),\quad p_1\le p_1+p_3=P(B)\ \Rightarrow\ p_1\le \min\lbrace P(A),P(B)\rbrace.
$$
また
$$
1=(p_1+p_2)+(p_1+p_3)-p_1+p_4
= P(A)+P(B)-P(AB)+p_4
$$
から $p_4\ge0$ を用いて
$$
P(AB)=p_1\ge P(A)+P(B)-1.
$$

以上より
$$
P(A)+P(B)-1\ \le\ P(A\cap B)\ \le\ \min\lbrace P(A),P(B)\rbrace.
$$
本問では $P(A)=P(B)=\tfrac34$ なので
$$
\tfrac12\ \le\ P(A\cap B)\ \le\ \tfrac34.
$$

[3]

三事象の原子を

\begin{aligned}
&E_1=ABC,\\
&E_2=ABC^c,\\ 
&E_3=AB^cC,\\ 
&E_4=A^cBC,\\
&E_5=AB^cC^c,\\ 
&E_6=A^cBC^c,\\ 
&E_7=A^cB^cC,\\
&E_8=A^cB^cC^c
\end{aligned}

とし,$p_i=P(E_i)\ (\ge0)$,$\sum_{i=1}^8p_i=1$ と置く。すると

\begin{aligned}
&P(A)=p_1+p_2+p_3+p_5,\quad\\
&P(B)=p_1+p_2+p_4+p_6,\\
&P(C)=p_1+p_3+p_4+p_7,\quad\\
&P(ABC)=p_1.
\end{aligned}

上限は包含から直ちに
$$
P(ABC)=p_1\le \min\lbrace P(A),P(B),P(C)\rbrace.
$$

下限は $S:=P(A)+P(B)+P(C)$ を用いて導く。上の和から
$$
S=3p_1+2(p_2+p_3+p_4)+(p_5+p_6+p_7).
$$
一方,$1=\sum_{i=1}^8p_i=p_1+(p_2+p_3+p_4)+(p_5+p_6+p_7)+p_8$ より
$$
(p_2+p_3+p_4)+(p_5+p_6+p_7)\le 1-p_1.
$$
$S$ を固定して $p_1$ を最小化するには,係数が大きい項にできるだけ割り当てればよいので
$(p_2+p_3+p_4)=1-p_1,\ (p_5+p_6+p_7)=0$ とすると
$$
S\le 3p_1+2(1-p_1)=p_1+2 \ \Rightarrow\ p_1\ge S-2.
$$
また $p_1\ge 0$ だから
$$
P(ABC)\ge \max\lbrace S-2,\ 0\rbrace.
$$

以上より Fréchet 境界
$$
\max\lbrace P(A)+P(B)+P(C)-2,\ 0\rbrace\ \le\ P(ABC)\ \le\ \min\lbrace P(A),P(B),P(C)\rbrace.
$$

本問では $P(A)=P(B)=P(C)=\tfrac34$ なので
$$
\tfrac14\ \le\ P(ABC)\ \le\ \tfrac34.
$$

(達成例:下限は $p_1=\tfrac14,\ p_2=p_3=p_4=\tfrac14,\ \text{他}=0$。上限は $A=B=C$ とすれば $p_1=\tfrac34$。)

[4]

\begin{aligned}
&E_1=ABC,\\
&E_2=ABC^c,\\ 
&E_3=AB^cC,\\ 
&E_4=A^cBC,\\
&E_5=AB^cC^c,\\ 
&E_6=A^cBC^c,\\ 
&E_7=A^cB^cC,\\
&E_8=A^cB^cC^c\\
&p_i=P(E_i)\ (\ge0)
\end{aligned}

条件より $P(A)=P(B)=P(C)=\tfrac34$、

対独立で $P(AB)=P(AC)=P(BC)=\left(\tfrac34\right)^2=\tfrac{9}{16}$。

$x:=P(ABC)=p_1$ とおくと

\begin{aligned}
p_2&=P(AB)-P(ABC)=\tfrac{9}{16}-x,\\
p_3&=P(AC)-P(ABC)=\tfrac{9}{16}-x,\\
p_4&=P(BC)-P(ABC)=\tfrac{9}{16}-x,\\
p_5&=P(A)-P(AB)-P(AC)+P(ABC)=x-\tfrac{3}{8},\\
p_6&=x-\tfrac{3}{8},\qquad\\
p_7&=x-\tfrac{3}{8},\\
p_8&=1-\sum_{i=1}^7 p_i
=1-\Bigl[x+3\Bigl(\tfrac{9}{16}-x\Bigr)+3\Bigl(x-\tfrac{3}{8}\Bigr)\Bigr]
=\tfrac{7}{16}-x.
\end{aligned}

非負性 $p_i\ge0$ から
$$
x\ge \tfrac{3}{8},\qquad x\le \tfrac{9}{16},\qquad x\le \tfrac{7}{16}.
$$
よって最終的に
$$
\tfrac{3}{8}\ \le\ P(A\cap B\cap C)=x\ \le\ \tfrac{7}{16}.
$$

(達成例:$x=\tfrac{3}{8}$ では $p_5=p_6=p_7=0,\ p_2=p_3=p_4=\tfrac{3}{16},\ p_8=\tfrac{1}{16}$。$x=\tfrac{7}{16}$ では $p_8=0,\ p_2=p_3=p_4=\tfrac{1}{8},\ p_5=p_6=p_7=\tfrac{1}{16}$。)

# Redraw the figures with smaller sizes and slightly smaller labels.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.patches import Circle

# ---------- [4] pairwise independent: area-faithful mosaic (smaller) ----------
PA = PB = PC = 3/4
PAB = PAC = PBC = (3/4)**2

def atoms_case4(x):
    p1 = x
    p2 = PAB - x
    p3 = PAC - x
    p4 = PBC - x
    p5 = PA - PAB - PAC + x
    p6 = PB - PAB - PBC + x
    p7 = PC - PAC - PBC + x
    p8 = 1 - (p1+p2+p3+p4+p5+p6+p7)
    return dict(p1=p1,p2=p2,p3=p3,p4=p4,p5=p5,p6=p6,p7=p7,p8=p8)

LABELS = {
    "p1":"ABC", "p2":"AB C^c", "p3":"A B^c C", "p4":"A^c B C",
    "p5":"A only", "p6":"B only", "p7":"C only", "p8":"none"
}

def draw_mosaic_small(probs, title):
    items = list(probs.items())
    items.sort(key=lambda kv: -kv[1])
    x0, y0, w, h = 0.0, 0.0, 1.0, 1.0
    horizontal = True
    remaining = sum(v for _, v in items)
    fig, ax = plt.subplots(figsize=(4.2,3.6))
    for k, val in items:
        if val <= 0: continue
        frac = val / remaining if remaining>0 else 0
        if horizontal:
            ww = w * frac; rect = (x0,y0,ww,h); x0 += ww; w -= ww
        else:
            hh = h * frac; rect = (x0,y0,w,hh); y0 += hh; h -= hh
        horizontal = not horizontal
        ax.add_patch(plt.Rectangle((rect[0], rect[1]), rect[2], rect[3],
                                   edgecolor='black', facecolor=None, fill=False, linewidth=1.2))
        cx, cy = rect[0]+rect[2]/2, rect[1]+rect[3]/2
        ax.text(cx, cy, f"{LABELS[k]}\n{probs[k]:.4f}", ha='center', va='center', fontsize=9)
        remaining -= val
    ax.set_xlim(0,1); ax.set_ylim(0,1); ax.set_aspect('equal'); ax.axis('off')
    ax.set_title(title, fontsize=11)
    plt.tight_layout()
    plt.show()

for x, name in [(3/8,"[4] Lower bound x=3/8"),
                ((3/4)**3,"[4] Independence x=(3/4)^3"),
                (7/16,"[4] Upper bound x=7/16")]:
    draw_mosaic_small(atoms_case4(x), name)

# ---------- [3] marginals only: smaller Venn-number (labels only) ----------
def feasible_a_interval(x):
    a_min = max(0.0, (5/4 - 2*x)/3)
    a_max = (3/4 - x)/2
    return a_min, a_max

def atoms_from_xa(x, a):
    b = 3/4 - x - 2*a
    p1 = x
    p2 = p3 = p4 = a
    p5 = p6 = p7 = b
    p8 = 1 - (p1 + 3*a + 3*b)
    return dict(p1=p1,p2=p2,p3=p3,p4=p4,p5=p5,p6=p6,p7=p7,p8=p8)

def venn_numbers_small(p, title):
    fig, ax = plt.subplots(figsize=(4.2,4.0))
    r = 1.2
    A, B, C = (0.0,0.0), (1.4,0.0), (0.7,1.1)
    for (cx, cy) in [A,B,C]:
        ax.add_patch(Circle((cx,cy), r, fill=False, linewidth=1.5))
    ax.text(-0.15,-1.45,"A", fontsize=10); ax.text(1.55,-1.45,"B", fontsize=10); ax.text(0.7,2.3,"C", fontsize=10)
    ax.text(0.7,0.3,  f"ABC\n{p['p1']:.4f}", ha='center', fontsize=9)
    ax.text(0.2,-0.1, f"AB C^c\n{p['p2']:.4f}", ha='center', fontsize=9)
    ax.text(0.5,0.8,  f"A B^c C\n{p['p3']:.4f}", ha='center', fontsize=9)
    ax.text(0.95,0.8, f"A^c B C\n{p['p4']:.4f}", ha='center', fontsize=9)
    ax.text(-0.5,0.2, f"A only\n{p['p5']:.4f}", ha='center', fontsize=9)
    ax.text(1.95,0.2, f"B only\n{p['p6']:.4f}", ha='center', fontsize=9)
    ax.text(0.7,2.0,  f"C only\n{p['p7']:.4f}", ha='center', fontsize=9)
    ax.text(2.2,-1.4, f"none\n{p['p8']:.4f}", ha='center', fontsize=9)
    ax.set_xlim(-1.2,2.6); ax.set_ylim(-1.8,2.4); ax.set_aspect('equal'); ax.axis('off')
    ax.set_title(title, fontsize=11); plt.tight_layout(); plt.show()

# Cases for [3]
for x, name in [(1/4, "[3] Lower bound x=1/4"),
                (0.50,"[3] Interior x=0.50"),
                (3/4, "[3] Upper bound x=3/4")]:
    a_min, a_max = feasible_a_interval(x); a = 0.5*(a_min+a_max)
    p = atoms_from_xa(x, a)
    venn_numbers_small(p, name)

image.png
image.png

円のベン図は確率の面積を反映していません。

image.png

image.png

参考

Python3ではじめるシステムトレード【第2版】環境構築と売買戦略

「画像をクリックしていただくとpanrollingのホームページから書籍を購入していただけます。

「画像をクリックしていただくとpanrollingのホームページから書籍を購入していただけます。」

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?