(初心者作業日誌)yahooのライブラリを利用した株データの取得

### やりたいこと
- yahoo_finance_api2の関数(引数、output)の確認
    - pandas_datareaderとの違い
    - コピペだけじゃなくて何をしているのかをできるだけ見てみる
- 可視化の方法
    - グラフ系のライブラリ・関数の確認

### 参考URL
- 【日本株対応】Pythonで株価のローソク足データを取得する方法まとめ【CSV、ライブラリ、スクレイピング】
    - https://myfrankblog.com/how_to_get_stock_price_with_python/
- GitHub - pkout_yahoo_finance_api2_ API to interact with Yahoo Finance
    - https://github.com/pkout/yahoo_finance_api2
- 【Pythonコード解説】yahoo_finance_api2で日本株の株価データを取得する
    - https://myfrankblog.com/stock_price_with_yahoo_finance_api2/
- Pythonのmpl_financeで株価のローソク足チャートを描く方法【コード解説】
    - https://myfrankblog.com/stock_price_chart_with_python_mpl_finance/
- 【Matplotlibの基礎】Pythonでグラフ、図を表示する方法｜株チャートを表示 _ こがたぶろぐ
    - https://kgt-blog.com/tech-32/3342/

## yahoo_finance_api2の特徴
### メリット
- 細かいデータ(分足・時間足・日足・週足・月足)の取得が可能
- リアルタイムに近いデータが取得可能　**★ただし20分以上遅延あり**
- 日本株に対応


### デメリット
- pandas_datareaderに比べると複雑
- 調整終値がない　**←調整終値とは？？**
- 短期間で乱発すると制限がかけられる可能性あり　**←どれくらいが限度なのか確認必要**


## コーディング

### 株価の取得(1976：明星工)

#### とりあえず株価を取得してみる
```python
import sys
#sys: Pythonのインタプリタや実行環境に関する情報を扱うためのライブラリ

import pandas as pd

from yahoo_finance_api2 import share
from yahoo_finance_api2.exceptions import YahooFinanceError

my_share = share.Share('1976.T')
symbol_data = None

try:
    symbol_data = my_share.get_historical(
        share.PERIOD_TYPE_DAY, 10,            #期間の指定 →10日間
        share.FREQUENCY_TYPE_MINUTE, 5)       #頻度の指定　→5分足
except YahooFinanceError as e:
    print(e.message)
    sys.exit(1)

print(symbol_data)
```

