BenchmarkAnalysis         package:fMultivar         R Documentation

_U_t_i_l_i_t_i_e_s _a_n_d _B_e_n_c_h_m_a_r_k _A_n_a_l_y_s_i_s

_D_e_s_c_r_i_p_t_i_o_n:

     A collection and description of utility  and benchmark functions
     for the analysis  of financial markets. The collection  provides a
     set of functions for the  computation of returns, for the display 
     of price charts, and for benchmark measurements. 

     The functions are:

       'getReturns'     Computes returns given a price series,
       'ohlcPlot'       Plots open-high-low-close bar charts,
       'sharpeRatio'    Computes Sharpe Ratio,
       'sterlingRatio'  Computes Sterling Ratio,
       'maxDrawDown'    Computes maximum drawdown.

_U_s_a_g_e:

     getReturns(x, type = c("continuous", "discrete"), percentage = FALSE, 
         trim = TRUE)
         
     ohlcPlot(x, xlim = NULL, ylim = NULL, xlab = "Time", ylab, col = par("col"),
         bg = par("bg"), axes = TRUE, frame.plot = axes, ann = par("ann"),
         main = NULL, date = c("calendar", "julian"), format = "%Y-%m-%d",
         origin = "1899-12-30", ...)
         
     sharpeRatio(x, r = 0, scale = sqrt(250))
     sterlingRatio(x)

     maxDrawDown(x)

_A_r_g_u_m_e_n_t_s:

date, format, origin: [ohlcPlot] - 
           date elements,
           'date', a string indicating the type of x axis annotation. 
          Default is calendar dates. 
           'format', a string indicating the format of the x axis 
          annotation if 'date == "calendar"'. For details see
          'format.POSIXct'. 
           'origin' an R object specifying the origin of the Julian 
          dates if 'date == "calendar"'. Defaults to 1899-12-30 
          (Popular spreadsheet programs internally also use Julian
          dates  with this origin). 

percentage: [getReturns] - 
           a logical flag. If set to 'TRUE', the return series will  be
          expressed in percentage points otherwise not. The default  is
          'FALSE'.  

       r: [sharpeRatio] - 
           the risk free rate. Default corresponds to using portfolio
          returns not in excess of the riskless return. 

   scale: [sharpeRatio] - 
           a scale factor. Default corresponds to an annualization when
          working with daily financial time series data. 

    trim: [getReturns] - 
           a logical flag. If set to 'TRUE', the first missing 
          observation in the return series will be removed. The 
          default is 'TRUE'. 

    type: [getReturns] - 
           a character string specifying the type of returns to be 
          computed. If 'type="continuous"', the returns are calculated 
          as the logarithm differences; if 'type="discrete"', the 
          returns are calculated as percentage changes. 

       x: a numeric vector of prices. For 'ohlcPlot' a multivariate
          time series object of  class 'mts' is required. 

xlim, ylim, xlab, ylab, col, bg, axes, frame.plot, ann, main: [ohlcPlot
          ] - 
           graphical arguments, see 'plot', 'plot.default' and 'par'. 

     ...: [ohlcPlot] - 
           further graphical arguments passed to 'plot.window', 
          'title', 'axis', and 'box'. 

_D_e_t_a_i_l_s:

     *Open-High-Low-Close Chart:* 

      Within an open-high-low-close bar chart, each bar represents
     price information for the time interval between the open and the
     close price. The left tick for each bar indicates the open price
     for the time interval. The right tick indicates the closing price
     for the time interval. The vertical length of the bar represents
     the price range for the time interval. The time scale of 'x' must
     be in Julian dates (days since the 'origin'). 
      '[tseries:plotOHLC]' 

     *Sharpe and Sterling Ratios:* 

        The Sharpe ratio is defined as a portfolio's mean return in
     excess of the riskless return divided by the portfolio's standard
     deviation. In finance the Sharpe Ratio represents a measure of the
     portfolio's risk-adjusted (excess) return.  The Sterling ratio is
     defined as a portfolio's overall return divided by the portfolio's
     maximum drawdown statistic. In finance the Sterling Ratio
     represents a measure of the portfolio's risk-adjusted return. 
      '[tseries:sharpe]' 


     *Maximum Drawdown:* 

      The maximum drawdown or maximum loss statistic is defined as the 
     maximum value drop after one of the peaks of 'x'. For financial
     instruments the maximum drawdown represents the worst investment 
     loss for a buy-and-hold strategy invested in 'x'. 
      '[tseries:maxdrawdown]' 

     *Get Returns:* 

      The function computes the return series given a financial
     security  price series. The price series may be an object of class
     'numeric' or a time series object. This includes objects of
     classes '"ts"', '"its"' and/or '"timeSeries"'.

_V_a_l_u_e:

     'ohlcPlot'  
      creates an Open-High-Low-Close chart.

     'sharpeRatio'
      'sterlingRatio'  
      return the Sharpe or Sterling ratio, a numeric value.

     'maxDrawDown' 
      returns a list containing the following three components: 
     'maxDrawDown', double representing the max drawdown or max loss 
     statistic; 'from', the index (or vector of indices) where the 
     maximum drawdown period starts; 'to', the index (or vector of 
     indices) where the max drawdown period ends.

     'getReturns' 
      returns an object of the same class as the input object 'x'.

_A_u_t_h_o_r(_s):

     Adrian Trapletti for the ohlcPlot,*Ratio and maxDrawDown
     functions, 
      Diethelm Wuertz for the Rmetrics R-port.

_E_x_a_m_p_l_e_s:

     ## SOURCE("fMultivar.1B-BenchmarkAnalysis")

     ## Not run: 
     ## ohlcPlot -
        # Plot OHLC for SP500
        # ohlcPlot(x, ylab = "price", main = instrument)
        
     ## sharpeRatio -
        # Sharpe Ratio for DAX and FTSE:
        data(EuStockMarkets)
        dax = log(EuStockMarkets[, "DAX"])
        ftse = log(EuStockMarkets[, "FTSE"])
        # Ratios:
        sharpeRatio(dax)
        sharpeRatio(ftse)
        
     ## maxDrawDown -
        par(mfrow = c(1, 1), cex = 0.7)
        data(EuStockMarkets)
        dax = log(EuStockMarkets[, "DAX"])
        mdd = maxDrawDown(dax)
        mdd
        # Plot DAX:
        plot(dax)
        segments(time(dax)[mdd$from], dax[mdd$from],
          time(dax)[mdd$to], dax[mdd$from])
        segments(time(dax)[mdd$from], dax[mdd$to],
          time(dax)[mdd$to], dax[mdd$to])
        mid = time(dax)[(mdd$from + mdd$to)/2]
        arrows(mid, dax[mdd$from], mid, dax[mdd$to], col = 2)
        title(main = "DAX: Max Drawdown")
        
     ## getReturns -
        par(mfrow = c(1, 1), cex = 0.7)
        data(EuStockMarkets)
        dax = log(EuStockMarkets[, "DAX"])
        plot(getReturns(dax))
        title(main = "DAX: Returns")
     ## End(Not run)

