Monthly Midpoint return

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Monthly Midpoint return

Phil Steel
Hi Phil here,
Sorry for bothering you all with this idiotic question but I can't find a simple way to go forward.
I can't manage to get the midpoint monthly returns from an daily price xts object.I know how to get monthly endpoints by using "to.monthly()"  but I can't figure how to transform the daily object to monthly midpoint. Lets say the midpoint is the first day trading day around the 15:th in a month or every 30:th day.
Anybody have encounter this "problem" and/or have a solution.
Have a great evening/afternoon/morning!
Cheers,Student      
        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Monthly Midpoint return

braverock
On Wed, 2015-06-17 at 12:10 +0000, Phil Steel wrote:
> Sorry for bothering you all with this idiotic question but I can't find a simple way to go forward.
> I can't manage to get the midpoint monthly returns from an daily price xts object.I know how to get monthly endpoints by using "to.monthly()"  but I can't figure how to transform the daily object to monthly midpoint. Lets say the midpoint is the first day trading day around the 15:th in a month or every 30:th day.
> Anybody have encounter this "problem" and/or have a solution.

I'm not entirely sure I understand your question.  

If you want the mean/median of the monthly series, or any other
calculable stat, you can use period.apply.

If you want a particular point in time, like the 15th of each month,
then use 'endpoints' or subset the index to get the points you're
looking for.

Regards,

Brian


--
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock

_______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Monthly Midpoint return

Phil Steel



Hi Brian and everybody else,
its downloaded stock prices I want to transform to middle of month stock price.
endpoints give end of month doesn't it?if Im using endpoints I get a really strange result with a lot of NA:s My Data starts with the 15:th som my idea it transforming the data to.monthly somehow
My function is ("provided" by Ulrich):
monthly = function(x){  sym <- sub("\\..*$", "", names(x)[1])  Ad(to.monthly(x, indexAt = 'lastof', drop.time = TRUE, name = sym))}

best regards,Phillip

> Subject: Re: [R-SIG-Finance] Monthly Midpoint return
> From: [hidden email]
> To: [hidden email]
> CC: [hidden email]
> Date: Wed, 17 Jun 2015 07:37:31 -0500
>
> On Wed, 2015-06-17 at 12:10 +0000, Phil Steel wrote:
> > Sorry for bothering you all with this idiotic question but I can't find a simple way to go forward.
> > I can't manage to get the midpoint monthly returns from an daily price xts object.I know how to get monthly endpoints by using "to.monthly()"  but I can't figure how to transform the daily object to monthly midpoint. Lets say the midpoint is the first day trading day around the 15:th in a month or every 30:th day.
> > Anybody have encounter this "problem" and/or have a solution.
>
> I'm not entirely sure I understand your question.  
>
> If you want the mean/median of the monthly series, or any other
> calculable stat, you can use period.apply.
>
> If you want a particular point in time, like the 15th of each month,
> then use 'endpoints' or subset the index to get the points you're
> looking for.
>
> Regards,
>
> Brian
>
>
> --
> Brian G. Peterson
> http://braverock.com/brian/
> Ph: 773-459-4973
> IM: bgpbraverock
>

     
        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Monthly Midpoint return

Ilya Kipnis
If you're going strictly for mid-month, 2/7ths of the time, that's a
weekend, and don't forget holidays.
On Jun 17, 2015 10:23 AM, "Phil Steel" <[hidden email]> wrote:

