[R] R - Confidence Intervals

Christian Goelz christian.goelz at gmx.de
Thu Oct 7 21:03:32 CEST 2010


Dear David,

Thank you for your prompt response. 

I understand that this may seem like an simple problem to you, but I have never done this before, so please excuse the mistakes along the line!

May I revise the code according to your suggestion and, should I have further problems, ask you for your help again?

Many thanks!

Best regards

Christian

Sent from my wireless smartphone device

On 7 Oct 2010, at 20:50, David Winsemius <dwinsemius at comcast.net> wrote:

> 
> On Oct 7, 2010, at 12:01 PM, Christian Goelz wrote:
> 
>> Dear Sirs,
>> 
>> I was hoping you can help me, I am quite desperate in finding a
>> solution for my problem! I have looked everywhere on the net and tried
>> hundreds of codes, but I am still not anywhere close to the solution.
>> I am quite new to R, so please excuse if this seems simple:
>> 
>> I am trying to use R to analyse some stocks, but I can't get the
>> theoretical confidence interval (95%) for my sample:
>> 
>> e.g. IBM:
>> 
>> library('tseries')
>> data<-get.hist.quote(instrument="IBM", start="2000-01-01",
>> end="2010-10-04", quote=c("O","H","L","C","A","V"),
>> compression='d',provider="yahoo", retclass="zoo")
>> names(IBM)
> 
> Problem 1: You name your data "data" and now you are referring to it by "IBM"
>> 
>> I have defined the parameters as follows:
>> 
>> Pt=IBM$Adj.Close
> 
> Problem 2... there is no column named Adj.Close
> 
>> r=diff(log(Pt))
>> l=length(Pt)
>> mu=mean(r)
>> t=2:l
>> 
>> Given the formula for confidence intervals E(logPt)=logP0+μ*t
>> +1.96*sqrt(t)*s^2, I tried to define a formula in R:
>> 
>> logP1=numeric()
>>> logP1[1]=log(Pt[1])
>>> logP1[2:l]=logP1[1]+cumsum(logP1+mu*t+c(-1.96,1.96)*sqrt(t)*sd(Pt))
> 
> Is it really true that s^2 is well estimated by that cusum?
> 
>>> P1=exp(logP1)
> 
> I ask that because P1 (after correction of the errors noted above) "blows up" , i.e. increases to "Inf".
>> 
>> However, although I don't receive an error message, I cannot show the
>> result!
> 
> Did you type:
> 
> P1   # ??? and then watch the stream of 2075 mostly Inf values?
> 
> Really? I got all sorts of cascading errors.
> -- 
> David.
> 
> 
>> 
>> Many thanks in advance for your assistance with this!
>> 
>> Yours sincerely
>> 
>> Christian
> 
> 
> -- 
> David Winsemius, MD
> West Hartford, CT
> 



More information about the R-help mailing list