You may first use "embed" function to create a data.frame with lagging time
and then use sapply to apply the function to each row. In this way you can
easily parallelize your code using sun grid engine or mcapply.

Hesen Peng

On Mar 28, 2010 11:15 AM, "David L. Van Brunt, Ph.D." <dlvanbrunt@gmail.com>
wrote:

For the life of me, I don't know why this is eluding me...

I'm trying to add a variable into a time series (have quote data added via
quantmod).  I've added technical indicators, but now want a column that will
reflect the trailing stop value for that day, given a starting date and
trade value, and a given trailing stop.

Is there a more sensible way than using a FOR loop to march through the
rows, lagging to compare prior highs/lows to current stop value?  I don't
want the canned Parabolic SAR, but a custom user-specifiable trailing stop
(for example, 5% below the high since position entry for long, 5% above low
since short entry)

Google searches have come up dry, and this seemingly simple task has eluded
me.

       [[alternative HTML version deleted]]

_______________________________________________
R-SIG-Finance@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.

	[[alternative HTML version deleted]]

