Short or Long Term Capital Gains for Multiple Investments
The default is FIFO: first in - first out. Unless you specifically instruct the brokerage otherwise, they'll report that the lot you've sold is of Jan 5, 2011. Note, that before 2011, they didn't have to report the cost basis to the IRS, and it would be up to you to calculate the cost basis at tax time, but that has been changed in 2011 and you need to make sure you've instructed the brokerage which lot exactly you're selling. I'm assuming you're in the US, in other places laws may be different. Tell your broker.  You can usually opt to have certain positions be FIFO and others LIFO.  Definitely possible with Interactive Brokers.
No matter what, you owe taxes on the gains, known as capital gains. How much, depends on how long you invested it for. In your example, each month is treated separately - each month you contribute starts a new clock on that set of investments. If you hold it for longer than a year, the taxes are treated as long-term, and less than a year is short-term. Short term taxes are at your marginal rate, and long term taxes are different, usually 15%. https://www.irs.gov/taxtopics/tc400/tc409 "An investment is sold when you sell that particular stock or fund. It doesn't wait until you withdraw cash from the brokerage account. Whether an investment is subject to long term or short term taxes depends on how long you held that particular stock. Sorry, you can't get around the higher short term tax by leaving the money in a brokerage account or re-investing in something else. If you are invested in a mutual fund, whether it's long or short term depends on when you buy and sell the fund. The fact that the fund managers are buying and selling behind your back doesn't affect this. (I don't know what taxes they have to pay, maybe you really are paying for it in the form of management fees or lower returns, but you don't explicitly pay the tax on these ""inner"" transactions.) Your broker should send you a tax statement every year giving the numbers that you need to fill in to the various boxes of your income tax form. You don't have to figure it out. Of course it helps to know the rules. If you've held a stock for 11 1/2 months and are planning to sell, you might want to consider waiting a couple of weeks so it becomes a long term capital gain rather than short term and thus subject to lower tax." It is worth noting first that interest and short-term dividends/capital gains are all taxed at the same rate. So all the investments below I mention (even savings accounts) will be taxed at the same rate.  Also, even short-term capital losses can often be harvested to reduce your tax rate in many countries. While it is worth paying attention to the taxes when investing in the short term the more important factor is how much risk that you can take or want to take with the money.  Most equity portfolios like the S&P index give a much higher risk that there will be much less in the account when you need to buy.  You generally have a higher expected return with equity but as you mention that return is very random over such a short period. Over such a short variable period many people will invest in short term bond-index funds or just keep the fund in a high-yielding savings account.  With the savings account your money is guaranteed.  Short term bond funds will have generally higher yields but a small chance you may lose money in the short term. Some people can trade short-term bond indices for free with their broker but if you can't be sure to include the trading costs when thinking about which investment to use as with how low yields are currently the fees may eat up any advantage you gain. Long term gains are taxed at 15% maximum.  Losses, up to the $3K/yr you cited, can offset ordinary income, so 25% or higher, depending on your income. Better to take the loss that way. With my usual disclaimer: Do not let the tax tail wag the investing dog. "From Intuit: ""Yes, but there are limits. Losses on your investments are first used to offset capital gains of the same type. So short-term losses are first deducted against short-term gains, and long-term losses are deducted against long-term gains. Net losses of either type can then be deducted against the other kind of gain."" ""If you have an overall net capital loss for the year, you can deduct up to $3,000 of that loss against other kinds of income, including your salary, for example, and interest income. Any excess net capital loss can be carried over to subsequent years to be deducted against capital gains and against up to $3,000 of other kinds of income."" So in your case, take the loss now if you have short term gains.  Also take it if you want to take a deduction on your salary (but this maxes at 3k, but you can keep using an additional 3k each year into the future until its all used up). There isn't really an advantage to a long term loss right now (since long term rates are LOWER than short term rates)." In the United States Short-term capital gains are taxed at rates similar to regular income which is 25% if you make less than $91,000 and 28% if you make more than that but less than $190,000. If you make more than $190,000 then the rate is 33%. If you hold the stock for a year or more than the tax rate is 15%, unless your income is less than $33,000 in which case there is no tax on long-term gains. As a general rule, the way to make money is to stay out of debt, so I cannot advise you to assume a mortgage. Financially you are better off investing your money. Much like you I bought a house with a mortgage using about $30,000 in a down payment about 20 years ago and I paid it off a few years ago. If I had to do it over again, I would have bought a shack (a steel building) for $30,000 and lived in that and invested my income. If I had done that, I would be about $500,000 richer today than I am now. Indeed, there's no short term/long term issue trading inside the IRA, and in fact, no reporting. If you have a large IRA balance and trade 100 (for example) times per year, there's no reporting at all.  As you note, long term gains outside the IRA are treated favorably in the tax code (as of now, 2012) but that's subject to change. Also to consider, The worst thing I did was to buy Apple in my IRA. A huge gain that will be taxed as ordinary income when I withdraw it. Had this been in my regular account, I could sell and pay the long term cap gain rate this year.  Last, there's no concept of Wash sale in one's IRA, as there's no taking a loss for shares sold below cost. (To clarify, trading solely within an IRA won't trigger wash sale rules. A realized loss in a taxable account, combined with a purchase inside an IRA can trigger the wash sale rule if the stock is purchased inside the IRA 30 days before or after the sale at a loss. Thank you, Dilip, for the comment.) Aside from the warnings of trading too much or running afoul of frequency restrictions, your observation is correct. For reporting purposes, I would treat the purchase and sale of gold like a purchase and sale of a stock. The place to do so is Schedule D. (And if it's the wrong form, but you reported it, there is might not be a penalty, whereas there is a penalty for NOT reporting.) The long term gain would be at capital gains rates. The short term gain would be at ordinary income rates. And if you have two coins bought at two different times, you get to choose which one to report (as long as you report the OTHER one when you sell the second coin). "Generally if you are using FIFO (first in, first out) accounting, you will need to match the transactions based on the number of shares. In your example, at the beginning of day 6, you had two lots of shares, 100 @ 50 and 10 @ 52.  On that day you sold 50 shares, and using FIFO, you sold 50 shares of the first lot.  This leaves you with 50 @ 50 and 10 @ 52, and a taxable capital gain on the 50 shares you sold. Note that commissions incurred buying the shares increase your basis, and commissions incurred selling the shares decrease your proceeds.  So if you spent $10 per trade, your basis on the 100 @ 50 lot was $5010, and the proceeds on your 50 @ 60 sale were $2990.  In this example you sold half of the lot, so your basis for the sale was half of $5010 or $2505, so your capital gain is $2990 - 2505 = $485. The sales you describe are also ""wash sales"", in that you sold stock and bought back an equivalent stock within 30 days.  Generally this is only relevant if one of the sales was at a loss but you will need to account for this in your code.  You can look up the definition of wash sale, it starts to get complex. If you are writing code to handle this in any generic situation you will also have to handle stock splits, spin-offs, mergers, etc. which change the number of shares you own and their cost basis.  I have implemented this myself and I have written about 25-30 custom routines, one for each kind of transaction that I've encountered.  The structure of these deals is limited only by the imagination of investment bankers so I think it is impossible to write a single generic algorithm that handles them all, instead I have a framework that I update each quarter as new transactions occur." It was not 100% clear if you have held all of these stocks for over a year.  Therefore, depending on your income tax bracket, it might make sense to hold on to the stock until you have held the individual stock for a year to only be taxed at long-term capital gains rates.  Also, you need to take into account the Net Investment Income Tax(NIIT), if your current modified adjusted income is above the current threshold.  Beyond these, I would think that you would want to apply the same methodology that caused you to buy these in the first place, as it seems to be working well for you. 2 & 3. No.  You trigger a taxable event and therefore have to pay capital gains tax on any gains.  If you have a loss in the stock and repurchase the stock within 30 days, you don't get to recognize the loss and have to add the loss to your basis in the stock (Wash Sales Rules). "You cannot get ""your investment"" out and ""leave only the capital gains"" until they become taxable at the long-term rate. When you sell some shares after holding them for less than a year, you have capital gains on which you will have to pay taxes at the short-term capital gains rate (that is, at the same rate as ordinary income).  As an example, if you bought 100 shares at $70 for a net investment of $7000, and sell 70 of them at $100 after five months to get your ""initial investment back"", you will have short-term capital gains of $30 per share on the 70 shares that you sold and so you have to pay tax on that $30x70=$2100. The other $4900 = $7000-$2100 is ""tax-free"" since it is just your purchase price of the 70 shares being returned to you.  So after paying the tax on your short-term capital gains, you really don't have your  ""initial investment back""; you have something less. The capital gains on  the 30 shares that you continue to hold will become (long-term capital gains) income to you only when you sell the shares after having held them for a full year or more: the gains on the shares sold after five months are taxable income in the year of sale." "It's a tricky question w/out more context. If your only options are between stock/funds and letting it sit (i.e. in a saving or CD), I'd have to say option one is the way to go (but that's based on my situation, and you did ask ""if you .."").  However, I think the true answer is ""it depends."" It depends on your risk tolerance and what are your short-term vs. long-term financial needs. Only after answering those questions you can then seek to strategize and diversify investment accordingly." To try to answer the three explicit questions: Every share of stock is treated proportionately: each share is assigned the same dollar amount of investment (1/176th part of the contribution in the example), and has the same discount amount (15% of $20 or $25, depending on when you sell, usually). So if you immediately sell 120 shares at $25, you have taxable income on the gain for those shares (120*($25-$17)). Either selling immediately or holding for the long term period (12-18 mo) can be advantageous, just in different ways.   Selling immediately avoids a risk of a decline in the price of the stock, and allows you to invest elsewhere and earn income on the proceeds for the next 12-18 months that you would not otherwise have had.  The downside is that all of your gain ($25-$17 per share) is taxed as ordinary income.   Holding for the full period is advantageous in that only the discount (15% of $20 or $25) will be taxed as ordinary income and the rest of the gain (sell price minus $20 or $25) will be taxed at long-term capital gain tax rates, which generally are lower than ordinary rates (all taxes are due in the year you do sell).  The catch is you will sell at different price, higher or lower, and thus have a risk of loss (or gain). You will never be (Federally) double taxed in any scenario.  The $3000 you put in will not be taxed after all is sold, as it is a return of your capital investment.  All money you receive in excess of the $3000 will be taxed, in all scenarios, just potentially at different rates, ordinary or capital gain.  (All this ignores AMT considerations, which you likely are not subject to.) I don't see a tag for United States, so I'm having to assume this is US taxes.  It doesn't matter what app you use, IRS trades are all calculated the same. First, you have to report each trade on a 8949 and from that the totals go into a schedule D.  Short term trades are stocks that you've kept exactly one year or less, long term trades are for 1 year + 1 day or more.  Trades where you sold a stock for a loss, then bought that stock back again under 30 days don't get to count as a loss.  This only affects realized capital gains and losses, you don't count fees. First, take all of your short term gains then offset them by all of your short term losses.  Do the same for long term gains and losses.  Short and long term gains are taxed at different rates.  You can deduct losses from short term to your long term and vice versa.  Then you can deduct the total losses up to $3000 (household, $1500 married, filing separately) per year on your regular income taxes or other dividend taxes.  If you have over $3000 in losses, then you need to carry that over to subsequent years. Edited per Dave's comments: thanks Dave "If you only have to pay 23k federal taxes on 100k, that means you are in the long term capital gains tax rate, which is the lower of the tax rates available. First you get your federal income tax marginal tax rate, and then find the matching long term capital gains tax rate. For example, if your marginal federal income tax rate is 28%, your capital gains tax rate would be 15%. Or rather, if the amount of the gain would put you in the 28% rate, then your long term capital gains tax rate is 15%. You can reduce that by having more losses. If you have anything else invested anywhere that is taking a loss, then you can sell that this year and it will offset the other gains you have realized. The only note is that your losses have to be long term capital losses too. Tax loss harvesting takes this to an extreme where you sell something at a loss to lock in the tax loss, but you didn't really want to get rid of that investment, so then you buy a nearly identical investment. ie. if you owned shares of ""Direxion Tech Sector ETF"" and it was at a loss, you would sell that and then immediately buy ""ProShares Tech Sector ETF"", the competing product that does the exact same thing. Then there is charity. This still requires spending money and you not having it any longer. If you feel that a cause can use the money more directly than the US government, you can donate an appreciated asset to the charity - not report a gain and also take a charitable deduction."