[R] new to R coding.

R. Michael Weylandt michael.weylandt at gmail.com
Mon Oct 24 18:10:36 CEST 2011


Assuming that d(x) is equal to x, (I don't know a d() function in R)
these should be the same.

log(a/b) = log(a) - log(b) = diff(log(c(a,b))

If you mean simple returns instead of continuous/log returns, perhaps try this:

x[-1]/x[-length(x)] - 1

Michael

On Mon, Oct 24, 2011 at 11:44 AM, tynashy <tynashy at yahoo.co.uk> wrote:
> how do I code the following in R. I want to produce a vector where dx=log(
> (d(x))/(d(x-1)) ). I can do it for dx=diff(log(x)). I am learning/trying to
> model log returns of a stock market index. But instead of using the
> difference of the closing values of two consecutive days, i want to use the
> log of the quotient of the two days. any help is most appreciated. d is a
> vector of the closing values of the stock market index of length 5000.
>
> --
> View this message in context: http://r.789695.n4.nabble.com/new-to-R-coding-tp3933588p3933588.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list