+ Reply to Thread
Results 1 to 3 of 3

calculating averages which reset if conditions are met

  1. #1
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    calculating averages which reset if conditions are met

    I've attached a workbook which has 6 columns of data (stock purchased and sold).

    The purchases and sales are not "matched" one to one. There are partial sales, and dates where stock is both bought and sold.

    Over a period of two weeks, the net shares held may go from zero to 200, and back to zero. Then the cycle begins again.

    For each cycle, I want to get the average price of shares, updated daily as shares are bought and sold within that cycle.

    I've tried some nested "if/then" formulas, and have almost solved the problem, but it eventually falls apart. (See worksheet, highlighted row).

    I'm hoping one of you geniuses can help me find a solution. As always, I'll very much appreciate any help!
    Attached Files Attached Files
    Last edited by jrtaylor; 06-07-2017 at 05:38 PM.

  2. #2
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: calculating averages which reset if conditions are met

    So, your new average price should just be the new cost plus the cost of the currently held shares (# shares * avg price) divided by the new total of shares. This should get you the proper weighted average.
    In cell R7, then drag down.
    =IF(O7+P7,(P6*R6+N7)/(O7+P7),0)

    Note, however, that there is a problem when you combine a purchase and a sell at the same time. Not sure why you would do that, but timing is everything. Buying then selling would yield a different average than selling then buying. For this exercise I followed your lead of buying then selling so that our numbers matched until you ran into difficulty.
    Pauley
    --------
    If I helped with your issue, I'd appreciate a rep bump (hit the '*' icon to the bottom left of this post).

  3. #3
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Re: calculating averages which reset if conditions are met

    Hi Pauley, thanks for that help. I appreciate it. Note that this particular strategy involves (but is not limited to) closing out positions at a fixed duration, whether or not a position is immediately reopened. For purposes of this exercise, I am making the assumption that price does not change much over a 10 minute +/- period during the closing/opening of positions.

    And I'll take into account your note about short vs long positions. Thanks again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Calculating Time Averages with conditions
    By HeyInKy in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-10-2016, 02:10 PM
  2. Getting graph to reset when conditions are met
    By bouncingbudha in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 07-21-2014, 07:22 PM
  3. Averages - with conditions
    By stevestodola in forum Excel General
    Replies: 4
    Last Post: 09-08-2011, 09:48 AM
  4. Calculating averages based on conditions
    By nmitch59 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-05-2009, 04:20 AM
  5. calculating Averages based upon conditions
    By Kfetterman1 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-27-2006, 11:24 AM
  6. Calculating Cell Averages Based upon conditions
    By Kfetterman1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-26-2006, 10:11 PM
  7. [SOLVED] calculating averages
    By Golf Averages in forum Excel General
    Replies: 1
    Last Post: 08-15-2005, 04:05 PM

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