S&P500を組み合わせて最適ポートフォリオを探索する【実行結果編】

5月 29, 2021

Pythonを用いて,S&P500(米国優良企業約500社)の組合せの中から最適ポートフォリオを見つけてみました.

この記事には,そのコードの実行結果のみを書いています.

最適ポートフォリオを見つけるコードは,以下で解説しているので気になる方はご覧ください.

やったこと

・S&P500銘柄をこちらのCSVから取得し,pandas-datareaderを使って株価時系列データを取得

・取得した株価データから各銘柄の期待リターンとボラティリティ(リスク,共分散の平方根)を求め,効率的フロンティアを生成

・効率的フロンティアから,ボラティリティが最小になるポートフォリオとシャープレシオ(期待リターン/ボラティリティ)が最大になるポートフォリオを探索

・セクター別にまとめたものも出力

条件

2014年からの株価データで実行しました.そのため,2014年以降に上場した銘柄は含まれていません.

効率的フロンティア

最適ポートフォリオ

左がシャープレシオを最大,右がボラティリティを最小にするポートフォリオ

シャープレシオ最大ポートフォリオ

リターン 0.1850

ボラティリティ 0.1846

シャープレシオ 1.0018

0MMM0.001556
1AOS0.003068
2ABT0.002113
3ABBV0.004224
4ABMD0.000507
5ACN0.000816
6ATVI0.000815
7ADBE0.002034
8AAP0.000342
9AMD0.001637
10AES0.001607
11AFL0.001149
12A0.000501
13APD0.000122
14AKAM0.000744
15ALK0.002818
16ALB0.001625
17ARE0.003103
18ALXN0.001473
19ALGN0.002462
20ALLE0.001072
21LNT0.003484
22ALL0.00218
23GOOGL0.000584
24GOOG0.002793
25MO0.001948
26AMZN0.002873
27AMCR0.00076
28AEE0.000358
29AAL0.001607
30AEP0.003496
31AXP0.002364
32AIG0.003323
33AMT0.001969
34AWK0.002709
35AMP0.000841
36ABC0.001677
37AME0.00185
38AMGN0.001877
39APH0.00014
40ADI0.001526
41ANSS0.003541
42ANTM0.003514
43AON0.002561
44APA0.001469
45AAPL0.003683
46AMAT0.00438
47APTV0.002046
48ADM0.000528
49AJG0.001756
50AIZ0.001609
51T0.00181
52ATO0.002532
53ADSK0.00102
54ADP0.004231
55AZO0.003406
56AVB0.001023
57AVY0.003919
58BKR0.002553
59BLL0.003455
60BAC0.000849
61BAX0.004239
62BDX0.001088
63BBY0.003686
64BIO0.001262
65BIIB0.000633
66BLK0.001447
67BA0.001992
68BKNG0.000615
69BWA0.000595
70BXP0.00169
71BSX0.004203
72BMY0.000179
73AVGO0.002477
74BR0.003053
75CHRW0.003887
76COG0.003085
77CDNS0.001951
78CPB0.003925
79COF0.000789
80CAH0.002471
81KMX0.002217
82CCL4.28E-05
83CAT0.002233
84CBOE0.00406
85CBRE0.00032
86CDW0.001899
87CE0.004265
88CNC0.004323
89CNP0.00429
90CERN0.001175
91CF0.003116
92SCHW0.003537
93CHTR0.001109
94CVX0.002805
95CMG0.004334
96CB0.004004
97CHD0.002862
98CI0.00407
99CINF0.002421
100CTAS0.000582
101CSCO0.003652
102C0.002986
103CTXS0.002891
104CME0.002003
105CMS0.00289
106KO0.00197
107CTSH0.003769
108CL0.001071
109CMCSA0.00047
110CMA0.004167
111CAG0.00376
112COP0.002464
113ED0.003286
114STZ0.003693
115CPRT0.003543
116GLW0.002624
117COST0.001927
118CCI0.003222
119CSX0.003532
120CMI0.000712
121CVS0.000456
122DHI0.004238
123DHR0.000525
124DRI0.001384
125DVA0.003896
126DE8.07E-05
127DAL0.003044
128XRAY0.001999
129DVN0.000815
130DXCM0.002918
131FANG0.001972
132DLR0.000462
133DFS0.001756
134DISCA0.002908
135DISCK0.002019
136DISH0.004354
137DG0.002262
138DLTR0.003274
139D0.002299
140DPZ0.000336
141DOV0.001682
142DTE0.00063
143DUK0.001337
144DRE0.000277
145DD0.001515
146DXC5.80E-05
147EMN0.00325
148ETN0.00418
149EBAY0.000274
150ECL0.002474
151EIX0.000762
152EW0.000396
153EA0.004091
154EMR0.000801
155ENPH0.003513
156ETR0.000177
157EOG0.000262
158EFX0.000122
159EQIX0.003399
160EQR0.002442
161ESS0.004048
162EL0.004262
163RE0.002027
164EVRG0.001498
165ES0.001065
166EXC0.000979
167EXPE0.000745
168EXPD0.00131
169EXR0.003066
170XOM9.80E-05
171FFIV0.002664
172FB0.004414
173FAST0.001063
174FRT0.0002
175FDX0.001856
176FIS0.002155
177FITB0.000484
178FRC1.16E-05
179FE0.003954
180FISV0.001686
181FLT0.000597
182FLIR0.003762
183FMC0.000903
184F0.001881
185FTNT0.002509
186FBHS0.00399
187BEN0.001111
188FCX0.001853
189GPS0.00026
190GRMN0.002384
191IT0.004004
192GNRC0.00093
193GD0.000589
194GE0.00086
195GIS0.00064
196GM0.001713
197GPC0.001983
198GILD0.001495
199GPN0.001746
200GL0.002183
201GS0.000598
202GWW0.002425
203HAL0.000719
204HBI0.0015
205HIG2.20E-05
206HAS0.002993
207HCA0.00119
208PEAK0.000381
209HSIC0.0019
210HES0.004288
211HLT0.003415
212HFC0.003815
213HOLX0.002005
214HD0.003524
215HON0.002255
216HRL0.003015
217HST0.000502
218HPQ0.004393
219HUM0.003084
220HBAN0.004272
221HII0.00185
222IEX0.001409
223IDXX0.000724
224ITW0.002107
225ILMN0.003685
226INCY0.004037
227INTC0.00083
228ICE0.002565
229IBM0.001042
230IFF0.000451
231IP0.00193
232IPG0.004239
233INTU0.002344
234ISRG0.004355
235IVZ0.000966
236IPGP0.000872
237IQV0.001089
238IRM0.000822
239JBHT0.003782
240JKHY0.003435
241J0.001682
242SJM0.000311
243JNJ0.003771
244JCI0.000939
245JPM0.002937
246JNPR0.000615
247KSU0.003737
248K0.003308
249KEY0.002243
250KMB0.000917
251KIM0.001209
252KMI0.001916
253KLAC0.001403
254KR0.002807
255LB0.001545
256LHX0.004289
257LH0.003646
258LRCX0.003018
259LVS0.001964
260LEG6.11E-05
261LDOS0.000454
262LEN0.004406
263LLY0.003732
264LNC0.001283
265LIN0.003525
266LYV0.00151
267LKQ0.001402
268LMT0.003648
269L0.001538
270LOW0.000512
271LYB0.002385
272MTB9.60E-05
273MRO0.000886
274MPC0.00373
275MKTX0.000331
276MAR0.003508
277MMC0.001232
278MLM0.004144
279MAS0.001455
280MA0.001686
281MXIM0.001791
282MKC0.000329
283MCD0.00361
284MCK0.000309
285MDT0.000841
286MRK0.004368
287MET0.003403
288MTD0.002614
289MGM0.000284
290MCHP0.000627
291MU0.003925
292MSFT0.003874
293MAA0.001698
294MHK0.00202
295TAP0.001688
296MDLZ0.003509
297MPWR0.002057
298MNST0.002151
299MCO0.001742
300MS0.000289
301MSI0.003402
302MSCI0.003544
303NDAQ0.004258
304NTAP0.001293
305NFLX0.001439
306NWL0.002156
307NEM0.001923
308NWSA0.001168
309NWS0.003408
310NEE0.001181
311NLSN0.002508
312NKE0.002034
313NI0.002016
314NSC0.002265
315NTRS0.001135
316NOC0.000686
317NLOK0.00299
318NCLH0.001595
319NOV0.000133
320NRG0.003199
321NUE0.002911
322NVDA0.002614
323NVR7.73E-05
324NXPI0.003558
325ORLY0.00392
326OXY0.000724
327ODFL0.003476
328OMC0.001783
329OKE0.000899
330ORCL0.0031
331PCAR0.000365
332PKG0.00173
333PH0.001645
334PAYX0.001527
335PENN0.004407
336PNR0.000677
337PBCT0.002732
338PEP0.001101
339PKI0.001969
340PRGO0.00404
341PFE0.001199
342PM0.003007
343PSX0.000455
344PNW0.004281
345PXD0.003193
346PNC0.001003
347POOL0.003702
348PPG0.002053
349PPL0.001594
350PFG0.003429
351PG0.001222
352PGR0.00265
353PLD0.001635
354PRU0.003708
355PTC0.004267
356PEG0.004046
357PSA0.004177
358PHM0.003488
359PVH0.001622
360QCOM0.000271
361PWR0.001752
362DGX0.002721
363RL0.00208
364RJF0.002551
365RTX0.000691
366O0.004043
367REG0.00295
368REGN6.88E-05
369RF0.004377
370RSG0.002779
371RMD0.002018
372RHI0.002551
373ROK0.00047
374ROL0.004085
375ROP0.002218
376ROST0.003725
377RCL0.000462
378SPGI0.001234
379CRM0.003063
380SBAC0.002102
381SLB0.000148
382STX0.000671
383SEE4.72E-05
384SRE0.000603
385NOW0.003698
386SHW0.001931
387SPG0.000594
388SWKS0.001424
389SNA0.001067
390SO0.002533
391LUV0.004032
392SWK0.000284
393SBUX0.001928
394STT0.000656
395STE0.002567
396SYK0.0013
397SIVB0.001642
398SNPS0.001379
399SYY0.00254
400TMUS0.004058
401TROW0.000258
402TTWO0.000719
403TPR0.001083
404TGT0.003278
405TEL0.002221
406TDY0.004209
407TFX0.000492
408TER0.00349
409TSLA0.00302
410TXN0.001602
411TXT0.003345
412BK0.002906
413CLX0.002474
414COO0.003084
415HSY0.003822
416MOS0.000539
417TRV0.002999
418DIS0.000136
419TMO0.000837
420TJX0.002318
421TSCO0.00113
422TT0.002183
423TDG1.46E-05
424TRMB0.001709
425TFC0.001957
426TWTR0.000341
427TYL0.004396
428TSN0.003661
429USB0.002238
430UDR0.003922
431ULTA0.000737
432UAA0.000973
433UNP0.001491
434UAL0.003173
435UPS0.003035
436URI0.000525
437UNH0.002869
438UHS0.000752
439UNM0.001754
440VLO0.003912
441VTR0.000504
442VRSN0.001315
443VRSK0.000684
444VZ0.000375
445VRTX0.001287
446VFC0.002576
447VIAC7.38E-05
448VTRS0.001853
449V0.001623
450VNO2.88E-05
451VMC0.001422
452WRB0.003214
453WBA0.002848
454WMT0.000295
455WM0.003351
456WAT0.001492
457WEC6.29E-05
458WFC0.001794
459WELL0.000767
460WST0.000915
461WDC0.002171
462WU0.003933
463WAB0.000851
464WY0.001168
465WHR0.003239
466WMB0.003283
467WLTW0.003866
468WYNN0.004188
469XEL0.004295
470XLNX0.001685
471XYL0.000323
472YUM0.001529
473ZBRA0.001187
474ZBH0.003633
475ZION0.002556
476ZTS0.003414

