Thanks all for your inputs. The cut worked.

Here is what I intended and what I got happily.

*binmarks= seq(from=0,to=1,by=0.1)*
*vol_cut=cut(vols,binmarks,labels=F)
*
*vols=cbind(vols,vol_cut)
*



Frank> Many thanks for your inputs. I was looking for something without for
loops and the above three lines do the job.

Output
 vols[1:30]
                 ..1 ..2
2011-06-29        NA  NA
2011-06-30        NA  NA
2011-07-01        NA  NA
2011-07-04        NA  NA
2011-07-05        NA  NA
2011-07-06        NA  NA
2011-07-07        NA  NA
2011-07-08        NA  NA
2011-07-11        NA  NA
2011-07-12 0.2985884   3
2011-07-13 0.2873109   3
2011-07-14 0.2780244   3
2011-07-15 0.2739429   3
2011-07-18 0.2609898   3
2011-07-19 0.2868996   3
2011-07-20 0.2613348   3
2011-07-21 0.2736182   3
2011-07-22 0.3060679   4
2011-07-25 0.1792170   2
2011-07-26 0.1767940   2
2011-07-27 0.1559522   2
2011-07-28 0.1844979   2
2011-07-29 0.1831905   2
2011-08-01 0.1840713   2
2011-08-02 0.2303922   3
2011-08-03 0.2299805   3
2011-08-04 0.1849425   2
2011-08-05 0.2833781   3
2011-08-08 0.3466735   4
2011-08-09 0.3627505   4

The xts class of vols remains intact as xts. For the benefit of the larger
community the purpose of this is a rough way to check which 'regime'
(loosely) of historical vols does the market fall into at the moment which
can be used for many things. HTH.

Thx
Raghu



On Thu, Oct 31, 2013 at 9:22 PM, Frank <frankm60606@gmail.com> wrote:

> ** **
>
> Hi Raghu,****
>
> ** **
>
> I figured out how to create your vols from your data. This should work:***
> *
>
> ** **
>
> ** **
>
> head(vols)****
>
> ** **
>
> vols_qtl<-quantile(vols, na.rm = TRUE)****
>
> print(vols_qtl[1])****
>
> print(vols_qtl[2])****
>
> print(vols_qtl[3])****
>
> print(vols_qtl[4])****
>
> ** **
>
> nvols<-NROW(vols)****
>
> nvols****
>
> vols_quantile<-numeric(length=nvols)****
>
> ** **
>
> for (i in 1:nvols) {****
>
> if (vols[i]>=vols_qtl[1]) vols_quantile[i]<-1****
>
> if (vols[i]>=vols_qtl[2]) vols_quantile[i]<-2****
>
> if (vols[i]>=vols_qtl[3]) vols_quantile[i]<-3****
>
> if (vols[i]>=vols_qtl[4]) vols_quantile[i]<-4****
>
> ** **
>
> }****
>
> ** **
>
> print (vols_quantile)****
>
> quit()****
>
> ** **
>  ------------------------------
>
> *From:* Raghuraman Ramachandran [mailto:optionsraghu@gmail.com]
> *Sent:* Thursday, October 31, 2013 4:17 PM
> *To:* Frank
> *Subject:* Re: [R-SIG-Finance] Ranking XTS based on quantiles****
>
> ** **
>
> Hi Frank****
>
> ** **
>
> Thanks. I will try this.****
>
> ** **
>
> Rgds****
>
> Raghu****
>
> ** **
>
> 2013/10/31 Frank <frankm60606@gmail.com>****
>
> Hi,
>
> This is close to what you want, I think:
>
> vols_qtl<-quantile(vols, na.rm = TRUE)
> print(vols_qtl[0])
> print(vols_qtl[1])
> print(vols_qtl[2])
> print(vols_qtl[3])
> print(vols_qtl[4])
> nvols<-nrows(vols)
> numeric(vols_quantile, length=nvols)
>
> for i=1:nvols {
> if (vols[i]>=vols_qtl[0]) vols_quantile[i]<-1
> if (vols[i]>=vols_qtl[1]) vols_quantile[i]<-2
> if (vols[i]>=vols_qtl[2]) vols_quantile[i]<-3
> if (vols[i]>=vols_qtl[3]) vols_quantile[i]<-4
> }
>
>
> Don't really know how vols_quantile to an XTS object. I think merge will do
> it.
>
> Thanks,
>
> Frank
> ****Chicago********
>
>
> -----Original Message-----
> From: r-sig-finance-bounces@r-project.org
> [mailto:r-sig-finance-bounces@r-project.org] On Behalf Of Raghuraman
> Ramachandran
> Sent: Thursday, October 31, 2013 6:40 AM
> To: r-sig-finance@stat.math.ethz.ch
> Subject: [R-SIG-Finance] Ranking XTS based on quantiles
>
> R GuRus
>
> I have an xts object called vols
>
> head(vols)
>                 [,1]
> 2011-07-12 0.2985884
> 2011-07-13 0.2873109
> 2011-07-14 0.2780244
> 2011-07-15 0.2739429
> 2011-07-18 0.2609898
> 2011-07-19 0.2868996
>
> and I wanted to have a column next to each in everyrow that ranks the vols
> based on quantiles.
>
> quantile(vols)
>        0%       25%       50%       75%      100%
> 0.0562344 0.1536431 0.2194198 0.3043755 1.3428146
>
> Can you help please?
>
> Thanks
> Raghu****
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance@r-project.org 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.****
>
> ** **
>

	[[alternative HTML version deleted]]

