機率 & 統計
A Comprehensive Tutorial to Probability & Statistics
盧政良 (Arthur)
預備知識
微積分
線性代數
關於微積分
• ⾄少掌握微分、積分的概念。
• 還債的機會
•
台⼤數學系朱樺老師:http:!//www.math.ntu.edu.tw/~hchu/Calculus/
⾃⾏閱讀Chapter 1,2,3,5。
變化量 累積量
關於線性代數
• ⾄少掌握向量、內積、聯立⽅程組、
反矩陣的概念。
• 還債的機會
•
3Blue1Brown:https:!//www.youtube.com/playlist?
list=PLZHQObOWTQDPD3MizzM2xVFitgF8hE_ab
不確定性
⽤機率的語⾔去描述不確定性
沒有完整的資訊
原因?成本太⾼,甚⾄根本不可⾏。
無法預知未來
尤其是⾦融市場!!!
擲⼀次硬幣
公正的硬幣:正⾯與反⾯出現的機率相同
均勻分配
Uniform Distribution
https:!//en.wikipedia.org/wiki/Discrete_uniform_distribution
https:!//en.wikipedia.org/wiki/Uniform_distribution_(continuous)
擲很多次硬幣
⼆項式分配
Binomial Distribution
https:!//en.wikipedia.org/wiki/Binomial_distribution
擲了無窮多次硬幣
常態分配
Normal Distribution
⼜稱⾼斯分配 (Gauss Distribution)
https:!//en.wikipedia.org/wiki/Normal_distribution
Z ∼ N(0, 1)
Z是⼀個隨機變數,遵守⼀個標準常態分配。
平均數
變異數
Z′ = 1 + 2 × Z ∼ N(1, 4)
shift
scaling
敘述統計
•
中⼼•
算術平均值、幾何平均數、調和平均數、中位數、眾數•
分散程度•
變異數、標準差、四分位差、百分位數、最⼤值、最⼩值https://upload.wikimedia.org/wikipedia/commons/thumb/8/8c/Standard_deviation_diagram.svg/2880px-Standard_deviation_diagram.svg.png
機率論
Probability Theory
https:!//en.wikipedia.org/wiki/Probability_axioms
符號定義
•
樣本:•
樣本空間:•
事件:•
事件空間:•
機率測度:•
機率空間:ω
Ω E
ℱ = 2 Ω
P : ℱ → ℝ (Ω, ℱ, P)
事件空間為樣本空間中所有元素的冪集
ω ∈ Ω
擲公正硬幣⼀次
•
考慮⼀個公正硬幣,則 。•
其事件空間 非 且非 , 出現 , 出現 , 出現 或•
所對應的機率測度為:•
•
•
Ω = {
H,
T}
ℱ = {
H T H T H T}
P(A = ϕ) = 0
P(A = H) = P(A = T) = 0.5 P(A = H or T) = 1
空集合
擲公正硬幣兩次
•
考慮⼀個公正硬幣,則 。•
其事件空間•
所對應的機率測度為:•
•
Ω = {
H,
T} × {
H,
T} ℱ = ?
P(A = (H, H)) = P(A = (T, T)) = 0.25
P(A = (H, ⋅ )) = P(A = (T, ⋅ )) = P(A = ( ⋅ , H)) = P(A = ( ⋅ , T)) = 0.5
樹狀圖?
來當個賭徒吧
假設出現正⾯獲得⼀元,出現反⾯則損失⼀元。
隨機變數
Random Variable
X : ω ∈ Ω → ℝ
X ∼ 某分配
每次擲硬幣的報酬是多少?
每次擲硬幣的期望報酬是多少?
E[ g(X) ] =
{
∑ Ω g(x)P(x)
∫ Ω g(x) dF(x)
連續版本 隨機變數的函數
離散版本
E[ X ] = X( H ) × P(X( H )) + X( T ) × P(X( T ))
= 1 × 0.5 + (−1) × 0.5
= 0
動差
•
第⼀動差:•
第⼆動差:•
標準差:•
標準化:•
第三動差:•
第四動差:μ X = E[ X ]
Var(X) = E [ (X − μ X ) 2 ] σ X = Var(X)
Z = X − μ X σ X
skewness
= E[ Z 3 ]
kurtosis
= E[ Z 4 ]
Moment
https:!//en.wikipedia.org/wiki/Skewness
https:!//en.wikipedia.org/wiki/Kurtosis
https:!//en.wikipedia.org/wiki/Central_moment
https://en.wikipedia.org/wiki/Skewness#/media/
File:Relationship_between_mean_and_median_under_different_skewness.png
z score
偏態 峰態
抽樣
Sampling從⺟體隨機抽取樣本
Population Sample
https://zh.wikipedia.org/wiki/%E6%8A%BD%E6%A8%A3#/media/File:Simple_random_sampling.PNG
台灣加權指數歷史收盤價 (未還原)
https:!//en.wikipedia.org/wiki/Sortino_ratio https:!//en.wikipedia.org/wiki/Sharpe_ratio
https:!//en.wikipedia.org/wiki/
Compound_annual_growth_rate
https:!//breakingdownfinance.com/
finance-topics/performance- measurement/calmar-ratio/
是否為常態分佈?
Hypothesis Testing
檢定
Normality Test
•
Shapiro-Wilk test•
Anderson-Darling test•
Kolmogorov-Smirnov test•
Jarque-Bera test•
Pearson’s testχ 2
https:!//en.wikipedia.org/wiki/Shapiro-Wilk_test
https:!//en.wikipedia.org/wiki/Anderson-Darling_test
https:!//en.wikipedia.org/wiki/Kolmogorov-Smirnov_test
https:!//en.wikipedia.org/wiki/Jarque-Bera_test
https:!//en.wikipedia.org/wiki/Pearson-_chi-squared_test
(´༎yД༎y`)
虛無假設
Null Hypothesis
: 是常態分佈
H 0
對立假設
Alternative Hypothesis
: 不是常態分佈
H 1
統計量
Statistic顯著性
Statistical Significance
α
常⾒的設定是 α = 0.05 或者是 α = 0.01
型⼀誤差
Type I Error
p-value
當p-value < 時,
此統計量有顯著差異,拒絕 !
α H 0
當p-value >= 時,
此統計量無顯著差異, 無法 α 拒絕 H 0 !
也就是說,我找不到⾜夠的證據來 證明 不成立! H 0
⼀開始可能會誤以為,既然沒有拒絕,代表 是對的。
但是這是錯誤的解讀。 H 0
– Ronald Fisher (1890–1962)
“... is never proved or established, but is possibly disproved, in the course of experimentation. Every
experiment may be said to exist only in order to give the facts a chance of disproving the null
hypothesis.”
型⼆誤差
Type II Error
https:!//en.wikipedia.org/wiki/Type_III_error
β
Confusion Matrix
ROC 曲線
https:!//en.wikipedia.org/wiki/Receiver_operating_characteristic
Receiver Operating Characteristic
https://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/ROC_curves.svg/1920px-ROC_curves.svg.png
型三誤差
Type III Error
https:!//en.wikipedia.org/wiki/Type_III_error
“correctly rejecting the null hypothesis for the wrong reason”
Bayes
https:!//en.wikipedia.org/wiki/Bayes'_theorem
先驗機率
Prior Probability, Belief
條件機率
Conditional Probability
P(A | B) = P(A ∩ B) P(B)
在事件B的條件下,發⽣事件A的機率
交集
⽂⽒圖
https:!//en.wikipedia.org/wiki/Venn_diagram
https://upload.wikimedia.org/wikipedia/commons/thumb/e/e4/Venn_diagram_gr_la_ru.svg/1920px-Venn_diagram_gr_la_ru.svg.png
P(A ∩ B) = P(A | B) P(B)
= P(B | A) P(A)
https://en.wikipedia.org/wiki/Bayes%27_theorem#A_more_complicated_example
獨立事件 Independence
P(A ∩ B) = P(A) P(B)
很重要,但是很難辦到!
案例:投籃命中率
案例:上漲下跌
題外話們
凱利賭徒
https:!//en.wikipedia.org/wiki/Kelly_criterion
平賭
https:!//en.wikipedia.org/wiki/Martingale_(probability_theory)
Martingale
https:!//rich01.com/blog-pos-22/