[R] Vectorization

From: ManojW <manojsw_at_gmail.com>
Date: Thu 16 Jun 2005 - 10:45:48 EST


Greetings,

    Can anyone suggest me if we can vectorize the following problem effectively?

    I have two datasets, one dataset is portfolio of stocks returns on a historical basis and another dataset consist of a bunch of factors (again on a historical basis). I intend to compute a rolling n-day sensitivitiesfor each stock for each factor, so the output will be a data frame with <ticker><dt><sensitivities>.

    How would you go onto vector this situation effectively?

    I end up with a psuedo code like this:

            # For each date
            For curr dt in all dates

# Get Universe of stocks as of that date
Get Universe for curr date
# Calculate Sensitivity for each factor between n days back
dt to curr date sensitivity = sapply(univ{ticker},CalcSensitivity,n_days_back_dt,dt) Next date

    I would highly appreciate if the above logic could be improved (if at all) by a more effective solution since I do get into such situations on a regular basis.

    Thanks in advance

Cheers

Manoj



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jun 16 10:49:21 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:43 EST