(投資)財報發布日

月營收:每月 10 日前

去年度財報:3 月 31 日前

第一季財報:5 月 15 日前

第二季財報:8 月 14 日前

第三季財報:11 月 14 日前

第四季財報及年報:隔年 3 月 31 日前

yfinance

 import yfinance as yf


msft = yf.Ticker("MSFT")


# get all stock info

msft.info


# get historical market data

hist = msft.history(period="1mo")


# show meta information about the history (requires history() to be called first)

msft.history_metadata


# show actions (dividends, splits, capital gains)

msft.actions

msft.dividends

msft.splits

msft.capital_gains  # only for mutual funds & etfs


# show share count

# - yearly summary:

msft.shares

# - accurate time-series count:

msft.get_shares_full(start="2022-01-01", end=None)


# show financials:

# - income statement

msft.income_stmt

msft.quarterly_income_stmt

# - balance sheet

msft.balance_sheet

msft.quarterly_balance_sheet

# - cash flow statement

msft.cashflow

msft.quarterly_cashflow

# see `Ticker.get_income_stmt()` for more options


# show holders

msft.major_holders

msft.institutional_holders

msft.mutualfund_holders


# show earnings

msft.earnings

msft.quarterly_earnings


# show sustainability

msft.sustainability


# show analysts recommendations

msft.recommendations

msft.recommendations_summary

# show analysts other work

msft.analyst_price_target

msft.revenue_forecasts

msft.earnings_forecasts

msft.earnings_trend


# show next event (earnings, etc)

msft.calendar


# Show future and historic earnings dates, returns at most next 4 quarters and last 8 quarters by default. 

# Note: If more are needed use msft.get_earnings_dates(limit=XX) with increased limit argument.

msft.earnings_dates


# show ISIN code - *experimental*

# ISIN = International Securities Identification Number

msft.isin


# show options expirations

msft.options


# show news

msft.news


# get option chain for specific expiration

opt = msft.option_chain('YYYY-MM-DD')

# data available via: opt.calls, opt.puts

If you want to use a proxy server for downloading data, use:


import yfinance as yf


msft = yf.Ticker("MSFT")


msft.history(..., proxy="PROXY_SERVER")

msft.get_actions(proxy="PROXY_SERVER")

msft.get_dividends(proxy="PROXY_SERVER")

msft.get_splits(proxy="PROXY_SERVER")

msft.get_capital_gains(proxy="PROXY_SERVER")

msft.get_balance_sheet(proxy="PROXY_SERVER")

msft.get_cashflow(proxy="PROXY_SERVER")

msft.option_chain(..., proxy="PROXY_SERVER")

...

Multiple tickers

To initialize multiple Ticker objects, use


import yfinance as yf


tickers = yf.Tickers('msft aapl goog')


# access each ticker using (example)

tickers.tickers['MSFT'].info

tickers.tickers['AAPL'].history(period="1mo")

tickers.tickers['GOOG'].actions

To download price history into one table:


import yfinance as yf

data = yf.download("SPY AAPL", start="2017-01-01", end="2017-04-30")

yf.download() and Ticker.history() have many options for configuring fetching and processing, e.g.:


yf.download(tickers = "SPY AAPL",  # list of tickers

            period = "1y",         # time period

            interval = "1d",       # trading interval

            prepost = False,       # download pre/post market hours data?

            repair = True)         # repair obvious price errors e.g. 100x?

Review the Wiki for more options and detail.


Smarter scraping

To use a custom requests session (for example to cache calls to the API or customize the User-agent header), pass a session= argument to the Ticker constructor.


import requests_cache

session = requests_cache.CachedSession('yfinance.cache')

session.headers['User-agent'] = 'my-program/1.0'

ticker = yf.Ticker('msft', session=session)

# The scraped response will be stored in the cache

ticker.actions

Combine a requests_cache with rate-limiting to avoid triggering Yahoo's rate-limiter/blocker that can corrupt data.


from requests import Session

from requests_cache import CacheMixin, SQLiteCache

from requests_ratelimiter import LimiterMixin, MemoryQueueBucket

from pyrate_limiter import Duration, RequestRate, Limiter

class CachedLimiterSession(CacheMixin, LimiterMixin, Session):

    pass


