[R-SIG-Finance] Subsetting Second to Last Day of the Month

Am Gut agquantr at gmail.com
Wed Oct 28 20:35:50 CET 2015


Illya,

Thanks for the help as I was able to get the intended result with the
following code (still one question remains):

##identify second to last business day of every month
month_end_rank = endpoints(matrix_rank, on ="months")
month_end_rank_minus = month_end_rank - 1
month_end_rank_minus = rbind(month_end_rank_minus)
for (i in 1:nrow(month_end_rank_minus))
{
    if (month_end_rank_minus[i]< 0)
    {
        month_end_rank_minus = month_end_rank_minus[-i]
    }
}
matrix_rank_minus = matrix_rank[month_end_rank_minus,]


However, if I wanted the second to last business day of each month and all
days of the year were loaded in the dataset, how would I communicate with R
that I want the second to last *business* day now that business days and
non-business days are loaded in the dataset. I would be going back a
different number of days different times. I have been looking through the
packages and still was unable to find an application. If you know of how, I
would also appreciate that insight.

Thanks for all of your help today. I am up and running for now.

AG

On Wed, Oct 28, 2015 at 1:43 PM, Ilya Kipnis <ilya.kipnis at gmail.com> wrote:

> As for the last day of each month as opposed to business day, then you
> need to have those holidays and weekends in your data set.
> On Oct 28, 2015 12:40 PM, "Am Gut" <agquantr at gmail.com> wrote:
>
>> Ilya,
>>
>> Thanks for such a fast reply. The output is the last day of each month in
>> my dataset - so sometimes not necessarily the last day of each month - but
>> the last day of the month within my dataset (which is just the business
>> days):
>>
>> [image: Inline image 1]
>>
>> Please let me know if you have any suggestions on how I can progress
>> along with this issue and thanks in advance.
>>
>> Kind Regards,
>>
>> AG
>>
>> On Wed, Oct 28, 2015 at 1:36 PM, Ilya Kipnis <ilya.kipnis at gmail.com>
>> wrote:
>>
>>> Do you know what the output of the endpoints function is? It's trivial
>>> from there.
>>> On Oct 28, 2015 12:35 PM, "Am Gut" <agquantr at gmail.com> wrote:
>>>
>>>> Good Morning Everyone,
>>>>
>>>> I have essentially two questions. I am trying to subset a an existing
>>>> dataset based on the last two business days of each month in the dataset. I
>>>> am able to subset based on the last business day of each month (or the last
>>>> day as I am only using business days in my dataset) via the following code:
>>>>
>>>> ##identify second to last business day of every month
>>>> month_end = lookback_returns_nona[endpoints(lookback_returns_nona,
>>>> on="months"),]
>>>>
>>>> However, I do not have to make this the second to last day instead. In
>>>> addition, can someone help me understand how I could do the last business
>>>> day of each month and the second to last business day of each month?
>>>>
>>>> My dataset simply contains a date index, and a few variables with daily
>>>> returns:
>>>>
>>>>
>>>> [image: Inline image 1]
>>>>
>>>> As a side note, I am new to the forum so please feel free to let me
>>>> know if I am not observing proper posing rules. Thanks in advance as any
>>>> help would be extremely useful.
>>>>
>>>> Kind Regards,
>>>>
>>>> AG
>>>>
>>>> _______________________________________________
>>>> R-SIG-Finance at 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.
>>>>
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20151028/4947770d/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 5672 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20151028/4947770d/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 7735 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20151028/4947770d/attachment-0001.png>


More information about the R-SIG-Finance mailing list