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
The functions are:
||Plots open--high--low--close bar charts,|
||Computes Sharpe Ratio,|
||Computes Sterling Ratio,|
||Computes maximum drawdown.|
1 2 3 4 5 6 7 8 9
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 numeric vector of prices.
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
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.
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
The function computes the return series given a financial security price series. The price series may be an object of class
or a time series object. This includes objects of classes
creates an Open–High–Low–Close chart.
return the Sharpe or Sterling ratio, a numeric value.
returns a list containing the following three components:
maxDrawDown, double representing the max drawdown or max loss
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.
Adrian Trapletti for the ohlcPlot,*Ratio and maxDrawDown functions,
Diethelm Wuertz for the Rmetrics R-port.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
## 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 - data(EuStockMarkets) dax = log(EuStockMarkets[, "DAX"]) mdd = maxDrawDown(dax) mdd # Plot DAX: plot(dax) grid() 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")
Loading required package: timeDate Loading required package: timeSeries Loading required package: fBasics Rmetrics Package fBasics Analysing Markets and calculating Basic Statistics Copyright (C) 2005-2014 Rmetrics Association Zurich Educational Software for Financial Engineering and Computational Science Rmetrics is free software and comes with ABSOLUTELY NO WARRANTY. https://www.rmetrics.org --- Mail to: firstname.lastname@example.org  1.000859  0.8583209 $maxdrawdown  0.256471 $from  236 $to  331
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.