+ Reply to Thread
Results 1 to 15 of 15

For stock trade profile, calculate the new positions and add new stock to the new row

  1. #1
    Registered User
    Join Date
    09-22-2017
    Location
    Hong Kong
    MS-Off Ver
    Office 10
    Posts
    21

    For stock trade profile, calculate the new positions and add new stock to the new row

    Hi my friends! I need some help on the attached Excel file . Please give me a hand if you don't mind.
    This excel is for stock trading position record. I would like to automatically add (by using VBA I guess) the new trade position to stocks I have bought (like the first five trades on AAPL &BABA on the "NEW TRADE" and add the trade on a new row if I have no existing position on the stock (like the sixth trade on AMZN on the sheet "NEW TRADE"). Pleas forgive me if what Im saying is confusing Since I am not a English native speaker.
    Attached Files Attached Files
    Last edited by sunnyray25; 02-12-2018 at 02:01 AM.

  2. #2
    Forum Contributor
    Join Date
    01-03-2018
    Location
    Fukuoka, Japan
    MS-Off Ver
    Excel 2013
    Posts
    123

    Re: For stock trade profile, calculate the new positions and add new stock to the new row

    Hi, sunnyray.

    To get straight to the point, what you want to do is to add the new trade position to the "Existing Position", right?

  3. #3
    Registered User
    Join Date
    09-22-2017
    Location
    Hong Kong
    MS-Off Ver
    Office 10
    Posts
    21

    Re: For stock trade profile, calculate the new positions and add new stock to the new row

    Thank you for your reply, Jujin!

    For stocks like BABA/ AAPL I have existing position, I would like to recalculate the new average price and number of shares.
    FOr sotcks like AMZN I have no existing position AMZN, I would like to create a new row for the new stock like AMZN.

    On my example workbook, spreadsheet "New Trade" means the trades I would like to add to the spreadsheet "Existing Position", and the spreadsheet "Existing P + New Trade" mean the final result I need. I wish to add a button to get the new result automatically.

    I am not certain, but the logic could be
    1.) look up the the Stock Code (Cell A2 on spreadsheet "New Trade") on spreadsheet "Existing position"
    2.) If yes (Cell A2= BABA, which exists on the spreadsheet" Existing Position", then it will recalculate the new average price and number of shares.
    3.)If no (Cell A7 = AMZN, then I would like to add a new row under the last row of the spreadsheet "Existing Position.

    Your help will be really appreciated!

  4. #4
    Forum Contributor
    Join Date
    01-03-2018
    Location
    Fukuoka, Japan
    MS-Off Ver
    Excel 2013
    Posts
    123

    Re: For stock trade profile, calculate the new positions and add new stock to the new row

    I think I can figure out what you want, but I'd like to ask you some more questions.

    In "New Trade" sheet, do you enter the data manually and click the button to do the job (recalculating etc)?

    If Stock Code is not found in "New Trade", Stock Code and Company Name will be copied from "New Trade" to "Existing Position", but how about Average Price or Long Positions? Where do they come from? Can they also be copied from "New Trade"?

  5. #5
    Registered User
    Join Date
    09-22-2017
    Location
    Hong Kong
    MS-Off Ver
    Office 10
    Posts
    21

    Re: For stock trade profile, calculate the new positions and add new stock to the new row

    Thank you for your help! Please see the colored reply below.

    Quote Originally Posted by yujin View Post
    I think I can figure out what you want, but I'd like to ask you some more questions.

    In "New Trade" sheet, do you enter the data manually and click the button to do the job (recalculating etc)?
    Yes, I would enter the data manually , and a macro the do the job.

    If Stock Code is not found in "New Trade", Stock Code and Company Name will be copied from "New Trade" to "Existing Position", but how about Average Price or Long Positions? Where do they come from? Can they also be copied from "New Trade"?
    For the stock code cannot be found in "New Trade", they will be just copied from the "New Trade"by the macro.

  6. #6
    Forum Contributor
    Join Date
    01-03-2018
    Location
    Fukuoka, Japan
    MS-Off Ver
    Excel 2013
    Posts
    123

    Re: For stock trade profile, calculate the new positions and add new stock to the new row

    The last thing I want to know is how to recalculate the average prices in "Existing Position".
    Will you show me the formula to calculate them?

  7. #7
    Registered User
    Join Date
    09-22-2017
    Location
    Hong Kong
    MS-Off Ver
    Office 10
    Posts
    21

    Re: For stock trade profile, calculate the new positions and add new stock to the new row

    Quote Originally Posted by yujin View Post
    The last thing I want to know is how to recalculate the average prices in "Existing Position".
    Will you show me the formula to calculate them?
    It will be like
    1.) 'New Trade!' Cell(Ai) lookup with 'Existing Position!' Cell(Ai) [ for example, BABA = 'New Trade!' Cell(A2) = 'Existing Position!' Cell(A2)

    2.) [('New Trade!' Cell(C2) * 'New Trade!' Cell(E2)) +('Existing Position!' Cell(C2)*'Existing Position!' Cell(D2)]/('New Trade!' Cell(E2)+'Existing Position!' Cell(D2))---------->[(174*(-25))+(150*500)]/(500+(-25))

    3.) then loop it for every row on "New Trade"

    P.S. when the number of shares are in the column "Short Position" which should be negative, and I can just fix it by adding one more column with formula [=-(cell), so basically ignore the negative sign.

    Thanks a lot Yujin.
    I just cant find something similar online to be an example to amend, and I don't know how to build a macro like this.

  8. #8
    Forum Contributor
    Join Date
    01-03-2018
    Location
    Fukuoka, Japan
    MS-Off Ver
    Excel 2013
    Posts
    123

    Re: For stock trade profile, calculate the new positions and add new stock to the new row

    So, "Average Price" and "Long/Short Positions" in "Existing Position" are fixed values.
    And values in "Existing P + New Trade" are to be recalculated.

    Is my understanding correct?

  9. #9
    Registered User
    Join Date
    09-22-2017
    Location
    Hong Kong
    MS-Off Ver
    Office 10
    Posts
    21

    Re: For stock trade profile, calculate the new positions and add new stock to the new row

    Quote Originally Posted by yujin View Post
    So, "Average Price" and "Long/Short Positions" in "Existing Position" are fixed values.
    And values in "Existing P + New Trade" are to be recalculated.

    Is my understanding correct?
    The most ideal way is that Both "Average Price" and "Long/Short Positions" can be updated on Existing Position". But I am not sure if it will get error easily. Otherwise, I can just create another spreadsheet for it and make them be fixed value in "Existing Position"

  10. #10
    Forum Contributor
    Join Date
    01-03-2018
    Location
    Fukuoka, Japan
    MS-Off Ver
    Excel 2013
    Posts
    123

    Re: For stock trade profile, calculate the new positions and add new stock to the new row

    Sorry to take some time to understand what you want.
    But I've got to get it straight to write the code.

    C2 cell in "Existing P + New Trade" sheet has the formula below.
    =(((174*-25)+(169*50)+(172*-70)+(150*500))/(500-20-70+50))

    Bold red numbers (500 and 150) are from C2 or D2 cell in "Existing Position" if I understand correctly.

    But C2 and D2 in "Existing Position" has no formula but fixed value.
    That's why I considered these values would be fixed.

  11. #11
    Registered User
    Join Date
    09-22-2017
    Location
    Hong Kong
    MS-Off Ver
    Office 10
    Posts
    21

    Re: For stock trade profile, calculate the new positions and add new stock to the new row

    Quote Originally Posted by yujin View Post
    Sorry to take some time to understand what you want.
    But I've got to get it straight to write the code.
    Instead, I really appreciate your help Yujin.

    C2 cell in "Existing P + New Trade" sheet has the formula below.
    =(((174*-25)+(169*50)+(172*-70)+(150*500))/(500-20-70+50))

    Bold red numbers (500 and 150) are from C2 or D2 cell in "Existing Position" if I understand correctly.

    But C2 and D2 in "Existing Position" has no formula but fixed value.
    That's why I considered these values would be fixed.
    The spreadsheet "Existing P + New Trade" actually is the completed version of "Existing Position" after running macro.
    "Existing Postion" is the raw/"pre edit" version. just like before and after.

  12. #12
    Forum Contributor
    Join Date
    01-03-2018
    Location
    Fukuoka, Japan
    MS-Off Ver
    Excel 2013
    Posts
    123

    Re: For stock trade profile, calculate the new positions and add new stock to the new row

    Here's the code I've written. Maybe it's a little slow, I guess.
    Try it and tell me if there's something wrong.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    09-22-2017
    Location
    Hong Kong
    MS-Off Ver
    Office 10
    Posts
    21

    Re: For stock trade profile, calculate the new positions and add new stock to the new row

    Really appreciate your help Jujin! It works very great, and now I have one more template to study! You are amazing man!!

  14. #14
    Forum Contributor
    Join Date
    01-03-2018
    Location
    Fukuoka, Japan
    MS-Off Ver
    Excel 2013
    Posts
    123

    Re: For stock trade profile, calculate the new positions and add new stock to the new row

    You are welcome.
    But the code might be insufficient for practical use, I guess.
    Please feel free to ask if you need a hand.

  15. #15
    Registered User
    Join Date
    09-22-2017
    Location
    Hong Kong
    MS-Off Ver
    Office 10
    Posts
    21

    Re: For stock trade profile, calculate the new positions and add new stock to the new row

    Sure! I am still studying the code you provided. its really well organized!

+ 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. Trying to build Function to calculate average of stock returns, with stock prices as input
    By jameslaughlin129 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-16-2017, 05:18 PM
  2. Replies: 31
    Last Post: 10-28-2015, 01:54 AM
  3. Replies: 4
    Last Post: 01-29-2013, 02:26 AM
  4. VBA code to separate open and closed stock positions
    By RunninRebel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-06-2012, 10:44 AM
  5. Replies: 0
    Last Post: 10-28-2012, 07:22 AM
  6. Replies: 0
    Last Post: 09-25-2012, 09:39 AM
  7. New stock positions across account numbers
    By Dexterddog in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-06-2012, 07:21 AM

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