Purchase same stock twice
how does the trading company know which one I want to sell? It doesn't need to know. You just sell one. From taxation point of view depending on the country / tax jurisdiction, it can be only be FIFO or specific stock. Investors purchase additional shares all the time. Every investor that adds money to their investments does this every paycheck or every month. Investors do this every time they reinvest dividends, interest or capital gains. They also buy and sell shares when they decide to rebalance their portfolio.  Whether you are investing via a broker, mutual fund or ETF the investment company can handle this issue. You do want to know how they want you to specify which shares you want them to sell. The laws in your country may specify a default procedure, or what needs to be done if you want to use another procedure, or if you are allowed to change once you have specified a procedure.
"It sounds like this is an entirely unsettled question, unfortunately.  In the examples you provide, I think it is safe to say that none of those are 'substantially identical'; a small overlap or no overlap certainly should not be considered such by a reasonable interpretation of the rule. This article on Kitces goes into some detail on the topic.  A few specifics. First, Former publication 564 explains: Ordinarily, shares issued by one mutual fund are not considered to be substantially identical to shares issued by another mutual fund. Of course, what ""ordinarily"" means is unspecified (and this is no longer a current publication, so, who knows). The Kitces article goes on to explain that the IRS hasn't really gone after wash sales for mutual funds: Over the years, the IRS has not pursued wash sale abuses against mutual funds, perhaps because it just wasn’t very feasible to crack down on them, or perhaps because it just wasn’t perceived as that big of an abuse. After all, while the rules might allow you to loss-harvest a particular stock you couldn’t have otherwise, it also limits you from harvesting ANY losses if the overall fund is up in the aggregate, since losses on individual stocks can’t pass through to the mutual fund shareholders. But then goes to explain about ETFs being very different: sell SPY, buy IVV or VTI, and you're basically buying/selling the identical thing (99% or so correlation in stocks owned).   The recommendation by the article is to look at the correlation in owned stocks, and stay away from things over 95%; that seems reasonable in my book as well. Ultimately, there will no doubt be a large number of “grey” and murky situations, but I suspect that until the IRS provides better guidance (or Congress rewrites/updates the wash sale rules altogether!), in the near term the easiest “red flag” warning is simply to look at the correlation between the original investment being loss-harvested, and the replacement security; at correlations above 0.95, and especially at 0.99+, it’s difficult to argue that the securities are not ”substantially identical” to each other in performance. Basically - use common sense, and don't do anything you think would be hard to defend in an audit, but otherwise you should be okay." I think what you're asking is,  Can I buy 1000 shares of the stock at $1.  For $1000.   it goes up to $2, then sell 500 shares of the stock with proceeds of $1000, now   having my original $1000 out of it, and still owning 500 shares.    And that not create a taxable event. Since all I   did was take my cost basis back out, and didn't collect any gains.   And then I want to repeat that over and over. Nope, not in the USA anyway.   Each sale is a separate taxable event. The first sale will have proceeds of $1000 and a cost basis of $500, with $500 of capital gains, and taxes owed at the time of that sale. The remaining stock will have a cost basis of $500 and proceeds of whatever you sell it for in the future. The next batch of stock will have a cost basis of whatever you pay for it.   The only thing that works anything like the way you're thinking, is a Roth IRA...   You can put your cost basis in, pull it back out, and put it back in again, all tax free.   But every time your cost basis cycles in, that counts towed your contribution limits unless you do it fast enough to call it a rollover. No, this is not generally possible, as each security purchase is booked as a separate order => hence separate transaction. You can do this through purchasing of a fund, i.e.: purchasing one share of a ETF will get you a relative share of the ETF holdings, but the actual holdings are not up to you then. Remember that unless you participate in the actual fund that these individuals offer to the public, you will not get the same returns they will. If you instead do something like, look at what Warren Buffet's fund bought/sold yesterday (or even 60 minutes ago), and buy/sell it yourself, you will face 2 obstacles to achieving their returns: 1) The timing difference will mean that the value of the stock purchased by Warren Buffet will be different for your purchase and for his purchase. Because these investors often buy large swathes of stock at once, this may create large variances for 2 reasons: (a) simply buying a large volume of a stock will naturally increase the price, as the lowest sell orders are taken up, and fewer willing sellers remain; and (b) many people (including institutional investors) may be watching what someone like Warren Buffet does, and will want to follow suit, chasing the same pricing problem. 2) You cannot buy multiple stocks as efficiently as a fund can. If Warren Buffet's fund holds, say, 50 stocks, and he trades 1 stock per day [I have absolutely no idea about what diversification exists within his fund], his per-share transaction costs will be quite low, due to share volume. Whereas for you to follow him, you would need 50 transactions upfront, + 1 per day. This may appear to be a small cost, but it could be substantial. Imagine if you wanted to invest 50k using this method - that's $1k for each of 50 companies. A $5 transaction fee would equal 1% of the value of each company invested [$5 to buy, and $5 to sell]. How does that 1% compare to the management fee charged by the actual fund available to you? In short, if you feel that a particular investor has a sound strategy, I suggest that you consider investing with them directly, instead of attempting to recreate their portfolio. "Finding the ""optimal"" solution (and even defining what optimal is) would probably take a lot of searching of all the possible combinations of stocks you could buy, given that you can't buy fractional shares. But I'd guess that a simple ""greedy"" algorithm should get you close enough. For any given portfolio state, look at which stock is furthest below the target size - e.g. in your example, S3 is 3.5% away whereas S1 is only 3.1% away and S2 is over-sized. Then decided to buy one stock of S3, recalculate the current proportions, and repeat until you can't buy more stocks because you've invested all the money. If you have to pay a transaction fee for each kind of stock you purchase you might want to calculate this in larger lot sizes or just avoid making really small purchases." "The wash sale rule only applies when the sale in question is at a loss.  So the rule does not apply at all to your cases 3, 4, 7, 8, 11, 12, 15, and 16, which all start with a gain.  You get a capital gain at the first sale and then a separately computed gain / loss at the second sale, depending on the case, BUT any gain or loss in the IRA is not a taxable event due to the usual tax-advantaged rules for the IRA. The wash sale does not apply to ""first"" sales in your IRA because there is no taxable gain or loss in that case.  That means that you wouldn't be seeking a deduction anyway, and there is nothing to get rolled into the repurchase. This means that the rule does not apply to 1-8.  For 5-8, where the second sale is in your brokerage account, you have a ""usual"" capital gain / loss as if the sale in the IRA didn't happen. (For 1-4, again, the second sale is in the IRA, so that sale is not taxable.) What's left are 9-10 (Brokerage -> IRA) and 13-14 (Brokerage -> Brokerage).   The easier two are 13-14.  In this case, you cannot take a capital loss deduction for the first sale at a loss.  The loss gets added to the basis of the repurchase instead.  When you ultimately close the position with the second sale, then you compute your gain or loss based on the modified basis.  Note that this means you need to be careful about what you mean by ""gain"" or ""loss"" at the second sale, because you need to be careful about when you account for the basis adjustment due to the wash sale. Example 1: All buys and sells are in your brokerage account.  You buy initially at $10 and sell at $8, creating a $2 loss.  But you buy again within the wash sale window at $9 and sell that at $12.  You get no deduction after the first sale because it's wash.  You have a $1 capital gain at the second sale because your basis is $11 = $9 + $2 due to the $2 basis adjustment from wash sale. Example 2: Same as Example 1, except that final sale is at $8 instead of at $12.  In this case you appear to have taken a $2 loss on the first buy-sell and another $1 loss on the second buy-sell.  For taxes however, you cannot claim the loss at the first sale due to the wash.  At the second sale, your basis is still $11 (as in Example 1), so your overall capital loss is the $3 dollars that you might expect, computed as the $8 final sale price minus the $11 (wash-adjusted) basis. Now for 9-10 (Brokerage->IRA), things are a little more complicated.  In the IRA, you don't worry about the basis of individual stocks that you hold because of the way that tax advantages of those accounts work.  You do need to worry about the basis of the IRA account as a whole, however, in some cases.  The most common case would be if you have non-deductable contributions to your traditional IRA.  When you eventually withdraw, you don't pay tax on any distributions that are attributable to those nondeductible contributions (because you already paid tax on that part).  There are other cases where basis of your account matters, but that's a whole question in itself - It's enough for now to understand 1. Basis in your IRA as a whole is a well-defined concept with tax implications, and 2. Basis in individual holdings within your account don't matter. So with the brokerage-IRA wash sale, there are two questions:  1. Can you take the capital loss on the brokerage side?  2. If no because of the wash sale, does this increase the basis of your IRA account (as a whole)?  The answer to both is ""no,"" although the reason is not obvious. The IRS actually put out a Special Bulletin to answer the question specifically because it was unclear in the law. Bottom line for 9-10 is that you apparently are losing your tax deduction completely in that case. In addition, if you were counting on an increase in the basis of your IRA to avoid early distribution penalties, you don't get that either, which will result in yet more tax if you actually take the early distribution. In addition to the Special Bulletin noted above, Publication 550, which talks about wash sale rules for individuals, may also help some." "Yes, this is possible with some companies. When you buy shares of stock through a stock broker, the shares are kept in ""street name.""  That means that the shares are registered to the broker, not to you.  That makes it easy to sell the stock later.  The stock broker keeps track of who actually owns which shares.  The system works well, and there are legal protections in place to protect the investors' assets. You can request that your broker change the stock to your name and request a certificate from the company.  However, companies are no longer required to do this, and some won't.  Your broker will charge you a fee for this service. Alternatively, if you really only want one share for decoration, there are companies that specialize in selling shares of stock with certificates.  Two of them are giveashare.com and uniquestockgift.com, which offer one real share of stock with a stock certificate in certain popular companies.  (Note: I have no experience with either one.)  Some companies no longer issue new stock certificates; for those, these services sell you a replica stock certificate along with a real share of electronic stock.  (This is now the case for Disney and Apple.) With your stock certificate, you are an actual official stockholder, entitled to dividends and a vote at the shareholder meeting. If this is strictly an investment for you, consider the advantages of street name shares: As to your question on buying stock directly from a company and bypassing a broker altogether, see Can I buy stocks directly from a public company?" Okay...yes. However, it's the same issue. Who's going to start offering options first? Who is that person going to be? How are they going to get a hold of the stock? They're going to have to buy it first. That takes us back to the original problem. Simple: Do a stock split. Each 1 Ordinary share now = 100 Ordinary shares (or 100,000 or whatever you choose). Then sell 20 (or 20,000) of them to your third party. (Stock splits are fairly routine occurrence. Apple for example has done several, most recently in 2014 when 1 share = 7 shares). Alternatively you could go the route of creating a new share class with different rights, preferences etc. But this is more complicated. How about this rule? Sell 10% of your shares every time they double in price.  (of course, only buy stocks that repeatedly double in price) "Note that these used to be a single ""common"" share that has ""split"" (actually a ""special dividend"" but effectively a split). If you owned one share of Google before the split, you had one share giving you X worth of equity in the company and 1 vote. After the split you have two shares giving you the same X worth of equity and 1 vote. In other words, zero change. Buy or sell either depending on how much you value the vote and how much you think others will pay (or not) for that vote in the future.  As Google issues new shares, it'll likely issue more of the new non-voting shares meaning dilution of equity but not dilution of voting power. For most of us, our few votes count for nothing so evaluate this as you will.  Google's founders believe they can do a better job running the company long-term when there are fewer pressures from outside holders who may have only short-term interests in mind. If you disagree, or if you are only interested in the short-term, you probably shouldn't be an owner of Google. As always, evaluate the facts for yourself, your situation, and your beliefs." Not illegal, its called treasury stock; happens all the time. Its used to increase the equity (and in theory, stock price) for the remaining shareholders.  A public company won't be a able to repurchase all of its shares unless the company has decided to go private. In that case, a person or other entity will usually purchase all of the outstanding shares of the company, usually at a premium. "According to page 56 of the 2015 IRS Publication 550 on Investment Income and Expenses: Wash sales. Your holding period for substantially identical stock or securities you acquire in a wash sale includes the period you held the old stock or securities. It looks like the rule applies to stocks and other securities, including options. It seems like the key is ""substantially identical"". For your brokerage / trading platform to handle these periods correctly for reporting to IRS, it seems best to trade the same security instead of trying to use something substantially identical." "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." "Scenario 1 - When you sell the shares in a margin account, you will see your buying power go up, but your ""amount available to withdraw"" stays the same until settlement. Yes, you can reallocate the same day, no need to wait until settlement. There is no margin interest for this scenario.  Scenario 2 -  If that stock is marginable to 50%, and all you have is $10,000 in that stock, you can buy another $10,000. Once done, you are at 50% margin, exactly."