[R-SIG-Finance] Volatility subsample analysis

Patrick Burns patrick at burns-stat.com
Wed Dec 1 16:55:10 CET 2010


First a comment:

I think it would be better to put NA
as the "not in this trend" value.

Assuming I understand your question
properly (and you've instituted the
above change), you can get what you
want via:

rle(is.na(vup))

On 01/12/2010 12:24, dondom wrote:
>
> My problem is the following.  I have applied some filterrules on the SMI to
> define points for investment and desinvestment (as in trend analysis). The
> aim was to define when upwardstrends and downwardstrends took place.
> Afterwards I calculated the volatility for the same dataset and calculated
> the mean volatility for each trend (up and down). As expected I found that
> uptrends have a lower volatility than downward trends.
> To get to my problem, I would like to analyse now the subsamples for each
> trend to get a better insight of this phenomenon. The thing is that I have
> now a vector for all upwardtrends and all downwardtrends (vup; vdown). They
> look like this.
>
>
> vup<- c(0.1,0.2,0.3,0,0,0,0.01,-0.002,0,0,0,0,0,0,0.005,0.1,0.2,0)
>
> Where zeros are placed a downward trend is observed and has to be left out
> of the analysis.
>
> This means that for a first subsample I would like to calculate the mean
> only for 0.1,0.2 and 0.3. Then for 0.01, -0.002, then for 0.005,0.1,0.2, and
> so on
>
>
> The solution should apply itself to a changing composition of the vector
> (because different filterrules are applied)
>
> What I tried is to construct a vector of length vup, with a value 1 where
> vup has a value. Then in a second step I wanted to change this vector so
> that the first observations are with a 1 after with 2 and so on,... that
> would have allowed me to apply the cut or split function in R. Explained in
> numbers:
>
> What I have:
> x<- c(1,1,1,0,0,0,1,1,0,0,0,0,0,0,1,1,1,0)
>
> What I want:
>
> y<- c(1,1,1,0,0,0,2,2,0,0,0,0,0,0,3,3,3,0)
>
>
> As mentioned with "y" I could apply easily a cut or split function and then
> calulate the subsample means.
>
> This might be a very simple thing to do, or maybe a completely better
> approach can be used.
>
> Thanks in advance for your help
> Dominik

-- 
Patrick Burns
patrick at burns-stat.com
http://www.burns-stat.com
http://www.portfolioprobe.com/blog



More information about the R-SIG-Finance mailing list