sm.density , , approx approxfun, Returns, . :
set.seed(1)
foo <- data.frame(Date = seq(as.Date("2010-01-01"), as.Date("2010-12-31"),
by = "days"),
Returns = rnorm(365))
head(foo)
dens <- with(foo, density(Returns, n = 512 * 8))
approx() x y , approxfun(), , , . -, :
BAR <- with(dens, approxfun(x = x, y = y))
BAR() , , . Returns:
> with(foo, BAR(Returns[1]))
[1] 0.3268715
, Returns:
> foo <- within(foo, Density <- BAR(Returns))
> head(foo)
Date Returns Density
1 2010-01-01 -0.6264538 0.3268715
2 2010-01-02 0.1836433 0.3707068
3 2010-01-03 -0.8356286 0.2437966
4 2010-01-04 1.5952808 0.1228251
5 2010-01-05 0.3295078 0.3585224
6 2010-01-06 -0.8204684 0.2490127
, , . , Returns, lines :
plot(dens)
with(foo, lines(sort(Returns), BAR(sort(Returns)), col = "red"))
- :

(512 * 8 ), , , "" Returns, , , lines() , , , lines(), .