<ソースコード>
# 日経平均の曜日別変化率を調べる import pandas_datareader.data as web import pandas as pd import datetime for i in range(1990, 2021, 1): # 日経平均株価を取得する nikkei = web.DataReader("NIKKEI225", "fred", "1950/5/16") print(i) year = str(i) start = year + '-01-01' end = year + '-12-31' nikkei['date'] = nikkei.index nikkei = nikkei[nikkei['date'] > start] nikkei = nikkei[end > nikkei['date']] nikkei['dotw'] = nikkei['date'].dt.dayofweek nikkei = nikkei.dropna(how='any') nikkei['change'] = nikkei['NIKKEI225'].pct_change() nikkei['change2'] = nikkei['change'].shift(-1) print(nikkei[nikkei['dotw'] == 0]['change2'].mean()) print(nikkei[nikkei['dotw'] == 1]['change2'].mean()) print(nikkei[nikkei['dotw'] == 2]['change2'].mean()) print(nikkei[nikkei['dotw'] == 3]['change2'].mean()) print(nikkei[nikkei['dotw'] == 4]['change2'].mean())
月 | 火 | 水 | 木 | 金 | |
1990 | 0.019545298 | -0.34040474 | -0.150879601 | -0.234566626 | -0.150626938 |
1991 | -0.05108079 | 0.057110046 | 0.10532893 | 0.188612597 | -0.346324431 |
1992 | -0.312555701 | -0.104199725 | 0.681170016 | -0.232691922 | -0.604166991 |
1993 | -0.016545164 | -0.069862757 | 0.510365856 | 0.004013032 | -0.317294992 |
1994 | 0.148648999 | 0.034074285 | 0.134967546 | -0.017807491 | -0.013071476 |
1995 | 0.166654056 | 0.047240286 | 0.078334141 | -0.075359195 | -0.154421392 |
1996 | 0.236075702 | 0.028371386 | -0.099575032 | -0.04730186 | -0.186079671 |
1997 | 0.367730813 | 0.11096995 | -0.229975636 | -0.504972807 | -0.124341782 |
1998 | 0.251871983 | 0.273671057 | -0.32604785 | -0.303317587 | 0.011278197 |
1999 | 0.101192418 | -0.032115378 | 0.205102864 | 0.122924067 | 0.344996843 |
2000 | -0.161242494 | -0.090097419 | -0.584858314 | -0.083105091 | 0.356733857 |
2001 | 0.398834472 | -0.305781733 | 0.11043261 | 0.070008373 | -0.704218869 |
2002 | -0.482387173 | -0.190718358 | 0.317927774 | -0.095061033 | -0.038087324 |
2003 | 0.020047085 | 0.076581177 | -0.099319217 | 0.147420959 | 0.318551367 |
2004 | 0.030071294 | 0.102719222 | -0.163120496 | 0.218233 | -0.029683064 |
2005 | 0.10536214 | 0.075529146 | 0.030386862 | 0.226637127 | 0.275074889 |
2006 | -0.034277973 | -0.161193563 | 0.389476273 | 0.164509483 | -0.231475876 |
2007 | 0.057378399 | -0.296477969 | 0.284927706 | -0.253813097 | 0.00365941 |
2008 | -0.549316967 | 0.108922053 | -0.282162691 | -0.597986177 | 0.434327555 |
2009 | 0.033700243 | 0.221653065 | 0.066704992 | 0.22364731 | -0.155780905 |
2010 | -0.318953371 | 0.070774521 | 0.303752686 | -0.227541247 | 0.091762072 |
2011 | -0.365084139 | 0.241271629 | -0.014843797 | -0.01557826 | -0.254504841 |
2012 | 0.088648112 | 0.182814655 | 0.24059582 | -0.034030273 | -0.065031746 |
2013 | 0.227755483 | 0.096956234 | -0.093257902 | 0.487819241 | 0.219369549 |
2014 | 0.0952604 | 0.280388705 | -0.08514023 | 0.079346508 | -0.113258512 |
2015 | -0.157780412 | 0.257307903 | 0.311089359 | 0.065575619 | -0.233793665 |
2016 | -0.031438859 | -0.108575541 | -0.070137105 | -0.131891039 | 0.485329602 |
2017 | 0.034416954 | 0.087210738 | 0.041318128 | 0.099929721 | 0.052691226 |
2018 | -0.009052744 | -0.004050614 | -0.087475067 | -0.018348836 | -0.171580488 |
2019 | 0.207064309 | -0.037638384 | -0.08908817 | 0.162379124 | 0.191178103 |
2020 | 0.692284799 | 0.094028064 | -0.398285743 | -0.167217238 | -0.076929702 |
火曜日が全体的に期待値高そうな感じですね
コメント