0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

日本円米ドルのデータ分析

Last updated at Posted at 2019-11-13

0 注意

  この記事は知識の共有目的ではなく、プログラミングしていく過程で自身の過去の作業を見返す必要があるときに備え、記録しておく為のものです。
  そのため必要最低限のメモとファイルの引用しかしておらず、Qiitaの記事を参考にして日本円米ドルのデータ分析を行うことを目的とする方は、別の投稿者の記事を参考にすることを強く推奨します。
  

1 csvファイルからpandasで読み込み

「日付け」のデータ型がstrだったのでdatetimeに調整。

test01.py

def main():
    fname01 = "USDJPY_test01.csv"

    df = pd.read_csv(fname01,sep=',')
    df['日付け'] = pd.to_datetime(df['日付け'],format='%Y年%m月%d日')

# 実行結果
# 日付け      終値      始値      高値      安値    前日比%
# 0 2019-03-05  111.89  111.72  112.12  111.70   0.13%
# 1 2019-03-04  111.75  111.77  112.02  111.64  -0.15%
# 2 2019-03-01  111.92  111.39  112.08  111.33   0.48%
# 3 2019-02-28  111.39  111.00  111.50  110.66   0.35%
# 4 2019-02-27  111.00  110.58  111.08  110.36   0.38%

# 日付け     datetime64[ns]
# 終値             float64
# 始値             float64
# 高値             float64
# 安値             float64
# 前日比%            object
# dtype: object

2 変化率の分析

  ある日に数値が大きく上昇または下降した場合、次の日はその逆の動きをする説を検証したい。

2.1 変化率をヒストグラムでプロットして表示。

test01.py

    df['前日比%'].plot.hist(bins=200,range=(-2,2))
    plt.show()

Figure_1.png

予想してはいたが、正規分布に近い形になっている。

2.2 変化率の大きさと次の日の動きの相関係数を調べる。

test01.py

    l=[]
    for i in range(0,200,1):
        #cnt1: しきい値よりも変化率が大きい かつ 次の日に前日の動きと逆の動きをした 日数
        cnt1 = df[((df['前日比%'] >= i*0.01)&(df['前日比%'].shift(1)<0) ) | ((df['前日比%'] <= i*-0.01)&(df['前日比%'].shift(1)>0) ) ]
        #cnt2: しきい値よりも変化率が大きい日数
        cnt2 = df[(df['前日比%'] >= i*0.01) | (df['前日比%'] <= i*-0.01) ]
        l.append(cnt1['日付け'].count()/cnt2['日付け'].count()*100)

    res=pd.DataFrame({'d1': [i * 0.01 for i in range(0,200,1)],
                      'd2': l    })

    print(res.corr())
    print(res[res['d2'] >= 60])

    #res['d2'].plot.hist()
    res.plot(kind='scatter',x='d1',y='d2')
    plt.show()

    #実行結果
    #    d1        d2
    #d1  1.000000  0.707159
    #d2  0.707159  1.000000

Figure_2.png

変化率の最大値は5.35だった。
 変化率のしきい値を0~5.35で変化させ、変化率が大きくなればなるほど、次の日にその変化率とは逆の動きをする確率が高くなるのかをしきい値ごとに調べた。
結果は相関係数は0.70でやや相関があるといった様子。
しかし、散布図を見るにしきい値が4.0以上のあたりのデータが不適切である。
この部分を除いて相関を考えると、とても弱いことが分かる。
より正確な確率を求めるため度数分布を用いてみる。

2.2 度数分布の作成

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?