```:結果
{'timestamp': [1695081600000, 1695081900000, 1695082200000, 1695082500000, 1695082800000, 1695083100000, 1695083400000, 1695083700000, 1695084000000, 1695084300000, 1695084600000, 1695084900000, 1695085200000, 1695085500000, 1695085800000, 1695086100000, 1695086400000, 1695086700000, 1695087000000, 1695087300000, 1695087600000, 1695087900000, 1695088200000, 1695088500000, 1695088800000, 1695089100000, 1695089400000, 1695089700000, 1695090000000, 1695090300000, 1695090600000, 1695090900000, 1695091200000, 1695091500000, 1695091800000, 1695092100000, 1695092400000, 1695092700000, 1695093000000, 1695093300000, 1695093600000, 1695093900000, 1695094200000, 1695094500000, 1695094800000, 1695095100000, 1695095400000, 1695095700000, 1695096000000, 1695096300000, 1695096600000, 1695096900000, 1695097200000, 1695097500000, 1695097800000, 1695098100000, 1695098400000, 1695098700000, 1695099000000, 1695099300000, 1695099600000, 1695099900000, 1695100200000, 1695100500000, 1695100800000, 1695101100000, 1695101400000, 1695101700000, 1695102000000, 1695102300000, 1695102600000, 1695102900000, 1695168000000, 1695168300000, 1695168600000, 1695168900000, 1695169200000, 1695169500000, 1695169800000, 1695170100000, 1695170400000, 1695170700000, 1695171000000, 1695171300000, 1695171600000, 1695171900000, 1695172200000, 1695172500000, 1695172800000, 1695173100000, 1695173400000, 1695173700000, 1695174000000, 1695174300000, 1695174600000, 1695174900000, 1695175200000, 1695175500000, 1695175800000, 1695176100000, 1695176400000, 1695176700000, 1695177000000, 1695177300000, 1695177600000, 1695177900000, 1695178200000, 1695178500000, 1695178800000, 1695179100000, 1695179400000, 1695179700000, 1695180000000, 1695180300000, 1695180600000, 1695180900000, 1695181200000, 1695181500000, 1695181800000, 1695182100000, 1695182400000, 1695182700000, 1695183000000, 1695183300000, 1695183600000, 1695183900000, 1695184200000, 1695184500000, 1695184800000, 1695185100000, 1695185400000, 1695185700000, 1695186000000, 1695186300000, 1695186600000, 1695186900000, 1695187200000, 1695187500000, 1695187800000, 1695188100000, 1695188400000, 1695188700000, 1695189000000, 1695189300000, 1695254400000, 1695254700000, 1695255000000, 1695255300000, 1695255600000, 1695255900000, 1695256200000, 1695256500000, 1695256800000, 1695257100000, 1695257400000, 1695257700000, 1695258000000, 1695258300000, 1695258600000, 1695258900000, 1695259200000, 1695259500000, 1695259800000, 1695260100000, 1695260400000, 1695260700000, 1695261000000, 1695261300000, 1695261600000, 1695261900000, 1695262200000, 1695262500000, 1695262800000, 1695263100000, 1695263400000, 1695263700000, 1695264000000, 1695264300000, 1695264600000, 1695264900000, 1695265200000, 1695265500000, 1695265800000, 1695266100000, 1695266400000, 1695266700000, 1695267000000, 1695267300000, 1695267600000, 1695267900000, 1695268200000, 1695268500000, 1695268800000, 1695269100000, 1695269400000, 1695269700000, 1695270000000, 1695270300000, 1695270600000, 1695270900000, 1695271200000, 1695271500000, 1695271800000, 1695272100000, 1695272400000, 1695272700000, 1695273000000, 1695273300000, 1695273600000, 1695273900000, 1695274200000, 1695274500000, 1695274800000, 1695275100000, 1695275400000, 1695275700000, 1695340800000, 1695341100000, 1695341400000, 1695341700000, 1695342000000, 1695342300000, 1695342600000, 1695342900000, 1695343200000, 1695343500000, 1695343800000, 1695344100000, 1695344400000, 1695344700000, 1695345000000, 1695345300000, 1695345600000, 1695345900000, 1695346200000, 1695346500000, 1695346800000, 1695347100000, 1695347400000, 1695347700000, 1695348000000, 1695348300000, 1695348600000, 1695348900000, 1695349200000, 1695349500000, 1695349800000, 1695350100000, 1695350400000, 1695350700000, 1695351000000, 1695351300000, 1695351600000, 1695351900000, 1695352200000, 1695352500000, 1695352800000, 1695353100000, 1695353400000, 1695353700000, 1695354000000, 1695354300000, 1695354600000, 1695354900000, 1695355200000, 1695355500000, 1695355800000, 1695356100000, 1695356400000, 1695356700000, 1695357000000, 1695357300000, 1695357600000, 1695357900000, 1695358200000, 1695358500000, 1695358800000, 1695359100000, 1695359400000, 1695359700000, 1695360000000, 1695360300000, 1695360600000, 1695360900000, 1695361200000, 1695361500000, 1695361800000, 1695362100000, 1695600000000, 1695600300000, 1695600600000, 1695600900000, 1695601200000, 1695601500000, 1695601800000, 1695602100000, 1695602400000, 1695602700000, 1695603000000, 1695603300000, 1695603600000, 1695603900000, 1695604200000, 1695604500000, 1695604800000, 1695605100000, 1695605400000, 1695605700000, 1695606000000, 1695606300000, 1695606600000, 1695606900000, 1695607200000, 1695607500000, 1695607800000, 1695608100000, 1695608400000, 1695608700000, 1695609000000, 1695609300000, 1695609600000, 1695609900000, 1695610200000, 1695610500000, 1695610800000, 1695611100000, 1695611400000, 1695611700000, 1695612000000, 1695612300000, 1695612600000, 1695612900000, 1695613200000, 1695613500000, 1695613800000, 1695614100000, 1695614400000, 1695614700000, 1695615000000, 1695615300000, 1695615600000, 1695615900000, 1695616200000, 1695616500000, 1695616800000, 1695617100000, 1695617400000, 1695617700000, 1695618000000, 1695618300000, 1695618600000, 1695618900000, 1695619200000, 1695619500000, 1695619800000, 1695620100000, 1695620400000, 1695620700000, 1695621000000, 1695621300000], 'open': [1060.0, 1055.0, 1050.0, 1049.0, 1045.0, 1047.0, 1049.0, 1047.0, 1048.0, 1047.0, 1047.0, 1048.0, 1045.0, 1047.0, 1047.0, 1047.0, None, 1046.0, 1044.0, 1045.0, 1044.0, 1044.0, 1044.0, 1044.0, 1045.0, 1044.0, 1047.0, 1047.0, 1048.0, 1046.0, 1045.0, 1045.0, None, None, None, None, None, None, None, None, None, None, 1043.0, 1050.0, 1050.0, 1049.0, 1048.0, 1048.0, 1048.0, 1048.0, 1048.0, 1048.0, 1049.0, 1051.0, 1051.0, 1052.0, 1051.0, None, 1052.0, 1052.0, 1052.0, None, 1052.0, 1053.0, 1053.0, 1054.0, 1053.0, 1056.0, 1056.0, 1057.0, 1057.0, 1059.0, 1062.0, 1050.0, 1049.0, 1046.0, 1045.0, 1040.0, 1040.0, 1039.0, 1039.0, 1040.0, 1042.0, 1041.0, 1040.0, 1042.0, 1041.0, 1040.0, 1041.0, 1038.0, 1038.0, 1038.0, 1039.0, 1038.0, None, 1038.0, 1037.0, 1036.0, 1035.0, 1033.0, 1033.0, 1033.0, 1031.0, 1031.0, None, None, None, None, None, None, None, None, None, None, 1031.0, 1031.0, 1029.0, 1029.0, 1029.0, 1028.0, 1029.0, 1029.0, 1030.0, 1030.0, 1027.0, 1030.0, 1030.0, 1031.0, 1029.0, 1030.0, 1030.0, 1030.0, 1029.0, 1029.0, 1029.0, 1030.0, 1028.0, 1029.0, 1029.0, 1030.0, 1032.0, 1032.0, 1032.0, 1032.0, 1015.0, 1029.0, 1032.0, 1033.0, 1035.0, 1036.0, 1032.0, 1034.0, 1035.0, 1034.0, None, None, 1035.0, 1037.0, 1036.0, 1036.0, None, None, None, 1034.0, 1033.0, None, 1034.0, None, None, 1033.0, 1031.0, None, 1030.0, 1029.0, 1029.0, 1029.0, None, None, None, None, None, None, None, None, None, None, 1029.0, 1033.0, 1035.0, 1034.0, 1034.0, 1033.0, 1034.0, 1034.0, 1033.0, 1034.0, 1034.0, None, 1034.0, 1031.0, None, 1032.0, 1031.0, 1029.0, None, 1029.0, 1031.0, 1031.0, 1032.0, 1031.0, 1030.0, 1031.0, 1033.0, 1035.0, 1033.0, 1032.0, 1017.0, 1015.0, 1016.0, 1016.0, 1014.0, 1014.0, 1015.0, 1015.0, 1016.0, 1016.0, 1015.0, 1017.0, 1018.0, 1019.0, 1020.0, 1019.0, 1019.0, 1020.0, 1020.0, 1022.0, 1022.0, 1022.0, 1021.0, 1020.0, 1019.0, 1019.0, 1019.0, 1022.0, 1021.0, 1020.0, 1018.0, 1018.0, None, None, None, None, None, None, None, None, None, None, 1018.0, 1023.0, 1024.0, 1022.0, 1022.0, 1022.0, 1023.0, 1025.0, 1024.0, 1026.0, 1025.0, 1025.0, 1024.0, None, 1022.0, 1024.0, 1025.0, 1026.0, 1027.0, 1027.0, 1029.0, 1030.0, 1028.0, 1028.0, 1029.0, 1029.0, 1030.0, 1030.0, 1029.0, 1027.0, 1035.0, 1024.0, 1026.0, 1023.0, 1026.0, 1027.0, 1027.0, 1029.0, 1027.0, 1026.0, 1029.0, 1028.0, None, 1028.0, 1029.0, 1029.0, 1028.0, 1030.0, 1028.0, None, 1029.0, 1030.0, 1029.0, 1028.0, None, 1028.0, 1028.0, None, 1028.0, 1026.0, 1025.0, 1025.0, None, None, None, None, None, None, None, None, None, None, 1025.0, 1027.0, 1026.0, None, 1026.0, None, 1027.0, None, 1027.0, None, 1027.0, None, 1026.0, 1026.0, 1026.0, 1024.0, 1023.0, None, 1024.0, 1024.0, None, 1025.0, None, 1025.0, 1027.0, 1027.0, 1027.0, 1029.0, 1028.0, 1029.0], 'high': [1060.0, 1056.0, 1051.0, 1049.0, 1047.0, 1049.0, 1049.0, 1048.0, 1048.0, 1048.0, 1049.0, 1048.0, 1047.0, 1047.0, 1048.0, 1048.0, None, 1046.0, 1044.0, 1045.0, 1045.0, 1044.0, 1045.0, 1044.0, 1045.0, 1047.0, 1047.0, 1047.0, 1048.0, 1046.0, 1045.0, 1045.0, None, None, None, None, None, None, None, None, None, None, 1049.0, 1051.0, 1050.0, 1049.0, 1048.0, 1048.0, 1048.0, 1048.0, 1048.0, 1049.0, 1050.0, 1051.0, 1051.0, 1052.0, 1051.0, None, 1052.0, 1053.0, 1052.0, None, 1053.0, 1053.0, 1054.0, 1054.0, 1055.0, 1056.0, 1057.0, 1058.0, 1058.0, 1061.0, 1062.0, 1052.0, 1049.0, 1046.0, 1045.0, 1041.0, 1042.0, 1039.0, 1040.0, 1044.0, 1042.0, 1041.0, 1041.0, 1042.0, 1041.0, 1040.0, 1041.0, 1039.0, 1038.0, 1039.0, 1039.0, 1040.0, None, 1038.0, 1037.0, 1036.0, 1035.0, 1034.0, 1034.0, 1033.0, 1031.0, 1031.0, None, None, None, None, None, None, None, None, None, None, 1031.0, 1031.0, 1030.0, 1030.0, 1029.0, 1028.0, 1030.0, 1030.0, 1030.0, 1031.0, 1030.0, 1030.0, 1031.0, 1031.0, 1029.0, 1030.0, 1030.0, 1030.0, 1029.0, 1030.0, 1029.0, 1030.0, 1028.0, 1030.0, 1031.0, 1032.0, 1032.0, 1032.0, 1033.0, 1033.0, 1033.0, 1029.0, 1035.0, 1035.0, 1036.0, 1036.0, 1035.0, 1037.0, 1035.0, 1036.0, None, None, 1037.0, 1038.0, 1036.0, 1037.0, None, None, None, 1034.0, 1035.0, None, 1034.0, None, None, 1033.0, 1031.0, None, 1030.0, 1029.0, 1029.0, 1029.0, None, None, None, None, None, None, None, None, None, None, 1034.0, 1035.0, 1035.0, 1034.0, 1034.0, 1033.0, 1034.0, 1034.0, 1034.0, 1034.0, 1034.0, None, 1034.0, 1031.0, None, 1032.0, 1031.0, 1031.0, None, 1029.0, 1031.0, 1031.0, 1032.0, 1031.0, 1032.0, 1032.0, 1033.0, 1035.0, 1033.0, 1032.0, 1020.0, 1017.0, 1017.0, 1017.0, 1017.0, 1015.0, 1015.0, 1015.0, 1017.0, 1016.0, 1015.0, 1017.0, 1019.0, 1020.0, 1020.0, 1019.0, 1019.0, 1020.0, 1022.0, 1022.0, 1023.0, 1022.0, 1021.0, 1020.0, 1020.0, 1019.0, 1021.0, 1022.0, 1022.0, 1020.0, 1018.0, 1018.0, None, None, None, None, None, None, None, None, None, None, 1025.0, 1024.0, 1024.0, 1022.0, 1022.0, 1022.0, 1024.0, 1026.0, 1024.0, 1026.0, 1025.0, 1025.0, 1024.0, None, 1024.0, 1024.0, 1025.0, 1027.0, 1027.0, 1031.0, 1029.0, 1030.0, 1028.0, 1029.0, 1029.0, 1030.0, 1031.0, 1030.0, 1029.0, 1028.0, 1035.0, 1024.0, 1026.0, 1026.0, 1027.0, 1028.0, 1028.0, 1030.0, 1027.0, 1028.0, 1029.0, 1028.0, None, 1029.0, 1030.0, 1029.0, 1030.0, 1030.0, 1029.0, None, 1029.0, 1030.0, 1029.0, 1029.0, None, 1028.0, 1028.0, None, 1028.0, 1027.0, 1025.0, 1025.0, None, None, None, None, None, None, None, None, None, None, 1027.0, 1027.0, 1026.0, None, 1026.0, None, 1028.0, None, 1028.0, None, 1027.0, None, 1026.0, 1026.0, 1026.0, 1024.0, 1025.0, None, 1024.0, 1025.0, None, 1025.0, None, 1026.0, 1027.0, 1027.0, 1028.0, 1029.0, 1029.0, 1030.0], 'low': [1051.0, 1050.0, 1049.0, 1046.0, 1044.0, 1047.0, 1048.0, 1047.0, 1048.0, 1046.0, 1046.0, 1045.0, 1045.0, 1047.0, 1047.0, 1046.0, None, 1045.0, 1043.0, 1044.0, 1044.0, 1044.0, 1044.0, 1044.0, 1044.0, 1044.0, 1047.0, 1047.0, 1047.0, 1046.0, 1045.0, 1045.0, None, None, None, None, None, None, None, None, None, None, 1043.0, 1050.0, 1048.0, 1049.0, 1048.0, 1048.0, 1048.0, 1048.0, 1047.0, 1047.0, 1049.0, 1051.0, 1051.0, 1052.0, 1051.0, None, 1052.0, 1052.0, 1052.0, None, 1051.0, 1053.0, 1052.0, 1054.0, 1053.0, 1054.0, 1056.0, 1057.0, 1057.0, 1059.0, 1052.0, 1049.0, 1046.0, 1046.0, 1042.0, 1039.0, 1040.0, 1039.0, 1038.0, 1040.0, 1041.0, 1041.0, 1040.0, 1042.0, 1041.0, 1040.0, 1039.0, 1038.0, 1037.0, 1038.0, 1039.0, 1038.0, None, 1038.0, 1037.0, 1035.0, 1034.0, 1033.0, 1033.0, 1032.0, 1031.0, 1031.0, None, None, None, None, None, None, None, None, None, None, 1029.0, 1031.0, 1029.0, 1029.0, 1029.0, 1028.0, 1027.0, 1028.0, 1030.0, 1029.0, 1027.0, 1030.0, 1030.0, 1029.0, 1029.0, 1030.0, 1029.0, 1029.0, 1029.0, 1028.0, 1029.0, 1028.0, 1028.0, 1029.0, 1029.0, 1030.0, 1032.0, 1031.0, 1031.0, 1031.0, 1015.0, 1029.0, 1032.0, 1033.0, 1035.0, 1032.0, 1032.0, 1033.0, 1035.0, 1034.0, None, None, 1035.0, 1037.0, 1036.0, 1036.0, None, None, None, 1033.0, 1033.0, None, 1033.0, None, None, 1031.0, 1031.0, None, 1029.0, 1029.0, 1029.0, 1029.0, None, None, None, None, None, None, None, None, None, None, 1029.0, 1033.0, 1035.0, 1034.0, 1034.0, 1033.0, 1034.0, 1034.0, 1033.0, 1034.0, 1033.0, None, 1032.0, 1031.0, None, 1032.0, 1029.0, 1027.0, None, 1029.0, 1031.0, 1031.0, 1030.0, 1030.0, 1030.0, 1031.0, 1033.0, 1034.0, 1032.0, 1031.0, 1016.0, 1012.0, 1015.0, 1015.0, 1013.0, 1014.0, 1015.0, 1014.0, 1016.0, 1013.0, 1015.0, 1016.0, 1018.0, 1019.0, 1019.0, 1019.0, 1019.0, 1019.0, 1020.0, 1022.0, 1022.0, 1021.0, 1020.0, 1019.0, 1019.0, 1017.0, 1018.0, 1022.0, 1021.0, 1018.0, 1018.0, 1018.0, None, None, None, None, None, None, None, None, None, None, 1018.0, 1022.0, 1023.0, 1021.0, 1021.0, 1022.0, 1022.0, 1025.0, 1023.0, 1026.0, 1024.0, 1025.0, 1023.0, None, 1022.0, 1024.0, 1025.0, 1026.0, 1026.0, 1027.0, 1029.0, 1028.0, 1028.0, 1028.0, 1028.0, 1029.0, 1030.0, 1029.0, 1027.0, 1025.0, 1021.0, 1024.0, 1023.0, 1020.0, 1026.0, 1026.0, 1027.0, 1028.0, 1027.0, 1026.0, 1027.0, 1028.0, None, 1028.0, 1029.0, 1029.0, 1027.0, 1029.0, 1028.0, None, 1028.0, 1030.0, 1028.0, 1028.0, None, 1028.0, 1028.0, None, 1027.0, 1026.0, 1025.0, 1025.0, None, None, None, None, None, None, None, None, None, None, 1025.0, 1026.0, 1026.0, None, 1026.0, None, 1027.0, None, 1027.0, None, 1027.0, None, 1026.0, 1026.0, 1024.0, 1023.0, 1023.0, None, 1023.0, 1024.0, None, 1025.0, None, 1025.0, 1026.0, 1027.0, 1027.0, 1028.0, 1028.0, 1029.0], 'close': [1055.0, 1050.0, 1051.0, 1046.0, 1046.0, 1049.0, 1049.0, 1048.0, 1048.0, 1047.0, 1049.0, 1045.0, 1047.0, 1047.0, 1047.0, 1046.0, None, 1045.0, 1043.0, 1044.0, 1045.0, 1044.0, 1045.0, 1044.0, 1044.0, 1047.0, 1047.0, 1047.0, 1047.0, 1046.0, 1045.0, 1045.0, None, None, None, None, None, None, None, None, None, None, 1049.0, 1051.0, 1049.0, 1049.0, 1048.0, 1048.0, 1048.0, 1048.0, 1047.0, 1047.0, 1050.0, 1051.0, 1051.0, 1052.0, 1051.0, None, 1052.0, 1053.0, 1052.0, None, 1053.0, 1053.0, 1053.0, 1054.0, 1055.0, 1055.0, 1056.0, 1058.0, 1058.0, 1060.0, 1052.0, 1051.0, 1049.0, 1046.0, 1042.0, 1040.0, 1040.0, 1039.0, 1040.0, 1042.0, 1041.0, 1041.0, 1041.0, 1042.0, 1041.0, 1040.0, 1039.0, 1039.0, 1037.0, 1039.0, 1039.0, 1039.0, None, 1038.0, 1037.0, 1036.0, 1035.0, 1034.0, 1033.0, 1032.0, 1031.0, 1031.0, None, None, None, None, None, None, None, None, None, None, 1029.0, 1031.0, 1030.0, 1029.0, 1029.0, 1028.0, 1028.0, 1030.0, 1030.0, 1029.0, 1030.0, 1030.0, 1031.0, 1029.0, 1029.0, 1030.0, 1029.0, 1029.0, 1029.0, 1030.0, 1029.0, 1028.0, 1028.0, 1029.0, 1030.0, 1032.0, 1032.0, 1031.0, 1033.0, 1031.0, 1033.0, 1029.0, 1035.0, 1035.0, 1036.0, 1032.0, 1035.0, 1035.0, 1035.0, 1036.0, None, None, 1037.0, 1038.0, 1036.0, 1037.0, None, None, None, 1033.0, 1035.0, None, 1033.0, None, None, 1031.0, 1031.0, None, 1029.0, 1029.0, 1029.0, 1029.0, None, None, None, None, None, None, None, None, None, None, 1034.0, 1035.0, 1035.0, 1034.0, 1034.0, 1033.0, 1034.0, 1034.0, 1034.0, 1034.0, 1033.0, None, 1032.0, 1031.0, None, 1032.0, 1029.0, 1031.0, None, 1029.0, 1031.0, 1031.0, 1030.0, 1031.0, 1031.0, 1032.0, 1033.0, 1034.0, 1032.0, 1031.0, 1016.0, 1017.0, 1017.0, 1016.0, 1017.0, 1015.0, 1015.0, 1014.0, 1016.0, 1013.0, 1015.0, 1017.0, 1019.0, 1020.0, 1019.0, 1019.0, 1019.0, 1019.0, 1022.0, 1022.0, 1022.0, 1021.0, 1020.0, 1019.0, 1020.0, 1019.0, 1021.0, 1022.0, 1022.0, 1019.0, 1018.0, 1018.0, None, None, None, None, None, None, None, None, None, None, 1025.0, 1024.0, 1023.0, 1021.0, 1022.0, 1022.0, 1024.0, 1026.0, 1024.0, 1026.0, 1024.0, 1025.0, 1023.0, None, 1024.0, 1024.0, 1025.0, 1027.0, 1026.0, 1030.0, 1029.0, 1028.0, 1028.0, 1029.0, 1029.0, 1030.0, 1031.0, 1030.0, 1027.0, 1026.0, 1021.0, 1024.0, 1023.0, 1026.0, 1027.0, 1026.0, 1028.0, 1028.0, 1027.0, 1028.0, 1027.0, 1028.0, None, 1029.0, 1029.0, 1029.0, 1030.0, 1029.0, 1028.0, None, 1029.0, 1030.0, 1029.0, 1029.0, None, 1028.0, 1028.0, None, 1027.0, 1026.0, 1025.0, 1025.0, None, None, None, None, None, None, None, None, None, None, 1026.0, 1026.0, 1026.0, None, 1026.0, None, 1027.0, None, 1027.0, None, 1027.0, None, 1026.0, 1026.0, 1024.0, 1023.0, 1025.0, None, 1023.0, 1025.0, None, 1025.0, None, 1026.0, 1026.0, 1027.0, 1028.0, 1029.0, 1029.0, 1029.0], 'volume': [0, 1800, 2900, 2500, 1400, 1100, 2100, 800, 200, 1000, 1700, 1400, 2100, 100, 1100, 900, None, 1100, 1000, 1300, 700, 500, 900, 500, 2100, 1500, 100, 100, 1200, 1200, 100, 0, None, None, None, None, None, None, None, None, None, None, 49600, 700, 2000, 100, 500, 300, 700, 100, 1300, 1700, 1100, 200, 1300, 300, 1300, None, 800, 700, 1100, None, 1000, 300, 1100, 500, 3100, 3900, 1600, 1600, 1900, 3800, 4900, 3000, 1900, 600, 3000, 2800, 1600, 300, 1500, 3000, 300, 1400, 900, 200, 500, 1400, 1400, 500, 700, 2600, 300, 2500, None, 600, 300, 1200, 400, 500, 1900, 900, 500, 0, None, None, None, None, None, None, None, None, None, None, 45200, 0, 46800, 900, 1500, 200, 4500, 1000, 100, 1500, 1000, 100, 1200, 600, 200, 1100, 200, 600, 200, 3700, 400, 700, 500, 1600, 1200, 1200, 200, 200, 4000, 3400, 3900, 100, 300, 700, 1100, 1100, 1000, 3500, 100, 600, None, None, 700, 700, 100, 700, None, None, None, 500, 900, None, 500, None, None, 1000, 200, None, 2000, 300, 100, 0, None, None, None, None, None, None, None, None, None, None, 22300, 700, 100, 300, 100, 1200, 100, 700, 300, 400, 700, None, 2800, 300, None, 100, 600, 2600, None, 100, 500, 400, 300, 1900, 2400, 800, 500, 1800, 1700, 1000, 4400, 6100, 1200, 1100, 2100, 600, 600, 700, 500, 700, 0, 19900, 300, 700, 300, 100, 200, 1100, 200, 200, 800, 300, 300, 800, 500, 900, 3300, 200, 300, 1500, 600, 0, None, None, None, None, None, None, None, None, None, None, 37000, 900, 700, 800, 500, 500, 1200, 300, 1500, 100, 200, 200, 800, None, 1300, 400, 900, 200, 300, 5300, 900, 600, 200, 2100, 1200, 1700, 4800, 1800, 2800, 2300, 7700, 200, 700, 3500, 1100, 700, 300, 1900, 100, 300, 1300, 300, None, 0, 20600, 100, 1400, 300, 500, None, 300, 800, 800, 200, None, 300, 100, None, 300, 500, 700, 0, None, None, None, None, None, None, None, None, None, None, 28500, 900, 200, None, 100, None, 900, None, 2200, None, 300, None, 400, 100, 2400, 1900, 1400, None, 1000, 800, None, 700, None, 300, 1500, 100, 1100, 1200, 4300, 2300]}
```
- データはjson形式
- pandas_datareaderに比べると確かに複雑

