fatreturns | R Documentation |
fatreturns
is an elaborated function to compute prices to returns.
It includes a pre-treatment for negative prices.
It computes either log-returns (default) or percentage-returns.
It handles properly NA values in the input vector, replacing them by 0
in the output vector. Doing so, it warrants that the sum of the log-returns
(when selected) is equal to the difference of the log-prices.
It works with vector, matrix, data.frame, timeSeries, xts, zoo, list, list of lists
and even list of vector, data.frame, timeSeries, xts, zoo mixed together.
The returned object is of same dimension and same class than the input object
with the first line filled with 0.
The results may be as per one, per cent (default), per thousand and per ten thousand.
logreturns
is an improved version of function 100*diff(log(x))
to handle
vector, matrix, data.frame and list. It handles properly the first line and the NA values.
It does not control time, rownames and colnames but may return them.
fatreturns(x, log = TRUE, per = "cent", e = NULL, dfrcol = 1,
na.rm = TRUE)
logreturns(x)
replaceNA(x)
x |
The prices (vector, data.frame, matrix, timeSeries, xts, zoo, list). |
log |
boolean. log returns or percentage returns. |
per |
character. Either "one", "cent, "thousand", "tenthousand" or "o", "c", "th", "te". Multiply the result by 1, 100, 1000, 10000. |
e |
NULL or positive numeric. NULL is for no change |
dfrcol |
integer. For data.frame only, designates the column that handles the time
and must be processed separately. Use |
na.rm |
boolean. Replace |
Negative prices in financial markets, like interest rates in Europe, are a
nightmare as the rough calculation of the returns generates non-sense values.
elevate
uses an hyperbola and implements the following formula:
elevate(x, e) = (x + sqrt(x*x + e*e)) / 2
There is currently no rule of thumb to calculate e
.
When e = NULL
, there is no change and the output is identical to the input.
When e = 0
, all negative values are turned to 0.
fatreturns(extractData())
logreturns(getDSdata())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.