Hi Brian,

Sorry again. I would like your guide to get through this. I simulated a
dataset just to go through a simple example of my first strategy in
quantstrat. After simulating, the data is in an xts format. I am wondering
how do you make it such that strategy knows it as a symbol? Says if I were
to set it to symbol "XYZ". I read getSymbols.FI manual to start with but
don't quite understand how it works in this case. Thank you.

set.seed(119302);
t0 <- Sys.time();
N <- 10000;
p0 <- 1700;
sigma <- 0.01/sqrt(23.5*60*60);
# first construct test data
price <- p0*(1 + cumsum(arima.sim(list(ar=0.3,ma=0.1),N,sd=sigma)));
vlm <- sign(runif(N,-1,1))*ceiling(exp(arima.sim(list(ar=-0.2),N,sd=1)));
dur <- rexp(N,rate=0.3);
timevec <- t0 + cumsum(dur);
dt <- c(0,diff(timevec));
vwap <- VWAP(price,abs(vlm),100);
mydata <- xts(data.frame(price,vlm,dt,vwap),order.by=timevec);

devCalc <- function(price,vwap)
{
    (price-vwap)/p0/sigma;
}

SYMBOL <- "XYZ";
DATA_DIR <- "~/Data";
# create instruments
save(mydata,file=file.path(DATA_DIR,SYMBOL));
# read symbol back (but fails!!) R says that data is not found.
getSymbols(SYMBOL,src="FI", dir=DATA_DIR,extension="");



On Thu, Dec 13, 2012 at 7:52 AM, Brian G. Peterson <brian@braverock.com>wrote:

> On 12/12/2012 09:45 PM, Robert A'gata wrote:
>
>> Thank you Aleksey. My doubt is less about whether it will be xts or zoo.
>> My
>> apology as I should be more precise. Says, I have an xts data with the
>> following columns: TradePrice, TradeSize, Bid, Ask, HistoricalVolatility.
>> Then my questions are:
>>
>> 1) How can I make this xts available to add.indicator? In most examples, I
>> see that one has to create an instrument out of it. Then assign instrument
>> ID to portfolio or strategy object. Finally rely on mktdata to look up.
>> 2) For each tick, I'd like to access all the columns in the xts. A
>> simplest
>> example would be, I'd like to compute VWAP with 100-trade rolling window.
>> Then compute the distance betwen current mid price and the running VWAP.
>> How can I let my add.indicator know that I want a whole row and not only
>> price? My understanding is that quote(mktData) will try to look for price
>> only.
>>
>>
> As is outlined in the documentation, you need instrument metadata that
> defines the instruments that you're trying to use.  For TAQ data from NYSE,
> these would be stock() instruments.
>
> quantstrat, by default, assumes that you will have data named for each
> instrument, just as though you had called getSymbols.  Other approaches are
> possible, but harder, so we'll skip that.
>
> If you use RTAQ (or the newer 'highfrequency' from R-Forge) to create xts
> objects from your TAQ CSV files, you can easily save these parsed xts
> objects to disk in a format suitable for getSymbols (specifically,
> getSymbols.FI) to go get them for you with from and to dates.  This will
> have the added advantage of making in faster and easier to get this data
> back into R for later analysis.
>
> Let's assume you've done all that, and want to add a 100-trade VWAP
> indicator, as you've requested.  That would look like:
>
> add.indicator(s, name="VWAP",
>         arguments = list(
>                 price = quote(mktdata$TradePrice)),
>                 n = 100,
>                 volume = quote(mktdata$TradeSize))
>         ),
>         label="VWAP"
> )
>
> As a side note, You could also easily create and add your
> HistoricalVolatility column as an indicator inside the strategy as well,
> encapsulating all the required analytical code in the strategy object.
>
> Regards,
>
>    - Brian
>
> --
> Brian G. Peterson
> http://braverock.com/brian/
> Ph: 773-459-4973
> IM: bgpbraverock
>
>
> ______________________________**_________________
> R-SIG-Finance@r-project.org mailing list
> https://stat.ethz.ch/mailman/**listinfo/r-sig-finance<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]]

