Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6602983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:56:45+00:00 2026-05-25T18:56:45+00:00

I am trying to aggregate daily share price data (close only) to weekly share

  • 0

I am trying to aggregate daily share price data (close only) to weekly share price data using the “to.weekly” function in quantmod. The xts object foo holds daily share price data for a stock starting from Monday 3 January 2011 and ending on Monday 20 September 2011. To aggregate this daily data I used:

tmp <- to.weekly(foo)

The above approach succeeds in that tmp now holds a series of weekly OHLC data points, as per the quantmod docs. The problem is that the series begins on Monday 3 January 2011 and each subsequent week also begins on Monday e.g. Monday 10 January, Monday 17 January and so on. I had expected the week to default to ending on Friday so that the weekly series started on Friday 7 January and ended on Friday 16 September.

I have experimented with adjusting the start and end of the data and using ‘endof’ or ‘startof’ together with the indexAt parameter but I cannot get it to return a week ending in Friday.

I am grateful for any insights received.
(Sorry, I could not find any way to attach dput file so data appears below)

foo:

2011-01-03 2802
2011-01-04 2841
2011-01-05 2883
2011-01-06 2948
2011-01-07 2993
2011-01-10 2993
2011-01-11 3000
2011-01-12 3000
2011-01-13 3025
2011-01-14 2970
2011-01-17 2954
2011-01-18 2976
2011-01-19 2992
2011-01-20 2966
2011-01-21 2940
2011-01-24 2969
2011-01-25 2996
2011-01-26 2982
2011-01-27 3035
2011-01-28 3075
2011-01-31 3020

tmp:

           foo.Open foo.High foo.Low foo.Close
2011-01-03     2802     2802    2802      2802
2011-01-10     2841     2993    2841      2993
2011-01-17     3000     3025    2954      2954
2011-01-24     2976     2992    2940      2969
2011-01-31     2996     3075    2982      3020
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:56:45+00:00Added an answer on May 25, 2026 at 6:56 pm

    I’ve come up with something yielding only Close values, perhaps it can be hacked further to return OHLC series.

    Assuming that foo is an xts object, first we create the vector of indeces of Fridays:

    fridays = as.POSIXlt(time(foo))$wday == 5
    

    Then we prepend it with 0:

    indx <- c(0, which(fridays))
    

    And use period.apply:

    period.apply(foo, INDEX=indx, FUN=last)
    

    Result:

              [,1]
    2011-01-07 2993
    2011-01-14 2970
    2011-01-21 2940
    2011-01-28 3075
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find a way to collect data using sql aggregate functions
i am trying to aggregate form elements into object and then send it via
I am trying to write an aggregate udf for using Sql Server 2008 and
I'm trying to apply the Aggregate Root pattern to my domain. I'm using Entity
Trying to reverse a string but getting error in Aggregate function private string Reverse(string
I'm trying to aggregate some customer order data into one table for analysis. The
I'm trying to do a cumulative aggregate in MySQL. My raw data looks like
trying to use this route: from(activemq:profiles).aggregate(header(cheese)).batchSize(30).bean(ProfilesQueueService, saveContacts) Fails with: No signature of method: org.apache.camel.model.RouteType.aggregate()
Trying to get parameters from a PUT request using HttpServlet#doPut: public void doPut(HttpServletRequest request,
I am trying to aggregate the names of all the users in on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.