Note that there are some explanatory texts on larger screens.

plurals
  1. POApply ksmooth to time series
    primarykey
    data
    text
    <p>I have the following problem:</p> <p>I have a data frame "test" that looks more or less like this:</p> <pre><code>Date return price vol 20100902 0.3 15 8.5 20100902 0.4 17 8.6 20100902 0.6 19 8.7 ..... 20100903 0.2 13 8.2 20100903 0.4 17 8.6 20100903 0.8 21 9.0 ..... </code></pre> <p>So I have given values for each date (10 per day). What I would like to do now is apply ksmooth() on each date, so e.g. ksmooth(return, price, n.points = 50) for each date. This should give me 50 observations for each date. In addition, I would like a time stamp for the interpolated values. So the resulting frame should like </p> <pre><code>Date return price 20100620 0.3 15 20100620 0.31 15.2 20100620 0.32 15.3 20100620 0.4 17 20100620 0.6 19 ..... 20100621 0.2 13 20100621 0.21 13.1 20100621 0.22 13.2 20100621 0.4 17 20100621 0.8 21 etc. </code></pre> <p>with 50 observations per day. So here is what I'm looking for: take the first 10 observations (e.g. date 1 = 20102006, interpolate and put a time stamp on the interpolated values (20100620). Then, take second 10 observations (date = 20100621), interpolate and put a time stamp on the interpolated values (20100621) and so on.</p> <p>I'm quite new to R, but this is what I tried. I thought of using the zoo() function to that. Before implementing anything, I wanted to make my date entries unique, so I just added hours to each entry</p> <pre><code>test &lt;- read.zoo("test.txt", format = "%Y%m%d") test &lt;- zoo(test, as.POSIXct(time(test)) + 1:26) </code></pre> <p>There probably is something wrong with that, because R complained. Then I thought of using the rollapply() function.</p> <pre><code>roll.test &lt;- rollapply(test, 10, FUN = function(x,y) ksmooth(test$return, + test$price, "normal", bandwidth = 20, n.points = 50) ) </code></pre> <p>Unfortunately the result is very confusing. And the by.column = FALSE demand does not work.</p> <p>I would very appreciate some help. It does not have to build upon my "trial version" at all. Thank you very much Dani</p> <p>My data looks like this:</p> <pre><code>"date" "days" "return" "price" "66" 20100620 91 0.18 1389.373 "67" 20100620 91 0.19 1370.57 "68" 20100620 91 0.19 1353.122 "69" 20100620 91 0.19 1336.291 "70" 20100620 91 0.20 1319.774 "71" 20100620 91 0.20 1303.341 "72" 20100620 91 0.21 1286.656 "326" 20100621 91 0.18 1386.28 "327" 20100621 91 0.18 1367.694 "328" 20100621 91 0.19 1350.375 "329" 20100621 91 0.19 1333.615 "330" 20100621 91 0.20 1317.164 "331" 20100621 91 0.20 1300.783 "332" 20100621 91 0.21 1284.113 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload