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 closing values), i wanted to use the quotient of the two closing values. I have tried the following without any luck
> x = c (2434.1 2463.7 2451.6 2444.5 2431.3 2436.3 2412.6 2417.9 2380.1 > 2366.2 2349.1 2373.9 2336.9 2335.0 2297.1 2291.1 2278.6 2289.9 2314.5 2328.8 2322.0 2337.3 2345.8 2355.1 2348.4 2321.1 2307.4 2331.0 2313.6 2286.9 2293.2 2298.3 2313.8 2325.9 2297.1 2277.0 2259.7 2269.2 2236.7 2249.3 2254.8 2255.4 2238.4 2254.8 2230.5 2216.0 2230.3 2250.0 2234.3 2222.8 2224.5 2226.1 2234.9 2263.9 2238.0 2259.7 2250.3 2258.9 2283.9 2298.2 2266.2 2275.0 2263.0 2247.9 2221.6 2240.7 2231.6 2239.5 2221.1) #extraction of the stock index returns > n=length(x) > d=diff (log(x)) # daily log returns > for (i in 2:n) { + dx[i]=(d[i])/(d[i-1]) + delta=dx[i] + } # this is what I have tried to do. how do i do this properly in R please. -- View this message in context: http://r.789695.n4.nabble.com/new-to-R-coding-tp3933588p3933738.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@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.