ทฤษฎีพอร์ตโฟลิโอสมัยใหม่

การวิเคราะห์พอร์ตโฟลิโอด้วย Python

Charlotte Werger

Data Scientist

การสร้างพอร์ตโฟลิโอที่เหมาะสมที่สุด

ไอคอนกลยุทธ์การลงทุน

การวิเคราะห์พอร์ตโฟลิโอด้วย Python

Portfolio Optimization คืออะไร?

รู้จัก Harry Markowitz

Harry Markowitz

การวิเคราะห์พอร์ตโฟลิโอด้วย Python

โจทย์การหาค่าเหมาะสม: ค้นหาน้ำหนักที่ดีที่สุด

$$ โจทย์การหาค่าเหมาะสมของ Markowitz

อธิบายเป็นภาษาธรรมดา:

  • ลดความแปรปรวนของพอร์ตโฟลิโอให้น้อยที่สุด ภายใต้เงื่อนไข:
  • ผลตอบแทนเฉลี่ยที่คาดหวังต้องไม่ต่ำกว่าค่าเป้าหมาย
  • ผลรวมของน้ำหนักต้องเท่ากับ 100%
  • น้ำหนักบางส่วนต้องมีค่าเป็นบวก
การวิเคราะห์พอร์ตโฟลิโอด้วย Python

การเปลี่ยนค่าผลตอบแทนเป้าหมายนำไปสู่ Efficient Frontier

กราฟของ Efficient Frontier

การวิเคราะห์พอร์ตโฟลิโอด้วย Python

PyPortfolioOpt สำหรับการหาค่าเหมาะสมของพอร์ตโฟลิโอ

from pypfopt.efficient_frontier import EfficientFrontier
from pypfopt import risk_models
from pypfopt import expected_returns
df=pd.read_csv('portfolio.csv')
df.head(2)
                XOM        RRC        BBY         MA        PFE       
date
2010-01-04  54.068794  51.300568  32.524055  22.062426  13.940202 
2010-01-05  54.279907  51.993038  33.349487  21.997149  13.741367
# Calculate expected annualized returns and sample covariance
mu = expected_returns.mean_historical_return(df)
Sigma = risk_models.sample_cov(df)
การวิเคราะห์พอร์ตโฟลิโอด้วย Python

ดึงข้อมูล Efficient Frontier และน้ำหนักพอร์ตโฟลิโอ

# Calculate expected annualized returns and risk
mu = expected_returns.mean_historical_return(df)
Sigma = risk_models.sample_cov(df)
# Obtain the EfficientFrontier
ef = EfficientFrontier(mu, Sigma)
# Select a chosen optimal portfolio
ef.max_sharpe()
การวิเคราะห์พอร์ตโฟลิโอด้วย Python

การหาค่าเหมาะสมแบบต่าง ๆ

# Select the maximum Sharpe portfolio
ef.max_sharpe()
# Select an optimal return for a target risk 
ef.efficient_risk(2.3)
# Select a minimal risk for a target return
ef.efficient_return(1.5)
การวิเคราะห์พอร์ตโฟลิโอด้วย Python

คำนวณความเสี่ยงและประสิทธิภาพของพอร์ตโฟลิโอ

# Obtain the performance numbers
ef.portfolio_performance(verbose=True, risk_free_rate = 0.01)
Expected annual return: 21.3%
Annual volatility: 19.5%
Sharpe Ratio: 0.98
การวิเคราะห์พอร์ตโฟลิโอด้วย Python

มาฝึกกันเถอะ!

การวิเคราะห์พอร์ตโฟลิโอด้วย Python

Preparing Video For Download...