量化基本面-找出風險股(1)

Sina_席納
15 min readApr 11, 2024

明智的投資需要具有辨識不僅是有前景的機會,而且還有潛在投資陷阱的眼光。通過量化基本面方法,一種將量化分析與深入的財務審查相結合的方法,可以實現這種微妙的平衡。

通過將此策略應用於標普500指數,找出風險較高的股票,從而引導投資者避開潛在的損失。這過程分為四個步驟,用以識別和評估來自表現不佳行業或顯示財務困難跡象的公司。

  1. 行業表現評估

1.1. 獲取標普500公司及其行業

過程首先從維基百科提取標普500公司及其各自行業的列表。這一步對於了解更廣泛的市場格局並為更細緻的分析奠定基礎至關重要。

# Fetch the Wikipedia page and extract S&P 500 companies and their industries
url = "https://en.wikipedia.org/wiki/List_of_S%26P_500_companies"
page = requests.get(url)
soup = BeautifulSoup(page.content, "html.parser")

# Extract tickers and industries
table = soup.find('table', {'class': 'wikitable sortable'})
tickers = []
industries = []
company_names = []
for row in table.findAll('tr')[1:]:
company_name = row.find_all('td')[1].text.strip()
ticker = row.find_all('td')[0].text.strip()
industry = row.find_all('td')[2].text.strip()
company_names.append(company_name)
tickers.append(ticker)
industries.append(industry)

# Combine tickers and industries into a DataFrame
df_SP500 = pd.DataFrame({
'Company': company_names,
'Ticker': tickers,
'Industry': industries
})


# Fetch historical performance data for each company
end_date = datetime.today()
start_date = end_date - timedelta(days=250)

1.2. 識別表現最差的行業 使用過去約250天的股票價格數據,計算每家公司的股票價格百分比變化。

所使用的公式為:

# Function to fetch historical data
def fetch_performance(ticker):
stock = yf.Ticker(ticker)
hist = stock.history(start=start_date, end=end_date)
if not hist.empty…

--

--