Python Get Historical Stock Prices With Yfinance
November 2, 2020import yfinance as yf
yticker = yf.Ticker("MSFT")
df = yticker.history(period="3y") # max, 3mo, etc
# print(df.columns)
# ['Open', 'High', 'Low', 'Close', 'Volume', 'Dividends', 'Stock Splits'
print(df)
'''
Open High ... Dividends Stock Splits
Date ...
2017-10-31 80.666197 80.666197 ... 0.0 0
2017-11-01 80.015972 80.092470 ... 0.0 0
2017-11-02 79.700420 80.761818 ... 0.0 0
2017-11-03 80.398455 80.838313 ... 0.0 0
2017-11-06 80.513203 80.991310 ... 0.0 0
... ... ... ... ... ...
2020-10-26 213.850006 216.339996 ... 0.0 0
2020-10-27 211.589996 214.669998 ... 0.0 0
2020-10-28 207.669998 208.839996 ... 0.0 0
2020-10-29 204.070007 207.360001 ... 0.0 0
2020-10-30 203.500000 204.289993 ... 0.0 0
'''
for index, row in df.iterrows():
# 2017-10-31 00:00:00 80.6661972680961 80.6661972680961 79.47093001044333 79.5378646850586 27086600.0
print(index, row['Open'], row['High'], row['Low'], row['Close'], row['Volume'])
- algo-trading
- algolia
- analytics
- android
- android-ktx
- android-permission
- android-studio
- apps-script
- bash
- binance
- bootstrap
- bootstrapvue
- chartjs
- chrome
- cloud-functions
- coding-interview
- contentresolver
- coroutines
- crashlytics
- crypto
- css
- dagger2
- datastore
- datetime
- docker
- eslint
- firebase
- firebase-auth
- firebase-hosting
- firestore
- firestore-security-rules
- flask
- fontawesome
- fresco
- git
- github
- glide
- godot
- google-app-engine
- google-cloud-storage
- google-colab
- google-drive
- google-maps
- google-places
- google-play
- google-sheets
- gradle
- html
- hugo
- inkscape
- java
- java-time
- javascript
- jetpack-compose
- jetson-nano
- kotlin
- kotlin-serialization
- layout
- lets-encrypt
- lifecycle
- linux
- logging
- lubuntu
- markdown
- mate
- material-design
- matplotlib
- md5
- mongodb
- moshi
- mplfinance
- mysql
- navigation
- nginx
- nodejs
- npm
- nuxtjs
- nvm
- pandas
- payment
- pip
- pwa
- pyenv
- python
- recylerview
- regex
- room
- rxjava
- scoped-storage
- selenium
- social-media
- ssh
- ssl
- static-site-generator
- static-website-hosting
- sublime-text
- ubuntu
- unit-test
- uwsgi
- viewmodel
- viewpager2
- virtualbox
- vue-chartjs
- vue-cli
- vue-router
- vuejs
- vuelidate
- vuepress
- web-development
- web-hosting
- webpack
- windows
- workmanager
- wsl
- yarn