2:n) {
dx[i]=(d[i])/(d[i-1])
# delta doesn't really do anything so I commented out
# delta=dx[i]
} # this is what I have tried to do.
-Original Message-
From: tynashy
Sent: Monday, October 24, 2011 11:29 AM
To: r-help@r-project.org
Subject: Re: [R] new to R coding.
I am new to R c
I believe I already showed you how to do this (though your code
doesn't seem to do what your words ask, so I'm not sure which one to
answer), but didn't draw attention to it:
x[-1]/x[-length(x)]
This creates two vectors, one consisting of everything but the first
element of x and the other of eve
I am new to R coding and I am trying to model the returns on the ftse100
since 1990. I have got a vector with all the closing values on each trading
day. however, instead of using the difference in the closing values of two
consecutive days, (ie dx=diff(x) where x is the vector containing the
clos
Try it yourself:
x = seq(1, 11, by = 2)
diff(log(x))
log(x[-1]/x[-length(x)])
all.equal(diff(log(x)), log(x[-1]/x[-length(x)]))
It seems like you don't really understand logs / log returns and why
they are used by some in quant finance: might I suggest you read this:
http://quantivity.wordpress.
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
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
6 matches
Mail list logo