更多分析

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 中的金融交易

Passons à la pratique !

R 中的金融交易

Preparing Video For Download...