473,387 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Number of days stock held

Hello,

Does anyone have a formula for calculating the number of days a
stock was owned? Of course its real easy if you buy 100 shares on
April 1 and sell 100 shares on July 1 but what about multiple buys and
sells of different number of shares.

As an example: Buy 100 April 1, Buy 200 May 1, Sell 50 June 1,
Sell 250 July 1. For tax purposes we need to know the average number
of days the stock was held. In the calculation, I believe you have to
use the FIFO method. I was considering something like share/days but
wasn't sure how to implement it.

Any ideas would be appreciated.

Thanks,
Hank Reed

Mar 27 '06 #1
2 3363
I dont have any code but this is how I woudl lay out the data:-

Table - Stocks
... Holds stock information, ( stockID [unique primary key],company,
nominal value, market traded upon etc)

Table - Purchases
... Holds Purchase information (Purchase ID [Unique Primary], Stock ID,
Purchase Date, Purch Qty, Unit Value, Total Purchase.

Table - Sales
... Holds Sales information Sales ID [Unique Primary], Stock ID, Sale
Date, Sale Qty, Unit Value, Total Sale price

Table - SP Matches
... Holds Match ID [unique Primary] , Stock ID, Purch ID, Sales ID, Qty
As each Sale could come from many purchases and one purchase could
result in many sales, the SP Matches table would be used to work out
how many of each Purchase instance went to each sale. You can then
work out the # days for each assignment and the net gain or loss.
Weighted averages can then be applied if necessary.

You would create the SP match records by looking at the sale qty and
finding the last unmatched purchase record for the stock and generating
the SP match record with the lesser of unmatched Purchase Qty or sale
qty. If the sale qty > unmatched Purchase Qty, you would need to
create a second SP Match record for the balance against the next
purchase. Obvioulsy you would want some sanity checks so that you
could not match sales with purchases that happened after the sale
(unless you are playing futures markets!!)

You would probably also need to consider what you would do for share
splits and consolidations / rights issues / sahre conversions.

Incidentally this technique is also very useful for matching invoices
to reciepts if you are running any sort of accouting functions.

Mar 27 '06 #2
Aaron,

Thanks for the input. I actually download the transactions from my
stock site (unfortunately in .csv format) I convert them to an .xls and
then import them straight into my database. So all the buys, sells,
dividends, and splits are in one table, but they are clearly marked and
easy to sort through.

Your approach makes sense. Each Sell must be reconciled against a
previous Buy. I don't do short sales or futures. Using the FIFO
idea, which is what you are doing, I can calculate the actual number of
days each share is held. I'm sure you know that you are taxed much
higher on profits on stocks held less that one year. Kind of takes the
fun out of day trading, doesn't it?

The dividends only effect profit and loss, and not days held, so I
ignore them in this calculation. However, it was good that you pointed
out the situation with the stock splits ( I forgot ) because they are
just another Buy with no cost. And again we are just concerned with
days here, not dollars.

I do keep a separate table with the basic stock information, like
Symbol, Company Name, and almost anything else I can dredge up from the
stock analysis screen. I call them tiebreakers and you can pick
anything that you think will help make a decision. Analyst's
recommendations, Technical analysis, PE, Volume, et cetera.

In my day job ;-), I do reconcile Invoices but, unlike my stock shares,
they are serialized or at least numbered.

I'll keep working on it.

Thanks,
Hank Reed

Mar 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Marion Slaughter | last post by:
----FA48570F00BB51C Content-Type: text/html; charset="iso-35B2-E" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head>...
7
by: Shuffs | last post by:
Could someone, anyone please tell me what I need to amend, to get this function to take Sunday as the first day of the week? I amended the Weekday parts to vbSunday (in my code, not the code...
52
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
1
by: cknkomo | last post by:
Hie I am learning VB and I have a table with the following fields: - EmployeeNo - Date of Engagement - From Date - End Date - Days Acrued - Days taken
2
by: tyeung168 | last post by:
I am taking a C++ class in college and having problems completing last week's homework. Any help is greatly appreciated. The program is to read from a filing containing stock trades. Here is...
1
by: asmusdk | last post by:
I am working on creating a stock management database for a small company. The company receives the merchandise from a handful of suppliers and stocks it before it is sent to the customers –...
1
by: zafm86 | last post by:
Hi everyone! I'm sure my problem is pretty easy to solve but I've been working on it for a long and my my brain is not working correctly anymore. I'm working with an AS400 and I mhave to do an...
0
by: john | last post by:
SETP-08 Draft paper submission deadline is just few days from now The 2008 International Conference on Software Engineering Theory and Practice (SETP-08) (website: www.PromoteResearch.org ) will...
0
by: john | last post by:
EISWT-08 Draft paper submission is deadline is just few days from now The 2008 International Conference on Enterprise Information Systems and Web Technologies (EISWT-08) (website:...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.