ボラティリティ最小ポートフォリオ

リターン 0.1775

ボラティリティ 0.1821

シャープレシオ 0.9747

0MMM0.003041
1AOS0.001196
2ABT0.001024
3ABBV0.001947
4ABMD0.00166
5ACN0.004079
6ATVI0.000137
7ADBE0.001332
8AAP0.003516
9AMD0.000658
10AES0.001894
11AFL0.003172
12A0.00291
13APD0.000104
14AKAM0.001153
15ALK0.003417
16ALB0.00137
17ARE0.002833
18ALXN0.000738
19ALGN0.000135
20ALLE0.001342
21LNT0.002455
22ALL5.47E-05
23GOOGL0.003308
24GOOG0.001109
25MO0.000958
26AMZN0.003861
27AMCR0.002055
28AEE0.001187
29AAL0.002177
30AEP0.003851
31AXP0.003755
32AIG0.000528
33AMT0.00187
34AWK0.004095
35AMP0.001873
36ABC0.000453
37AME0.002474
38AMGN0.003098
39APH0.00213
40ADI0.001407
41ANSS0.001536
42ANTM0.001742
43AON0.001082
44APA0.001328
45AAPL0.003903
46AMAT0.000337
47APTV0.002937
48ADM0.000496
49AJG0.002914
50AIZ0.002282
51T0.001728
52ATO0.003316
53ADSK0.003947
54ADP0.001045
55AZO0.003622
56AVB0.00393
57AVY0.001864
58BKR0.002564
59BLL0.002271
60BAC0.002981
61BAX0.002603
62BDX0.002046
63BBY0.002842
64BIO0.000176
65BIIB0.003187
66BLK0.001546
67BA0.004273
68BKNG0.001948
69BWA0.004214
70BXP0.004292
71BSX0.003786
72BMY0.001718
73AVGO0.001187
74BR0.001221
75CHRW0.003163
76COG0.00311
77CDNS0.004167
78CPB0.001452
79COF0.000854
80CAH0.000253
81KMX0.001913
82CCL0.003719
83CAT0.00312
84CBOE0.004172
85CBRE0.002036
86CDW0.001401
87CE0.000151
88CNC0.003395
89CNP0.001863
90CERN0.000403
91CF9.95E-05
92SCHW0.002418
93CHTR0.001931
94CVX0.001959
95CMG0.003388
96CB0.002176
97CHD0.004153
98CI0.001417
99CINF2.36E-05
100CTAS0.000262
101CSCO0.003195
102C0.003684
103CTXS0.001514
104CME0.002548
105CMS0.000898
106KO0.002402
107CTSH0.001878
108CL0.000396
109CMCSA0.003671
110CMA0.000229
111CAG0.001676
112COP0.0024
113ED0.003513
114STZ0.00392
115CPRT3.61E-05
116GLW0.002612
117COST5.61E-05
118CCI0.003912
119CSX0.001116
120CMI0.000739
121CVS0.000489
122DHI0.002427
123DHR0.003892
124DRI0.000318
125DVA0.003535
126DE0.002717
127DAL0.000272
128XRAY0.00274
129DVN0.002708
130DXCM0.003378
131FANG0.002326
132DLR0.002648
133DFS0.00131
134DISCA0.000357
135DISCK0.002923
136DISH0.002152
137DG0.001601
138DLTR0.003678
139D0.003743
140DPZ0.003563
141DOV0.002452
142DTE0.001349
143DUK0.000629
144DRE0.000992
145DD0.001122
146DXC0.003641
147EMN0.000439
148ETN0.001211
149EBAY0.003739
150ECL0.004111
151EIX0.000716
152EW0.003407
153EA0.002959
154EMR0.001356
155ENPH0.000248
156ETR0.003195
157EOG0.002036
158EFX4.72E-05
159EQIX0.001039
160EQR0.003438
161ESS0.000937
162EL0.00244
163RE0.001121
164EVRG0.002806
165ES0.00222
166EXC0.000796
167EXPE0.003597
168EXPD0.001463
169EXR0.003255
170XOM0.000206
171FFIV0.001209
172FB0.001197
173FAST0.002339
174FRT0.002788
175FDX0.001294
176FIS0.003208
177FITB0.002849
178FRC0.003657
179FE0.004088
180FISV0.002754
181FLT0.002382
182FLIR0.003698
183FMC0.001434
184F0.000749
185FTNT0.003133
186FBHS0.000254
187BEN0.003961
188FCX0.001104
189GPS0.003488
190GRMN0.00113
191IT0.002694
192GNRC0.003475
193GD0.001084
194GE0.002365
195GIS0.002334
196GM0.000391
197GPC0.001395
198GILD0.003879
199GPN0.000603
200GL0.002161
201GS4.62E-05
202GWW0.000451
203HAL0.003127
204HBI0.001321
205HIG0.000437
206HAS0.001243
207HCA0.002368
208PEAK0.003152
209HSIC0.002162
210HES0.000396
211HLT0.004152
212HFC0.001797
213HOLX0.000126
214HD0.004017
215HON0.002355
216HRL0.003962
217HST0.001806
218HPQ0.000721
219HUM0.000523
220HBAN0.002971
221HII0.001182
222IEX0.002822
223IDXX0.002022
224ITW0.001697
225ILMN0.001183
226INCY0.004116
227INTC0.000467
228ICE0.004028
229IBM0.000376
230IFF0.004118
231IP0.002543
232IPG0.002501
233INTU0.003726
234ISRG0.000235
235IVZ0.000836
236IPGP0.001006
237IQV0.001185
238IRM0.000917
239JBHT0.001146
240JKHY0.002873
241J0.001034
242SJM0.003202
243JNJ0.000898
244JCI0.004197
245JPM0.000727
246JNPR0.001906
247KSU0.003265
248K0.002507
249KEY0.002985
250KMB0.000622
251KIM0.002884
252KMI0.000336
253KLAC0.002735
254KR0.004177
255LB0.000804
256LHX0.003238
257LH0.001749
258LRCX0.001948
259LVS0.001774
260LEG0.000746
261LDOS0.000934
262LEN0.001673
263LLY0.00277
264LNC0.001156
265LIN0.004247
266LYV0.002336
267LKQ0.001788
268LMT0.001301
269L0.000226
270LOW0.003878
271LYB0.002127
272MTB0.00156
273MRO0.001003
274MPC0.000496
275MKTX0.001202
276MAR0.002348
277MMC0.000481
278MLM0.00016
279MAS0.001216
280MA0.001759
281MXIM0.001049
282MKC0.003484
283MCD0.002914
284MCK0.000664
285MDT0.000355
286MRK0.00396
287MET0.002495
288MTD0.001589
289MGM0.000601
290MCHP0.004032
291MU0.000962
292MSFT0.001715
293MAA0.002443
294MHK0.001202
295TAP0.002317
296MDLZ0.002658
297MPWR0.001229
298MNST0.002344
299MCO0.001322
300MS0.000406
301MSI0.002683
302MSCI0.000123
303NDAQ0.003056
304NTAP0.00392
305NFLX0.004047
306NWL0.001139
307NEM0.002566
308NWSA0.001357
309NWS0.001148
310NEE0.004006
311NLSN0.001363
312NKE0.000641
313NI0.003075
314NSC0.001187
315NTRS0.004012
316NOC0.003632
317NLOK0.000383
318NCLH0.001678
319NOV0.001471
320NRG0.00145
321NUE0.003863
322NVDA0.003912
323NVR0.003362
324NXPI0.000851
325ORLY0.000324
326OXY0.00394
327ODFL0.003387
328OMC0.000829
329OKE0.0038
330ORCL0.003259
331PCAR0.002023
332PKG0.001394
333PH0.003663
334PAYX0.004222
335PENN0.003164
336PNR0.00291
337PBCT0.000121
338PEP0.002954
339PKI0.000521
340PRGO0.002758
341PFE1.75E-05
342PM0.000267
343PSX0.002731
344PNW0.003972
345PXD0.002428
346PNC0.002099
347POOL0.004244
348PPG0.003508
349PPL0.003425
350PFG0.002967
351PG0.003946
352PGR0.00376
353PLD0.002409
354PRU0.001192
355PTC0.001369
356PEG0.002051
357PSA0.003317
358PHM0.004215
359PVH0.002402
360QCOM0.001483
361PWR0.001642
362DGX0.00046
363RL0.002819
364RJF0.000161
365RTX0.003576
366O5.34E-05
367REG0.001276
368REGN0.003749
369RF0.001673
370RSG0.004284
371RMD0.002423
372RHI0.003589
373ROK0.002425
374ROL0.000422
375ROP0.001174
376ROST0.000346
377RCL0.002842
378SPGI0.000658
379CRM0.003063
380SBAC0.003241
381SLB0.00188
382STX0.001893
383SEE0.001153
384SRE0.003075
385NOW0.002162
386SHW0.002804
387SPG1.84E-05
388SWKS0.003023
389SNA0.002382
390SO0.004262
391LUV0.001783
392SWK0.002373
393SBUX0.000681
394STT0.002469
395STE0.002366
396SYK0.001516
397SIVB0.003039
398SNPS0.002491
399SYY0.000659
400TMUS0.003333
401TROW0.003474
402TTWO0.004106
403TPR0.001784
404TGT0.00141
405TEL0.000943
406TDY0.002435
407TFX0.004011
408TER0.001664
409TSLA0.00104
410TXN0.00061
411TXT0.000423
412BK5.63E-05
413CLX0.003706
414COO0.002855
415HSY0.00224
416MOS0.00117
417TRV0.001742
418DIS0.003391
419TMO0.002421
420TJX0.003475
421TSCO0.001356
422TT0.000656
423TDG0.002472
424TRMB0.001991
425TFC0.000603
426TWTR0.000801
427TYL0.003743
428TSN0.00376
429USB0.000155
430UDR0.003759
431ULTA0.000646
432UAA0.000373
433UNP0.004107
434UAL0.001074
435UPS0.004319
436URI0.000531
437UNH0.001881
438UHS0.003957
439UNM7.63E-05
440VLO0.003264
441VTR0.001758
442VRSN0.003821
443VRSK0.001043
444VZ0.003556
445VRTX0.002321
446VFC9.45E-05
447VIAC0.00092
448VTRS0.001684
449V0.0021
450VNO0.00304
451VMC0.003051
452WRB0.002426
453WBA0.00039
454WMT0.004024
455WM0.00423
456WAT0.002448
457WEC0.00111
458WFC0.003707
459WELL0.001077
460WST0.002261
461WDC0.00194
462WU0.003893
463WAB0.004237
464WY0.000637
465WHR0.000878
466WMB0.001058
467WLTW0.003424
468WYNN0.001837
469XEL0.000269
470XLNX0.001201
471XYL0.000513
472YUM0.000105
473ZBRA0.003757
474ZBH0.001905
475ZION0.001155
476ZTS0.002688

セクター別最適ポートフォリオ

上の最適ポートフォリオをセクター別にまとめたものです.

シャープレシオ最大

                      セクター        割合
0              Industrials  0.133726
1              Health Care  0.131538
2   Information Technology  0.159262
3   Communication Services  0.044618
4   Consumer Discretionary  0.126905
5                Utilities  0.061165
6               Financials  0.129596
7                Materials  0.052247
8              Real Estate  0.051724
9         Consumer Staples  0.065592
10                  Energy  0.043626

ボラティリティ最小

                      セクター        割合
0              Industrials  0.139383
1              Health Care  0.122160
2   Information Technology  0.149156
3   Communication Services  0.049797
4   Consumer Discretionary  0.127357
5                Utilities  0.069310
6               Financials  0.114380
7                Materials  0.048829
8              Real Estate  0.065760
9         Consumer Staples  0.067503
10                  Energy  0.046365

この結果を出力するコードについては以下の記事をご覧ください.