#### 表示形式を変換(DataFrame、Datatime、日本時間)
```python
#取得データの形式を変換(json→DataFrame)
df = pd.DataFrame(symbol_data)

#Datetimeの列を追加(timestamp→datetime変換し追加)
df["datetime"] = pd.to_datetime(df.timestamp, unit="ms")

#日本時間へ変換
import datetime 
df["datetime_JST"] = df["datetime"] + datetime.timedelta(hours=9)

df
```
```:結果
	timestamp	open	high	low	close	volume	datetime	datetime_JST
0	1695081600000	1060.0	1060.0	1051.0	1055.0	0.0	2023-09-19 00:00:00	2023-09-19 09:00:00
1	1695081900000	1055.0	1056.0	1050.0	1050.0	1800.0	2023-09-19 00:05:00	2023-09-19 09:05:00
2	1695082200000	1050.0	1051.0	1049.0	1051.0	2900.0	2023-09-19 00:10:00	2023-09-19 09:10:00
3	1695082500000	1049.0	1049.0	1046.0	1046.0	2500.0	2023-09-19 00:15:00	2023-09-19 09:15:00
4	1695082800000	1045.0	1047.0	1044.0	1046.0	1400.0	2023-09-19 00:20:00	2023-09-19 09:20:00
...	...	...	...	...	...	...	...	...
355	1695620100000	1027.0	1027.0	1027.0	1027.0	100.0	2023-09-25 05:35:00	2023-09-25 14:35:00
356	1695620400000	1027.0	1028.0	1027.0	1028.0	1100.0	2023-09-25 05:40:00	2023-09-25 14:40:00
357	1695620700000	1029.0	1029.0	1028.0	1029.0	1200.0	2023-09-25 05:45:00	2023-09-25 14:45:00
358	1695621000000	1028.0	1029.0	1028.0	1029.0	4300.0	2023-09-25 05:50:00	2023-09-25 14:50:00
359	1695621300000	1029.0	1030.0	1029.0	1029.0	2300.0	2023-09-25 05:55:00	2023-09-25 14:55:00
360 rows × 8 columns
```