session = CachedLimiterSession(

    limiter=Limiter(RequestRate(2, Duration.SECOND*5),  # max 2 requests per 5 seconds

    bucket_class=MemoryQueueBucket,

    backend=SQLiteCache("yfinance.cache"),

)

Managing Multi-Level Columns

The following answer on Stack Overflow is for How to deal with multi-level column names downloaded with yfinance?


yfinance returns a pandas.DataFrame with multi-level column names, with a level for the ticker and a level for the stock price data

The answer discusses:

How to correctly read the the multi-level columns after saving the dataframe to a csv with pandas.DataFrame.to_csv

How to download single or multiple tickers into a single dataframe with single level column names and a ticker column

pandas_datareader override

If your code uses pandas_datareader and you want to download data faster, you can "hijack" pandas_datareader.data.get_data_yahoo() method to use yfinance while making sure the returned data is in the same format as pandas_datareader's get_data_yahoo().


from pandas_datareader import data as pdr


import yfinance as yf

yf.pdr_override() # <== that's all it takes :-)


# download dataframe

data = pdr.get_data_yahoo("SPY", start="2017-01-01", end="2017-04-30")

Timezone cache store

When fetching price data, all dates are localized to stock exchange timezone. But timezone retrieval is relatively slow, so yfinance attemps to cache them in your users cache folder. You can direct cache to use a different location with set_tz_cache_location():


import yfinance as yf

yf.set_tz_cache_location("custom/cache/location")

...


HTML

段落標簽 : <p></p>

換行標籤 : <br>

CSS

 CSS Selector:


可以讓檔案知道,在下面內容中,有哪一個HTML Element是需要被它指到的。


CSS Statement的寫法就是 property:value;



「#」是指向id的,

「.」是指向class的。

(程式)物件導向程式

一般程式是 變數+函數

物件導向程式是 變數+函數+集合,三者混用

物件導向的集合叫做類別(class),集合裡的單元叫做 物件(object )。

集合裡可以有屬性,且集合裡的物件想當然有這些屬性。

範例來自 :
https://www.zetria.org/view.php?subj=programming&chap=3zzmik9mct

現在有一個集合,user , constructor(age, name, level, account, password) ,

建立user的屬性。

集合裡面還有一些函數。




/* 宣告類別:使用者 */
類用戶{
   /* 建構物件 */
   /* 輸入使用者資料 */
   /* 並將其存成屬性 */

   constructor(年齡、姓名、級別、賬號、密碼){
      這個。年齡=年齡;
      this.name = 名稱;
      this.level = 水平;
      this.account = 賬戶;
      this.password = 密碼;
   }
   登錄名(賬號,密碼){
      /* 確認帳號密碼正確 */
      如果(賬戶){
         如果(密碼==這個。密碼){
            print("登錄成功!");
            /* 呼叫greet 方法*/
            /* 與使用者打招呼 */
            這個。問候語();
         }
      }
   }
   /* 與使用者打招呼 */
   迎接(){
      print("歡迎回來,");
      打印(這個。名字);
   }
   /* 印出使用者等級 */
   顯示水平(){
      打印(此級別);
   }
   /* 將使用者等級加 1 */
   添加級別(){
      這個.level++;
   }
   /* 將使用者年齡加 1 */
   添加年齡(){
      這個年齡++;
   }
}


函式多載

允許同一個函數名,輸入不同的變數,輸出不同結果。



範例:C++ 中的函式多載

#include <iostream>

int Volume(int s) { // 立方體的體積。
  返回 s * s * s;
}

double Volume(double r, int h) { // 圓柱體的體積。
  返回 3.1415926 * r * r * static_cast<double>(h);
}

long Volume(long l, int b, int h) { // 長方體的體積。
  返回 l * b * h;
}

詮釋主要(){
  std::cout << 體積(10);
  std::cout << 體積 (2.5, 8);
  std::cout << 體積(100l, 75, 15);
}




方法覆寫

子集合裡的函數可以覆蓋掉父集合的函數輸出。

多形
多型性(Polymorphism)的概念,又可分為多載(Overloading)和複寫(Overriding)

用子類別實作出各式各樣不同的方法,藉此讓父類別的方法藉此達到延伸和多樣化的效果。

















重灌 Windows 10 之前,5紀錄你目前已安裝的應用程式、軟體名稱

 首先,打開命令提示字元(你可以在左下角 Windows 搜尋中輸入 CMD),然後依序輸入以下三行指令:

  1. wmic
  2. /output:C:\list.txt product get name, version
  3. 跑完之後輸入 exit 跳出

python 筆記 (零)

 pip安裝套件列表 : pip install -r requirement.txt

pip 匯出套件列表: pip freeze > requirement.txt


創建物件時第一個字通常大寫 EX: df=pd.Dataframe()

pcman 字型設定

 細明體 ExtB 標準   大小28

python 筆記 (二)

 


User-Agent

User-Agent 請求標頭(request header)含有能令網路協議同級層(peer)識別發出該用戶代理 (en-US)請求的軟體類型或版本號、該軟體使用的作業系統、還有軟體開發者的字詞串。





Requests 函式庫

requests 函式庫 ( 模組 ) 是相當流行的 Python 外部函式庫,具備了 GET、POST...等各種 request 用法,透過 requests 能夠輕鬆抓取網頁的資料 

python 筆記 (一)

// 商數(整數) ** 次方

!= 不等於

b = a[i:j:k]
表示 a[i] 複製到 a[j-1],以 k 的間距取樣。
省略k時,預設為1。

: 表示從a到 b ,空白預設 '0' 或 全部

a=[0,1,2,3]

a[1:] >>> [1,2,3]

a[:] =a[::] >>>[0,1,2,3]

a[1:5] >>> [1,2,3,4]

a=list(range(10))

>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

k<0 從最後開始計算

b=a[:-1]
print(b)
>>>[0, 1, 2, 3, 4, 5, 6, 7, 8]

c=a[2::-1]
print(c)
>>> [2, 1, 0]

d=a[:5:-2]
print(d)
>>>[9, 7]



\n 換行符號,字串中使用。

s='這是第一行\n這是第二行'
print(s)

>>>這是第一行
   這是第二行

''' :長引號,按照原有的排版格式存放到字串中


t= '''這是第一行
這是第二行
這是第三行
'''
print(t)

>>>
這是第一行
這是第二行
這是第三行

在print ()中 sep 是區隔符號
print (10,20,30,sep=’+’)


多行註解:
在每一行行的開頭加入#,選取多行程式碼區塊後,按下快捷鍵(ctrl+/)
在每一行行的開頭加入#,選取多行程式碼區塊後,按下快捷鍵(ctrl+/)









(投資)財報名詞


股東權益報酬率 (ROE) = 稅後淨利 / 股東權益

現金股利殖利率= 現金股利  /股票價格

保留盈餘成長率=ROE×(1-現金股利發放率)

附錄

附錄 A 集合 (APPENDIX A SETS) 一個 集合 (set) 是一些被稱為該集合之 元素 (elements) 的物件的聚集。如果 x 是集合 A 的一個元素,那麼我們寫作 x \in A ;否則,我們寫作 x \notin A 。例如,如果 Z...