進階分析

R 的金融交易

Ilya Kipnis

Professional Quantitative Analyst and R programmer

產生損益(P&L)序列

  • blotter 環境包含交易歷史
  • P&L 的語法:
portPL <- .blotter$portfolio.firststrat$summary$Net.Trading.PL
head(portPL)
           Net.Trading.PL
1999-01-01           0
2003-01-02           0
2003-01-03           0
2003-01-06           0
2003-01-07           0
2003-01-08           0
R 的金融交易

夏普比率

  • 可用策略的 P&L 取得
  • 為策略酬報對風險的比率
SharpeRatio.annualized(portPL, geometric = FALSE)
                                   Net.Trading.PL
Annualized Sharpe Ratio (Rf=0%)         0.5166274
R 的金融交易

取得報酬

  • 單筆交易之損益除以初始資本的比率
  • 取得投資組合報酬:
instrets <- 
      PortfReturns(account.st)
head(instrets, n = 3)
           LQD.DailyEndEq
2003-01-02           0
2003-01-03           0
2003-01-06           0
tail(instrets, n = 3)
            LQD.DailyEndEq
2015-12-29           0
2015-12-30           0
2003-12-31           0
R 的金融交易

為報酬計算夏普比率

SharpeRatio.annualized(instrets, geometric = FALSE)
                                  LQD.DailyEndEq
Annualized Sharpe Ratio (Rf=0%)        0.488011
R 的金融交易

一起來練習吧!

R 的金融交易

Preparing Video For Download...