Additional analytics

Financial Trading in R

Ilya Kipnis

Professional Quantitative Analyst and R programmer

Generate profit & loss (P&L) series

  • The blotter environment contains history of transactions
  • Syntax for 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
Financial Trading in R

Sharpe ratio

  • Can be obtained using P&L from your strategy
  • Is the ratio of reward to risk from your strategy
SharpeRatio.annualized(portPL, geometric = FALSE)
                                   Net.Trading.PL
Annualized Sharpe Ratio (Rf=0%)         0.5166274
Financial Trading in R

Getting returns

  • Ratio between profit or loss on a given trade, divided by initial equity
  • Obtaining portfolio returns:
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
Financial Trading in R

Getting Sharpe ratio for returns

SharpeRatio.annualized(instrets, geometric = FALSE)
                                  LQD.DailyEndEq
Annualized Sharpe Ratio (Rf=0%)        0.488011
Financial Trading in R

Let's practice!

Financial Trading in R

Preparing Video For Download...