- 日付情報はtimestampなのでdatatimeに変換が必要
- 日時情報はUTC。日本時間で利用するには変換が必要

#### 取得単位を変えてみる(期間、頻度)
```python

try:
    symbol_data2 = my_share.get_historical(
        share.PERIOD_TYPE_MONTH, 1,            #期間の指定 →1か月
        share.FREQUENCY_TYPE_DAY, 1)       #頻度の指定　→日足
except YahooFinanceError as e:
    print(e.message)
    sys.exit(1)

df2 = pd.DataFrame(symbol_data)
df2["datetime"] = pd.to_datetime(df.timestamp, unit="ms")
df2["datetime_JST"] = df["datetime"] + datetime.timedelta(hours=9)

df2
```

```:結果
timestamp	open	high	low	close	volume	datetime	datetime_JST
0	1695081600000	1060.0	1060.0	1051.0	1055.0	0.0	2023-09-19 00:00:00	2023-09-19 09:00:00
1	1695081900000	1055.0	1056.0	1050.0	1050.0	1800.0	2023-09-19 00:05:00	2023-09-19 09:05:00
2	1695082200000	1050.0	1051.0	1049.0	1051.0	2900.0	2023-09-19 00:10:00	2023-09-19 09:10:00
3	1695082500000	1049.0	1049.0	1046.0	1046.0	2500.0	2023-09-19 00:15:00	2023-09-19 09:15:00
4	1695082800000	1045.0	1047.0	1044.0	1046.0	1400.0	2023-09-19 00:20:00	2023-09-19 09:20:00
...	...	...	...	...	...	...	...	...
355	1695620100000	1027.0	1027.0	1027.0	1027.0	100.0	2023-09-25 05:35:00	2023-09-25 14:35:00
356	1695620400000	1027.0	1028.0	1027.0	1028.0	1100.0	2023-09-25 05:40:00	2023-09-25 14:40:00
357	1695620700000	1029.0	1029.0	1028.0	1029.0	1200.0	2023-09-25 05:45:00	2023-09-25 14:45:00
358	1695621000000	1028.0	1029.0	1028.0	1029.0	4300.0	2023-09-25 05:50:00	2023-09-25 14:50:00
359	1695621300000	1029.0	1030.0	1029.0	1029.0	2300.0	2023-09-25 05:55:00	2023-09-25 14:55:00
360 rows × 8 columns
```
- 期間指定には上限あり。100日指定→4か月指定など大きい単位で指定する