>
>
>
> Hi Brian and everybody else,
> its downloaded stock prices I want to transform to middle of month stock
> price.
> endpoints give end of month doesn't it?if Im using endpoints I get a
> really strange result with a lot of NA:s My Data starts with the 15:th som
> my idea it transforming the data to.monthly somehow
> My function is ("provided" by Ulrich):
> monthly = function(x){  sym <- sub("\\..*$", "", names(x)[1])
> Ad(to.monthly(x, indexAt = 'lastof', drop.time = TRUE, name = sym))}
>
> best regards,Phillip
> > Subject: Re: [R-SIG-Finance] Monthly Midpoint return
> > From: [hidden email]
> > To: [hidden email]
> > CC: [hidden email]
> > Date: Wed, 17 Jun 2015 07:37:31 -0500
> >
> > On Wed, 2015-06-17 at 12:10 +0000, Phil Steel wrote:
> > > Sorry for bothering you all with this idiotic question but I can't
> find a simple way to go forward.
> > > I can't manage to get the midpoint monthly returns from an daily price
> xts object.I know how to get monthly endpoints by using "to.monthly()"  but
> I can't figure how to transform the daily object to monthly midpoint. Lets
> say the midpoint is the first day trading day around the 15:th in a month
> or every 30:th day.
> > > Anybody have encounter this "problem" and/or have a solution.
> >
> > I'm not entirely sure I understand your question.
> >
> > If you want the mean/median of the monthly series, or any other
> > calculable stat, you can use period.apply.
> >
> > If you want a particular point in time, like the 15th of each month,
> > then use 'endpoints' or subset the index to get the points you're
> > looking for.
> >
> > Regards,
> >
> > Brian
> >
> >
> > --
> > Brian G. Peterson
> > http://braverock.com/brian/
> > Ph: 773-459-4973
> > IM: bgpbraverock
> >
>
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> [hidden email] 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]]

_______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Monthly Midpoint return

Mark Knecht
In reply to this post by Phil Steel
On Wed, Jun 17, 2015 at 7:23 AM, Phil Steel <[hidden email]> wrote:
>
>
>
> Hi Brian and everybody else,
> its downloaded stock prices I want to transform to middle of month stock price.
> endpoints give end of month doesn't it?if Im using endpoints I get a really strange result with a lot of NA:s My Data starts with the 15:th som my idea it transforming the data to.monthly somehow
> My function is ("provided" by Ulrich):
> monthly = function(x){  sym <- sub("\\..*$", "", names(x)[1])  Ad(to.monthly(x, indexAt = 'lastof', drop.time = TRUE, name = sym))}
>

Possibly put the month in an array, determine the size of the array
and then take the price/returns at the midpoint of the array? That way
number of days in the month, holidays, etc. wouldn't matter much?

- Mark

_______________________________________________
[hidden email] 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.
markknecht@gmail.com
Reply | Threaded
Open this post in threaded view
|

Re: Monthly Midpoint return

gsee
Try this

    data(sample_matrix) # load sample data first
    x <- as.xts(sample_matrix)

    do.call(rbind, lapply(split(x, "months"),
                          function(xx) xx[ceiling(nrow(xx)/2)]))

This code splits the object by months, then uses lapply() to loop over
each month and apply a function which selects the row that is in the
middle of the month.  (you could replace ceiling() with floor() or
round()).

Once you have the subsetted data, you can calculate returns however
you normally would (ROC(), Delt(), dailyReturn(), etc.)

HTH,
Garrett


On Wed, Jun 17, 2015 at 9:30 AM, Mark Knecht <[hidden email]> wrote:

> On Wed, Jun 17, 2015 at 7:23 AM, Phil Steel <[hidden email]> wrote:
>>
>>
>>
>> Hi Brian and everybody else,
>> its downloaded stock prices I want to transform to middle of month stock price.
>> endpoints give end of month doesn't it?if Im using endpoints I get a really strange result with a lot of NA:s My Data starts with the 15:th som my idea it transforming the data to.monthly somehow
>> My function is ("provided" by Ulrich):
>> monthly = function(x){  sym <- sub("\\..*$", "", names(x)[1])  Ad(to.monthly(x, indexAt = 'lastof', drop.time = TRUE, name = sym))}
>>
>
> Possibly put the month in an array, determine the size of the array
> and then take the price/returns at the midpoint of the array? That way
> number of days in the month, holidays, etc. wouldn't matter much?
>
> - Mark
>
> _______________________________________________
> [hidden email] 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.

_______________________________________________
[hidden email] 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.