信用リスクモデリングケーススタディ The MathWorks Computational Finance Team 2011 The MathWorks, Inc. 1
Time Table Time Agenda 15:20 15:25 Introduction 15:25 15:50 決定木による格付モデル 15:50 16:00 休憩 16:00 16:15 遷移行列とデフォルト確率 16:15 16:35 信用リスクの解析 16:35 16:50 まとめ 2
目標 : 信用リスクモデルのアプリケーション作成 信用 VaR を算出するツールを開発し Excel のアプリケーションとして組み込む Historical Data Portfolio Data 格付け Rating System クーポン レート日付業種優先順位 Market Data 利率 回収率 Transition Probabilities Credit Value at Risk 3
要求課題 計算能力 1,000 以上の債券銘柄 10,000 回のシミュレーション コスト 開発工数の削減 既存環境への適用 透明性 アルゴリズムの可読性 第三者への説明 4
Agenda 決定木による格付モデル 遷移行列とデフォルト確率 信用リスクの解析 まとめ 5
Task 1: Calibrating the rating system 過去のデータから格付分類モデルを作成 Historical Data Portfolio Data 格付け Rating System クーポン レート日付業種優先順位 Market Data 利率 回収率 Transition Probabilities Credit Value at Risk 6
Calibrating the rating system Altman の Z- スコアのための 5 つの財務指標 ID WC_TA RE_TA EBIT_TA MVE_BVTD S_TA Industry 60644 0.049 0.220 0.041 2.400 0.489 6 Rating System 手順 Ratings AA 1. データのインポート : DB / Excel 2. 線型回帰による単純な分類モデルを構築 3. ランダム フォレストを適用した分類モデルを構築 4. 分類モデルをROC 曲線 /AUCにより評価 7
Visual Query Builder データベースへのアクセス用 GUI 8
Confusion Matrix 混同行列 分類表 混同対照表 モデルの精度をあらわす表で 各成分には正しく分類された場合の数と 誤って分類された場合の数が示されている モデルによる分類 実際の分類 AAA AA A BBB BB B CCC AAA 201 192 141 46 0 0 0 AA 34 136 152 55 7 0 1 A 20 117 272 152 14 0 0 BBB 9 121 391 379 110 5 0 BB 2 31 232 413 209 38 2 B 3 5 32 107 102 51 20 CCC 7 1 3 6 17 28 68 モデルでは BB だが実際の格付は AA 9
Decision Tree 決定木 機械学習の一種で 木 構造を用いた予測方法 y f ( x, x2,, x 1 n ) の f が木構造 決定木には回帰木と分類木の 2 種類が存在 出力が連続的であれば 回帰 離散的であれば 分類 : Branch : Leaf + : Node 10
Random Forest vs. Bagging Bagging (Bootstrap Aggregating) 与えられたデータセットからブートストラップ法によって学習用サンプルデータを作成し そのサンプルデータを用いて決定木を指定された本数分だけ生成するアルゴリズム Random Forest 多数の決定木を用いた集団学習アルゴリズムの一つで Bagging という手法を発展させたもの 違いは? ( x, x2,, x Baggingは 各ブランチにて 1 n 全てに対して評価基準を計算し 最も高い変数を分岐変数として採用する ( x, x2,, x 一方 RFは 各ブランチにて 1 n からランダムに選出して評価基準を計算し 最も高い変数を分岐変数として採用する ) ) 11
Bagging Random Forest vs. Bagging アルゴリズムの違い [x 1, x 2,, x 25 ] 5 つランダム選択 [x 3, x 4, x 16, x 21, x 23 ] Gini 係数などを評価 x 3 を採択 x3 < 186.65 x3 > 186.65 変数をいくつランダムに選択するか? 開発者である Breiman は変数の数のルートの値を分岐変数の候補として選択することを推奨 Random Forest の長所 全ての変数に対して評価しないので計算コストが低い 大規模データに強い 12
ROC 曲線 : Receiver Operating Characteristic Curve 受信者動作特性曲線 ROC 曲線 : 分類の精度を表すグラフ 赤枠で囲まれるような表を考え 閾値 11 を設けます この時 11 以上を陽性 (Positive) 11 未満を陰性 (Negative) といい 5 個の F のうち 1 個が Positive 側に含まれることから偽陽性率は 0.2 で 10 個の T のうち 5 個が Positive 側に属するので真陽性率は 0.5 となります Threshold = 11 関数 perfcurve は False/True Positive Rate や AUC (Area under the curve) を計算する スコア ラベル ( 分類 ) 偽陽性率 (False Positive) 真陽性率 (True Positive) 16 T 0 0.1 15 T 0 0.2 14 F 0.2 0.2 13 T 0.2 0.3 12 T 0.2 0.4 11 T 0.2 0.5 10 F 0.4 0.5 9 T 0.4 0.6 8 T 0.4 0.7 8 T 0.4 0.8 8 T 0.4 0.9 8 F 0.6 0.9 7 F 0.8 0.9 6 T 0.8 1 5 F 1 1 13
ROC 曲線と AUC >> [x, y, t, auc] = perfcurve(labels, scores, 'T ); >> plot(x,y); >> xlabel( False Positive Rate ); ylabel('true Positive Rate'); >> text(0.5, 0.3, ['AUC = ', num2str(auc)], 'EdgeColor', 'k'); >> title('roc 曲線 '); AUC: ROC 曲線と x 軸が囲む領域の面積で AUC が 1 に近いほど分類の精度が高いことを意味する 14
格付 x 以下でデフォルトした会社の割合 CAP 曲線 Cumulative Accuracy Profile x k D D k 理想的な予測精度 1 x : 格付の低いほうから並べた順序付きランク N : 会社の総数 N k : 格付 k に属する会社の数 D k : 格付 k でデフォルトした会社の数 D : デフォルトした会社の総数 0 ランダムな予測精度 格付 x 以下に属する会社の割合 1 x k N N k 15
AR Accuracy Ratio 以下のように囲まれる面積の比で定義される値で 1 に近いほど分類モデルの精度が良いことを示す AR = の面積 の面積 16
登場した関数 R2008b R2009a confusionmat : Confusion Matrix を計算 dataset : データセット配列の作成 perfcurve : ROC 曲線や AUC などを算出 querybuilder : データベースにアクセスするためのUI regress : 線型回帰を実施 R2011a R2009a rng : 乱数生成器の初期化などのユーティリティ TreeBagger : Bagging/Random Forest 用クラス 17
Key tasks and solutions Key tasks 1. Data Management 2. Statistical Modeling Solutions 1. Database Toolbox: import from / export to database 2. Statistics Toolbox: dataset array, regression analysis, decision tree, confusion matrix, ROC curve. 18
Agenda 決定木による格付モデル 遷移行列とデフォルト確率 信用リスクの解析 まとめ 19
Task 2: Transition Probabilities 過去データに基づいた遷移確率行列を算出 Historical Data Portfolio Data 格付け Rating System クーポン レート日付業種優先順位 Market Data 利率 回収率 Transition Probabilities Credit Value at Risk 20
遷移確率行列の推定 Migration History ID Date Rating 1 07-Jul-05 A 1 31-Nov-07 BBB 2 07-Jul-05 AAA 2 02-Dec-08 AA 2 02-Dec-09 AAA 3 07-Aug-06 A 3 27-Sep-08 AA Migration Matrix 31-Dec-06 31-Dec-07 31-Dec-08 31-Dec-09 A BBB BBB BBB AAA AAA AA AAA A A AA AA Transition Probability Matrix to AAA to AA to A to BBB from AAA 0.5 0.5 0 0 from AA 0.5 0.5 0 0 from A 0 0.33 0.33 0.33 from BBB 0 0 0 1 21
遷移確率行列の推定 手順 1. テキストデータのインポートと時系列データの作成 2. Migration Matrixの生成 3. 遷移確率行列の算出と可視化 4. デフォルト確率の計算 AAA 93.68% 5.55% 0.59% 0.18% AA 2.44% 92.60% 4.03% 0.73% 0.15% 0.06% A 0.14% 4.18% 91.02% 3.90% 0.60% 0.08% 0.08% BBB 0.03% 0.23% 7.49% 87.86% 3.78% 0.39% 0.06% 0.16% BB 0.03% 0.12% 0.73% 8.27% 86.74% 3.28% 0.18% 0.64% B 0.11% 0.82% 9.64% 85.37% 2.41% 1.64% CCC 0.37% 1.84% 6.24% 81.88% 9.67% D 10 AAA AA A BBB BB B CCC D 22
transprob vs. transprobbytotals transprob: Estimation of transition probabilities from credit ratings data transprobbytotals: Estimation of transition probabilities from preprocessed credit ratings data transprobbytotals は transprob の結果を処理! 23
MATLAB Central Open exchange for the MATLAB and Simulink user community 662,000 visits per month File Exchange Upload/download access to free files including MATLAB code, Simulink models, and documents Ability to rate files, comment, and ask questions More than 9,000 contributed files, 400 submissions per month, 25,500 downloads per day Newsgroup Web forum for technical discussions about MATLAB and Simulink 200 posts per day Blogs Frequent posts from key MathWorks developers who design and build the products Open conversation at blogs.mathworks.com Based on February 2009 data 24
登場した関数 R2008a R2010b R2010b cfdates : キャッシュフロー日付の作成 fillts : Financial Time Series Objectの欠損データ補完 fints : Financial Time Series Objectを作成 intersect : 2つの集合の共通部分を抽出 (A B) ordinal : オーディナル配列の作成 parfor : for ループの並列版 transprob : 格付データから遷移確率行列を推定 transprobbytotals : 前処理済み格付データから遷移確率行列を推定 25
Key tasks and solutions AAA 93.68% 5.55% 0.59% 0.18% Key tasks 1. Improving Performance 2. Financial Analysis 3. Customized graphics AA A BBB BB B CCC D 2.44% 92.60% 0.14% 4.18% 0.03% 0.23% 0.03% 0.12% 4.03% 91.02% 7.49% 0.73% 0.11% 0.73% 3.90% 87.86% 8.27% 0.82% 0.37% 0.15% 0.60% 3.78% 86.74% 9.64% 1.84% 0.08% 0.39% 3.28% 85.37% 6.24% 0.06% 0.18% 2.41% 81.88% 0.06% 0.08% 0.16% 0.64% 1.64% 9.67% 10 AAA AA A BBB BB B CCC D Solutions 1. Parallel Computing Toolbox: parallel-for loop, etc. 2. Financial Toolbox: financial time series object, transiton probabilities. 3. MATLAB Central: File Exchange 26
Agenda 決定木による格付モデル 遷移行列とデフォルト確率 信用リスクの解析 まとめ 27
Task 3: Credit Risk Analysis 債券ポートフォリオの信用 VaR を計算 Historical Data Portfolio Data 格付け Rating System クーポン レート日付業種優先順位 Market Data 利率 回収率 Transition Probabilities Credit Value at Risk 28
Task 3: Credit risk analysis 手順 1. 債券ポートフォリオの価格算出 2. モンテカルロ シミュレーションの実行 3. シミュレーションに基づいてポートフォリオを再評価 Historical Data Portfolio Data Ratings Coupon rates Dates Industries Seniorities Rating System Market Data Interest rates Recovery rates Modeling data Transition probabilities Risk thresholds Time horizon Credit Value at Risk 29
モンテカルロ シミュレーションの実行 1 年後の格付予測 乱数を使って 1 年後の格付を予測する 1. 各格付けの閾値を設ける (Z AAA, Z AA,, Z CCC, Z D ) 2. 乱数生成器を使って確率変数 R を作る 3. Z X R Z X-1 を評価して R が属する格付けを決める ここで x, x-1 は格付けを表し x-1 は x より一つ格付けが 高い ことを意味します 30
モンテカルロ シミュレーションの実行格付けのための閾値設定 to AAA to AA to A... to D from AAA 0.94 0.05 0.01... 0 from AA 0.02 0.92 0.04... 0 from A 0.01 0.04 0.91... 0.01 : : : : : : from CCC 0 0 0... 0.10 Transition Probability Matrix P AAA +...+P D P AA +...+ P D P A +...+ P D... P D AAA 1 0.06 0.01... 0 AA 1 0.98 0.05... 0 A 1 0.99 0.96... 0.01 : : : : : : CCC 1 1 1... 0.10 31
モンテカルロ シミュレーションの実行格付けのための閾値設定 P AAA +...+P D P AA +...+ P D P A +...+ P D... P D AAA 1 0.06 0.01... 0 AA 1 0.98 0.05... 0 A 1 0.99 0.96... 0.01 : : : : : : CCC 1 1 1... 0.10 Z AAA Z AA Z A... Z D AAA - 1.52-2.42... - AA 1.97-1.65... - 3.25 A 2.99 1.72... - 3.15 : : : : : : CCC... - 1.30 32
1311 12 モンテカルロ シミュレーションの実行 乱数生成器による確率変数の作成 10000 12 の業種間に相関がある多次元正規分布に従う乱数を 10000 セット IndustryRandom = mvnrnd(zeros(12,1), Cov, 10000) IndustryRandom(6, :) IndustryRandom(4, :) : : IndustryRandom(11, :) BondRandom = α IndustryRandom(6, :) IndustryRandom(4, :) : : IndustryRandom(11,:) 2 + 1 randn(1311, 1e4) 但し α はExcel 上の Participation weight 33
モンテカルロ シミュレーションの実行確率変数がどの格付けに属するか評価 Z X BondRandom(n, :) Z X-1 を評価 たとえば n 番目の債権が AA で先に作成した閾値ベクトルが Z AAA Z AA Z A Z BBB... Z CCC Z D AA 1.97-1.65-2.34... -3.24-3.25 で 乱数により生成した BondRandom(n, :) のある成分の値が -0.2735 とすると Z A -0.2735 Z AA という関係より シミュレーションの結果は Z AA と判定される 34
シミュレーションに基づいてポートフォリオを再評価 シミュレーションの結果 格付が D 判定になった場合は Seniority ( 優先順位 ) に応じて Β 分布に従う乱数により回収率をシミュレーション ( デフォルト時の価格 ) = ( 額面価格 ) ( ( a, b) に従う乱数 ) 但し a b 2 3 2 2 2 3 2 2 2 2 35
Speeding-Up MATLAB bsxfun 関数 (m n) 行列と (m 1) ベクトル をループなしで処理 bsxfun @plus,, = 36
Speeding-Up MATLAB bsxfun 関数 (m n) 行列と (1 n) ベクトル をループなしで処理 bsxfun @times,, = 37
登場した関数 betarnd : Β 分布に従う乱数生成 bsxfun : 行列とベクトルを要素ごとに演算 R2009b prbyzero : ゼロ クーポン イールドカーブから債券価格を算出 mvnrnd : 多次元正規分布に従う乱数生成 norminv : 正規分布の逆関数 prctile : パーセンタイル値の計算 38
Key tasks and solutions Key tasks 1. Monte Carlo Simulation 2. Financial Analysis Solutions 1. Statistics Toolbox: many supported probability distributions and random number generator. 2. Financial Toolbox: bond pricing, term structure. 39
Agenda 決定木による格付モデル 遷移行列とデフォルト確率 信用リスクの解析 まとめ 40
Computational Finance Workflow Access Research and Quantify Share Files Files Databases Datafeeds Data Analysis and Visualization Data Financial Analysis Modeling & Visualization Application Development Reporting Reporting Applications Production Databases Financial Modeling Applications Spreadsheet Link EX Database Datafeed Datafeeds Fixed Income Financial Derivatives Econometrics Statistics Financial Application Development Optimization Builder EX Builder NE Builder JA Production MATLAB Compiler Report Generator MATLAB Parallel Computing MATLAB Distributed Computing Server Automate 41
標準モジュール生成と配布 Excel VBA への組込み 42
標準モジュールの配布フロー 1 Toolboxes MATLAB Compiler MATLAB デスクトップ 3 End User 2 MATLAB Builder EX 4.dll MATLAB Compiler 43
要求課題 計算能力 1,000 以上の債券銘柄 10,000 回のシミュレーション コスト 開発工数の削減 既存環境への適用 透明性 アルゴリズムの可読性 第三者への説明 44
MATLAB s solutions 計算能力 強力な計算エンジンと様々な関数 並列計算をサポート コスト 少ないコーディング作業 他言語 他のアプリへの実装 透明性 インタプリタ型言語 レポート生成機能 45
トレーニングサービス トレーニングサービス 定期トレーニング ; 東京 名古屋 大阪にて定期開催 基礎コース (11) 応用コース (11) 専門コース (4) をご提供 オンサイトトレーニング ; お客様サイトにて開催 ご要望に応じて 3 つのレベルでカリキュラムのカスタマイズが可能 投資 効果 投資対効果の最大化 46
Support and Community 47
Connections Program More than 300 add-on products and services that complement and extend MathWorks products: Specialized third-party toolboxes for MATLAB Interfaces to third-party software and hardware products Specialized training courses and consulting services System integrators and suppliers that incorporate MathWorks products 48
Book Program More than 1,000 books for educational and professional use, in 26 languages Controls Signal Processing Image Processing Biosciences Communications Mechanical Engineering Mathematics Aerospace Engineering Environmental Sciences Chemistry Finance Electronics 49
Technical Support Resources Over 100 support engineers All with MS degrees (EE, ME, CS) Local support in North America, Europe, and Asia Comprehensive, product-specific Web support resources High customer satisfaction 95% of calls answered within three minutes 70% of issues resolved within 24 hours 80% of customers surveyed rate satisfaction at 80-100% 50