### グラフで表示する
#### グラフ表示のためのDataFrame調整
```python
import matplotlib.pyplot as plt
import mplfinance as mpf
import pandas as pd
from datetime import datetime
from datetime import timedelta

df2 = pd.DataFrame(symbol_data.values(), index=symbol_data.keys()).T    #★ここは要確認
df2.timestamp = pd.to_datetime(df2.timestamp, unit='ms')
df2.index = pd.DatetimeIndex(df2.timestamp, name='timestamp').tz_localize('UTC').tz_convert('Asia/Tokyo')

# データの形を調整(mplfinanceモジュールに合わせた列名)
df2 = df2.rename(columns = {
    'open' : 'Open',
    'high' : 'High',
    'low' : 'Low',
    'close' : 'Close',
    'volume' : 'Volume'
})

df2
```

```:結果
	timestamp	Open	High	Low	Close	Volume
timestamp						
2023-09-19 09:00:00+09:00	2023-09-19 00:00:00	1060.0	1060.0	1051.0	1055.0	0.0
2023-09-19 09:05:00+09:00	2023-09-19 00:05:00	1055.0	1056.0	1050.0	1050.0	1800.0
2023-09-19 09:10:00+09:00	2023-09-19 00:10:00	1050.0	1051.0	1049.0	1051.0	2900.0
2023-09-19 09:15:00+09:00	2023-09-19 00:15:00	1049.0	1049.0	1046.0	1046.0	2500.0
2023-09-19 09:20:00+09:00	2023-09-19 00:20:00	1045.0	1047.0	1044.0	1046.0	1400.0
...	...	...	...	...	...	...
2023-09-25 14:35:00+09:00	2023-09-25 05:35:00	1027.0	1027.0	1027.0	1027.0	100.0
2023-09-25 14:40:00+09:00	2023-09-25 05:40:00	1027.0	1028.0	1027.0	1028.0	1100.0
2023-09-25 14:45:00+09:00	2023-09-25 05:45:00	1029.0	1029.0	1028.0	1029.0	1200.0
2023-09-25 14:50:00+09:00	2023-09-25 05:50:00	1028.0	1029.0	1028.0	1029.0	4300.0
2023-09-25 14:55:00+09:00	2023-09-25 05:55:00	1029.0	1030.0	1029.0	1029.0	2300.0
360 rows × 6 columns
```

#### 単純にプロットする
```python
mpf.plot(df2)
```
![20230925.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/565599/b9ff6428-84bd-94f6-26e2-5954ff370f1b.png)


#### ～とりあえず今日はここまで～
- 次はローソク足チャートの表示
- 移動平均などの指標の入れ方(および指標の意味理解)