Skip to content
Back to formatted view

Raw Message

Message-ID: <971536df05051308413d3c5b8c@mail.gmail.com>
Date: 2005-05-13T15:41:48Z
From: Gabor Grothendieck
Subject: Lowest data level since DateX
In-Reply-To: <834204C0D7C6D611A3BB000255FC6E9D06B63172@lbmsg002.fbn-nbf.local>

On 5/13/05, Lapointe, Pierre <Pierre.Lapointe at nbf.ca> wrote:
> Hello,
> 
> I'm dealing with financial time series.  I'm trying to find out X in this
> sentence:
> The most recent close is the lowest level since X(date).
> 
> Here's an example of what I'm looking for:
> 
> library(fBasics)
> data(DowJones30)
> tail(DowJones30[,1:5],n=10)
> 
> I need to come up with a vector that would look like this
> 
> AA             AXP          T            ...
> 2000-12-21     2000-12-20   2000-12-29
> 
> i.e. the last date at which the stocks were trading at a lower level than
> the most recent closing.
> 
> I know it has to do with min/max, pmin/pmax, cummin/cummax or rev(), but I
> can't figure it out.

The following returns the last index whose value is less than the
last entry in vector x (or numeric(0) if none):

> x <- c(1,4,2,6,3)
> tail(which(x < tail(x,1)),1)
[1] 3
> x <- c(1,4,2,6,.5)
> tail(which(x < tail(x,1)),1)
numeric(0)