+ Reply to Thread
Results 1 to 14 of 14

Convert Daily Stock date into weekly data.

  1. #1
    Forum Contributor stockgoblin42's Avatar
    Join Date
    05-26-2011
    Location
    vancouver, canada
    MS-Off Ver
    Excel 2010
    Posts
    222

    Convert Daily Stock date into weekly data.

    I see this has been tried many times but I haven't seen a successful stab at it.

    Okay, I have a list of dates and closing prices.

    I've managed to use an array formula:

    =INDEX(A$1:A$4000,SMALL(IF(WEEKDAY($A$1:$A$4000,2)=5,ROW($1:$4000)),ROW(1:1)))

    to pick out the friday values. However, the stock market is closed on some Fridays and even Thursdays occasionally, like at christmas. Sometimes the last day of the week with data is Wednesday. How would you get only the data from the last day of the week.

    Check out the Friday puller in the attached worksheet. It's close but skips a few weeks, like here:

    12/11/1998 1175.25
    12/18/1998 1197.25
    1/8/1999 1287
    1/15/1999 1248.5

    I need the closing value of each week, regardless if it's a 5 day, 4 day or a 3 day week.


    any help is appreciated.
    Attached Files Attached Files
    Last edited by stockgoblin42; 05-23-2012 at 01:06 AM.

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Convert Daily Stock date into weekly data.

    Hi stockgoblin42

    Welcome to the Forum ...

    See if this workbook helps.

    Sheet1 has some basic ideas that you might find useful.

    Sheet2 has a possible solution using a helper column that can be hidden with the grouping button.
    This should be faster than using an array formula.
    Attached Files Attached Files
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  3. #3
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Convert Daily Stock date into weekly data.

    I personally would stay away from arrays, they slow your workbook down too much. If you are open to the idea of a macro then try my workbook.


    Edit: Marcol has done via formula for you, but I made the macro so a may as well post it. Cheers
    Attached Files Attached Files
    Last edited by JapanDave; 05-23-2012 at 05:08 AM. Reason: Marcol beat me to it.
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  4. #4
    Forum Contributor stockgoblin42's Avatar
    Join Date
    05-26-2011
    Location
    vancouver, canada
    MS-Off Ver
    Excel 2010
    Posts
    222

    Re: Convert Daily Stock date into weekly data.

    Thanks JapanDave but no dice as:


    12/12/1997 966.5
    12/19/1997 957.5
    12/24/1997 942.25
    12/26/1997 946
    12/31/1997 979
    1/2/1998 984.75

    24th & 26th in the same week. 31st & 2nd in the same week. Close though, very close.

  5. #5
    Forum Contributor stockgoblin42's Avatar
    Join Date
    05-26-2011
    Location
    vancouver, canada
    MS-Off Ver
    Excel 2010
    Posts
    222

    Re: Convert Daily Stock date into weekly data.

    Thanks Marcol! That's the closest I've ever seen and I can manually check the end of years for errors like:


    Fri 12/26/1997 946
    Wed 12/31/1997 979
    Fri 1/2/1998 984.75
    Fri 1/9/1998 929.5

    as the 31st & 2nd are in the same calendar week, contrary to what excel thinks.

    workable though, thanks!

  6. #6
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Convert Daily Stock date into weekly data.

    Content deleted, post #5 wasn't visible when I posted.

    Happy to help, I've noticed that and other apparent anomalies before.
    Last edited by Marcol; 05-23-2012 at 09:49 AM.

  7. #7
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Convert Daily Stock date into weekly data.

    Ok, I am up for a challenge,

    Try this next file and see how it goes.
    Attached Files Attached Files
    Last edited by JapanDave; 05-23-2012 at 11:12 PM. Reason: Attached the wrong workbook

  8. #8
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Convert Daily Stock date into weekly data.

    @ JapanDave
    Your macro seems to return a mixture of dates as strings and serial dates.

  9. #9
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Convert Daily Stock date into weekly data.

    It does not do that on my machine, which is probably why I did not pick up on it.
    Try this next file, this should fix the problem.
    Attached Files Attached Files

  10. #10
    Forum Contributor stockgoblin42's Avatar
    Join Date
    05-26-2011
    Location
    vancouver, canada
    MS-Off Ver
    Excel 2010
    Posts
    222

    Re: Convert Daily Stock date into weekly data.

    I think that's it! You did it JapanDave! Wow, that macro is beyond me. What's the basic logic you used to solve this?

  11. #11
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Convert Daily Stock date into weekly data.

    It is days of the week, so I just threw the values into an array and took the last value for the week along with the matching date, so it won't matter if there is one day in the week it will take that value and show it for that week.

  12. #12
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Convert Daily Stock date into weekly data.

    So you are saying if Excel, for a date, returns week 53, and the day returned is Mon to Wed, ignore it.

    See the attached workbook.

    1/. Sheet1 is the original formula compared to Daves' results.
    The black cells are where I have moved Daves' result to align with mine.
    This reveals the dates to be removed.

    2/. Sheet2 is the modified formulae, again a comparism is shown with the macro result.
    Column E is not required, I've just retained it as a check column.

    On both sheets you'll notice where I'm still having issues with Daves' dates. (Highlighted white on red)
    This is probably due to regional settings, but it would be worth checking them if you go with the macro.
    Attached Files Attached Files

  13. #13
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Convert Daily Stock date into weekly data.

    Hmm. Marcol, that is very weird. Does this happen on 2003 & 2007 versions?

    It seems the month and day is getting put back to front.

    Can you try this and see if it gives you the same result? I have a feeling it is due to the Japanese ver of excel.
    Attached Files Attached Files

  14. #14
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Convert Daily Stock date into weekly data.

    @ japandave
    That now works for me, both the formula approach, Post#12, and your VBa, Post#13 now match.

    I'd go with the formula method, but then again I'm biased ...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1