2018年1月25日星期四

Python For Finance 2:Deverlopment Environment Setting

運行環境

下載好必要套件,就要設定好開發環境。
試用一下Visual studio code。
其實應該用一個簡單的Python IDE,安裝後就能即用的。
VS code裡還要設定很多,才能用。



-Install Python Extension
-設定task.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Run Python",
"type": "shell",
"command": "python",
"args": [
"${file}"
],
"presentation": {
"reveal": "always"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
雖然最後都成功運行,但好麻煩…..
Example code:
import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
style.use('ggplot')
start = dt.datetime(2018, 1, 1)
end = dt.datetime(2018, 1, 25)
df = web.DataReader('0005.HK', "yahoo", start, end)
print(df.head())

Notes

-要pip install pandas_datareader
-如查香港的股票,要4個數目字加.HK,如要看聯想,就是0992.HK
-df是Pandas所定義的一個Object,類似database。
-head() –>顯示頭5行
-Python真的好方便,幾句代碼就能得出想要的資料。
-要花點時間看看Pandas的文件。

Reference:

Tutorial
https://pythonprogramming.net/getting-stock-prices-python-programming-for-finance/








































沒有留言:

發佈留言