[R-SIG-Finance] ksmooth Function in Library ("stats")

Brian G. Peterson brian at braverock.com
Sun May 9 13:22:39 CEST 2010

This question has nothing to do with finance, despite the title of Carmona's 
book.  In the future, please direct non-finance questions to r-help.

The book was written quite a while ago for S-Plus.  You are using R.  The 
functions are slightly different.

Assuming for a moment that this isn't a homework assignment, the R ksmooth 
expects two series to regress, x, and  y.  Your data is univariate, and will 
thus fail with only x, per your error message.

Note also that the documentation for ksmooth says it is there only for S-Plus 
compatibility, and suggests that there are multiple better functions.

Carmona's book was good in its day, when there were no books that covered R in 
finance or time series explicitly, but now I would have to recommend Shumway 
and Stoffer, or perhaps Ruppert.  There was a thread on this list a while back 
that covered people's favorite texts for a variety of different time series 
tasks, it should be in your favorite list archive.


    - Brian

On 05/09/2010 01:57 AM, JOSH C. CHIEN wrote:
> Hi R user,
> I'm studying "Statistical Analysis of Financial Data in S-plus" by Carmona.
> In p.21, the author introduce ksmooth function to plot curve in Kernel estimate method.
> For this case, using data set "DSPLR",S&P return, it want to know the distribution of these return on a given day.
> There are two methods to do that. One is using density Function ; the other is using kernel estimate method.
> Below is my working on R console.
>> data(DSPLR)
>> class(DSPLR)
> [1] "numeric"
>> str(DSPLR)
>   num [1:10928] 0.00798 -0.00431 -0.00734 -0.00319 -0.01234 ...
>> hist(DSPLR,probability=T)
> DENS<- ksmooth(DSPLR, kernel="normal",bandwidth = .03)
> ************************************************
> Error in ksmooth(DSPLR, kernel = "normal", bandwidth = 0.03) :
>    y must be supplied.
> For density estimation use density()
> *************************************************
>> From error message above, lack in "y value" into argument.
> But, I saw example on textbook.
> Author' version is " DENS<- ksmooth(DSPLR, kernel="normal",bandwidth = .03) "
> how to figure out this error message ?
> thanks a lot.
> 	[[alternative HTML version deleted]]
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.

Brian G. Peterson
Ph: 773-459-4973
IM: bgpbraverock

More information about the R-SIG-Finance mailing list