--
---
You received this message because you are subscribed to the Google Groups "Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ledger-cli+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
* Martin Blais <bl...@furius.ca> [2014-06-12 02:05]:
> I don't understand how it works in your example. You're entering...
> the positions with price conversion, using the @ sign:
>
> 2014-01-01 Details for shares
> Assets:Investments:Stocks:Share A 15 ShareA @ 20€
> Assets:Investments:Stocks:Share B 5 ShareB @ 100€
> Equity:Opening Balance
>
> But his sale is using the "cost" syntax (with {}):
> How does this work under the covers?When you specify a cost with @, ledger internally keeps this cost
around. You'll have 15 ShareA {€20}. You can see this with
--lot-prices:
15 ShareA {€20} Share A
5 ShareB {€100} Share B
So when you sell, what you do by saying 5 ShareB {€100} @ €120 is that
you're selling the 5 particular ShareB with a cost of €100.
Consider you bought 5 ShareB at 100€ and 5 at 110€. Then you'd have:
5 ShareB {€100}
5 ShareB {€110} Share B
So which one are you selling? You indicate that by using the {..}
syntax.
> The price/rate is used to balance the transaction but the units areI think I actually disagree with this particular example. When I get
> deposited in the account without associated cost. This is what you
> would do, for instance, if you were making a withdrawal in a foreign
> country, e.g. in JPY and then spend it locally: you never think of
> these yen in your wallet as "being held at such and such" exchange
> rate, once converted, they have no "cost" to them anymore, all the
> bills are just "yen".
JPY out of an ATM, I'd say that a very clear exchange rate is attached
to those JPY (because you know exactly how much you paid in your local
currency).
But let's imagine you travel to Japan twice and you still have some
JPY left over from the previous trip. And now you go to the ATM
again. Then you have, let's say:
20000 JPY {$0.0090}
10000 JPY {$0.0098} Assets:Cash
So now things get complicated. The best solution would probably be to
just calculate the average cost and use that.
I suspect most people don't handle this correctly (me included :)
When you use --lot-prices, you actually see what's going on. I
suspect most people do something like this:
2014-03-01 * Buy JPY
Assets:Cash 10000 JPY @@ $98
Assets:Cash
2014-03-02 * Spend JPY
Expenses:Foo 10000 JPY
Assets:Cash -10000 JPY
And now ledger will say: ledger -f ~/e bal ets:cash
$-98 Assets:Cash
So everything *looks* great. But if you add --lot-prices, you see
that it's a mess:
$-98
-10000 JPY
10000 JPY {$0.0098} Assets:Cash
You have -10000 JPY and 10000 JPY {$0.0098}. This is because you
didn't specify the cost. You should have done:
2014-03-02 * Spend JPY
Expenses:Foo 10000 JPY {$0.0098}
Assets:Cash -10000 JPY {$0.0098}
But who does that?
> (In fact, if you're homed in multiple countries and hold assets inYes, I agree. Unfortunately, this situation applies to me and I
> many places, holding currencies at cost creates incredible
> unnecessary complexities, I'm quite certain this is not what's
> happening).
struggle with this all the time.
The method used in the cookbook, is not correct.
The cookbook uses the example of buying 10 shares of IBM at $160 and then selling those shares at $170. Without commissions, that would amount to a realized gain of $100, $1700 (the sales price) - $1600 (the cost basis). With commissions, however, the reportable gain is really $1700 (the sales price) - $9.95 (commission on the sale) - $1600 (basis) - $9.95 (commission on purchase) = $80.10. The method in the cookbook only accounts for the sale commission when figuring the capital gain.
So what's the right way to do this, accounting for commission on purchase. Note that if only part of the purchased shares are sold the commission is prorated, so the actual basis is $1609.95 or $160.995 per share.
On Fri, Jun 13, 2014 at 9:01 AM, Rick F <ri...@farnbach.com> wrote:
The method used in the cookbook, is not correct.That's not exactly true: it's correct if your definition of capital gain does not take into account commissions. I used the definition that excludes capital gains in order to keep things simple (the level of discussion I chose in that doc is that congruent with trying to explain P/L clearly, intro level). Whether you should be able to exclude commissions or not from your gains is a matter tax law, and it depends on your own situation.Thanks for bringing up the topic, though, I admit I did forget to explain it. I'll add a separate section about commissions. I'm well aware of this.At the moment, I simply subtract the commissions from the gains for reporting. The gains and commissions get counted in separate accounts (which is mostly fine, except for the prorating detail you bring up below). You can subtract the total commissions from total gain for a good approximation of gains-without-commissions. Most of my trading accounts already provide a suitable 1099 so I use my own accounting on these accounts for tax planning and cross-checking against their calculations, and I use the 1099 forms for tax reporting.The cookbook uses the example of buying 10 shares of IBM at $160 and then selling those shares at $170. Without commissions, that would amount to a realized gain of $100, $1700 (the sales price) - $1600 (the cost basis). With commissions, however, the reportable gain is really $1700 (the sales price) - $9.95 (commission on the sale) - $1600 (basis) - $9.95 (commission on purchase) = $80.10. The method in the cookbook only accounts for the sale commission when figuring the capital gain.Actually, that's incorrect, the method I described does exclude the commission from the gain on BOTH sides and will thus calculate a gain of 100$ (no commissions at all).So what's the right way to do this, accounting for commission on purchase. Note that if only part of the purchased shares are sold the commission is prorated, so the actual basis is $1609.95 or $160.995 per share.That's a great question.Again, how it should be done is a matter of tax law, it's a choice, but this is indeed a sensible one in many cases. Simply subtracting the sum of the commissions - you could easily track them per account, e.g. using Expenses:US:ETrade:Commissions instead of Expenses:Financial:Commissions - from the capital gains provides a good approximation of the gains as you describe it, but as you point out, not a perfectly accurate one, especially if you hold positions across reporting periods (taxation years). It is appropriate to note that folding in the purchase commission on the cost basis is but one method to automatically pro-rate that commission into the gain - we could track it separately, per-lot - but it is one that is elegant and leads to an unambiguous implementation. I would like to be able to support it.I don't have a good solution for doing this at the moment, but I want to think of one.In particular, we should design a method that leads to easy entry by a user, with a correspondingly nice syntax.I'll be thinking about this; any ideas welcome.
Some more thinking about this: one possible method would be to allow the user to indicate that a particular leg of the transaction is meant to be folded into the cost of another leg's, something I would implement like the following. First let's make up an example of a transaction the way they're currently done, with the full capital gain, that is, one that unfairly (to you) includes commissions: 2014-06-13 * "Transactions with Commissions" Assets:US:Invest:Cash -5009.95 USD ; 5009.95 USD Expenses:US:Invest:Commissions 9.95 USD ; 9.95 USD Assets:US:Invest:GOOG 10.00 GOOG {500.00 USD} ; 5000.00 USD 2014-06-20 * "Transactions with Commissions" Assets:US:Invest:GOOG -10.00 GOOG {500.00 USD} ; -5000.00 USD Expenses:US:Invest:Commissions 9.95 USD ; 9.95 USD Assets:US:Invest:Cash 5090.05 USD ; 5090.05 USD Income:US:Invest:PnL -100.00 USD ; -100.00 USD This is what we need to fix, we want the gain to become 100 USD - 2 x 9.95 USD. So now let's introduce a flag into the cost syntax (there's already a flag available on each posting): 2014-06-13 * "Transactions with Commissions" Assets:US:Invest:Cash -5009.95 USD ; 5009.95 USD + Expenses:US:Invest:Commissions 9.95 USD ; 0.00 USD (+) Assets:US:Invest:GOOG 10.00 GOOG {500.00 USD +} ; 5009.95 USD = 10.00 GOOG {500.995 USD} 2014-06-20 * "Transactions with Commissions" Assets:US:Invest:GOOG -10.00 GOOG {2014-06-13 -} ; -5009.95 USD = -10.00 GOOG {500.995 USD} - Expenses:US:Invest:Commissions 9.95 USD ; 0.00 USD (-) Assets:US:Invest:Cash 5090.05 USD ; 5090.05 USD Income:US:Invest:PnL -80.10 USD ; -80.10 USD When a flag is encountered in the cost, this says, add to the total cost the amount from postings marked with that flag. In the case of the buy, this means (500.00 x 10 + 9.95) is the new total cost and the cost per unit is now 500.995 USD. This works to give you a capital gain as you desired. However, here are some drawbacks: - You cannot use the cost basis of the lot to identify it anymore (the lot is now at a different cost basis, 500.995 USD instead of 500.00 USD, and that amounts shows up nowhere, we cannot realistically expect the user to know it). That may not be a bad thing though, I never liked identifying lots by their cost in the first place, I prefer a method that uses a label or the date to disambiguate. When reducing a position, the purpose of that cost really is just to identify which lot we should be using to reduce the position. I already have a proposal to make this better, by using labels or dates instead of cost (see sale transaction). - A bigger problem, however, and one that is preventing me from fully going ahead with this idea just yet, is that the expenses are gone. The expenses leg just cannot post to the commissions account, because its amount has been incorporated into the cost of the position. Allowing the cost to show up in both places would break the accounting equation; this transaction must balance. Maybe we should add an Income leg to absord the Expenses amount and post it anyhow? 2014-06-13 * "Transactions with Commissions" Assets:US:Invest:Cash -5009.95 USD ; 5009.95 USD + Expenses:US:Invest:Commissions 9.95 USD ; 0.00 USD (+) + Income:US:Invest:Commissions-Rebate Assets:US:Invest:GOOG 10.00 GOOG {500.00 USD +} ; 5009.95 USD = 10.00 GOOG {500.995 USD} I'm not quite sure how to solve this yet. Ideas welcome,
* Jostein Berntsen <jbe...@broadpark.no> [2014-06-20 04:26]:
> > ; Selling 2 ShareB at 2014/04/01
> > 2014-04-01 Selling 2 ShareB
> > Assets:Investments:Stocks:ShareB -2 ShareB @ 100€
> > Assets:SoldStocks:SoldB 2 ShareB @ 120€
> > Income:Investment Gains
> >
> Martin: Does this seem right for you?I'm not sure what Assets:SoldStocks:SoldB is for. If you're selling
two stocks for cash, you get cash; but in your example, you still have
those 2 stocks as an asset:
ledger -f qq bal Assets:SoldStocks:SoldB
2 ShareB Assets:SoldStocks:SoldB
What you want is this:
; Initial openings at 2014/01/01
2014-01-01 Opening BalanceAssets:Investments:Stocks:ShareB -2 ShareB {100€} @ 120€
Assets:Bank:Check Account 5000,00 €
Equity:Opening Balance
; Details of shares at 2014/01/01
;P 2014-01-01 00:00:00 ShareA 20€
;P 2014-01-01 00:00:00 ShareB 100€
2014-01-01 Details for shares
Equity:Opening Balance:Initial Investments
Assets:Investments:Stocks:ShareA 15 ShareA @ 20€
Assets:Investments:Stocks:ShareB 5 ShareB @ 100€
; Selling 2 ShareB at 2014/04/01
2014-04-01 Selling 2 ShareB
Assets:Cash 240€
Income:Investment Gains -40€
Assets:Investments:Stocks:ShareA -4 ShareA {20€} @ 30€
; Selling 2 ShareB at 2014/04/01
2014-04-02 Selling 4 ShareA
Assets:Cash 120€
Income:Investment Gains -40€
* Martin Blais <bl...@furius.ca> [2014-06-20 23:16]:
> > ; Selling 2 ShareB at 2014/04/01They are not ignored - they are used to calculate the gain/loss.
> > 2014-04-02 Selling 4 ShareA
> > Assets:Investments:Stocks:ShareA -4 ShareA {20€} @ 30€
> > Assets:Cash 120€
> > Income:Investment Gains -40€
>
> What I think has been confusing some people is that the 120E and 30E values
> above are [correctly] ignored (with your patch).
>
> They are going to be ignored, other than for adding an entry to the price
> DB, right?
> If not, how are they going to be used?
In other woods, this would not balance:
Assets:Investments:Stocks:ShareA -4 ShareA {20€} @ 30€
Assets:Cash 120€
Because you have 4 * 30, but also the 4*(30-20) gain, so you need:
Assets:Investments:Stocks:ShareA -4 ShareA {20€} @ 30€
Assets:Cash 120€
Income:Investment Gains -40€
I actually ran into something that's not ideal the other day. Since
ledger just caculates and doesn't understand what's going on, you
could happily do:
Assets:Cash 80€
Assets:Investments:Stocks:ShareA -4 ShareA {20€} @ 30€
This still balances, but doesn't represent the nature of the
transaction correctly -- it's exactly what you'd get without the
capital gain.
I'm not sure what to do about this... one solution is just to hope
people will get it right. Another would be new syntax to let people
give the name of an account the capital loss/gain should be booked to,
e.g.:
Assets:Investments:Stocks:ShareA -4 ShareA {20€} @ 30€ => Income:Capital gain
Assets:Cash 120€
Then Assets:Cash is 120 and Income:Capital gain is -40
Assets:Investments:Stocks:ShareA -4 ShareA {20€} @ 30€ => Income:Capital gain
Assets:Cash 110.05€
Expenses:Commissions 9.95€
Assets:Investments:Stocks:ShareA -4 ShareA {20€}
Income:Capital gain -4 @ 10€
Assets:Cash 110.05€
Expenses:Commissions 9.95€
How do you handle this in beancount?
Assets:Investments:Stocks:ShareA -4 ShareA {20€}
Income:Capital gain
Assets:Cash 110.05€
Expenses:Commissions 9.95€
Assets:Investments:Stocks:ShareA -4 ShareA {20€} @ 30€ +
Income:Capital gain +
Assets:Cash 110.05€
Expenses:Commissions 9.95€
2014-03-01 Details for shares Assets:Investments:Stocks 2 GOOG @ 500 USD Assets:Investments:Cash -1000 USD ; This does not generate an error... it should. 2014-03-02 Details for shares Assets:Investments:Stocks -2 GOOG {505 USD} @ 510 USD Assets:Investments:Cash This demonstrates that Ledger is not strict about which lots you can reduce... there are no "GOOG @ 505 USD" lots here, yet it allows us to do this. Moreover, it created 20 USD out of thin air... the sum of all accounts does not balance. This is one of many things I don't understand about it: I cannot conceive correctly entering my data without (1) strict inventory booking against existing lots, that is, you cannot reduce a position against a lot that does not exist, as in the above, and (2) the sum total of all transactions _must_ balance to 0 in all units. Beancount enforces both, always. Even when making transformations, such as filtering the entries to show a balance sheet and income statement and moving amounts from income accounts to equity's net income, I check that the sum is zero.
$ ledger -f badstock.lgr bal 10 USD Assets:Investments:Cash 10 USD Equity:Capital Gains -------------------- 20 USD Here is the detail: $ ledger -f test.lgr bal --lots 2 GOOG {500 USD} [2014/03/01] -2 GOOG {505 USD} 10 USD Assets:Investments 10 USD Cash 2 GOOG {500 USD} [2014/03/01] -2 GOOG {505 USD} Stocks 10 USD Equity:Capital Gains -------------------- 2 GOOG {500 USD} [2014/03/01] -2 GOOG {505 USD} 20 USD
2014-03-01 Details for shares Assets:Investments:Stocks 2 GOOG @ 500 USD Assets:Investments:Cash -1000 USD 2014-03-02 Details for shares Assets:Investments:Stocks -2 GOOG {500 USD} @ 510 USD Assets:Investments:Cash $ ledger -f test.lgr bal --lots 2 GOOG {500 USD} [2014/03/01] -2 GOOG {500 USD} Assets:Investments:Stocks 20 USD Equity:Capital Gains -------------------- 2 GOOG {500 USD} [2014/03/01] -2 GOOG {500 USD} 20 USD
So now we have both 2 GOOG @ 500 USD and -2 GOOG @ 500 USD?
Is this a bug? The only way I could make it balance is by specifying the date along.
both places would break the accounting equation; this transaction must balance."
So I've been thinking about this and I think that is the fundamental problem. Technically, commission (at least in the U.S.) isn't an expense, it's an asset. It sounds strange, but think about it. In the U.S., the commission counts toward the cost basis and the cost basis is recorded with the asset. It's the whole depreciate vs. expense issue in accounting.
I'm not sure how, but I think the solution is somewhere down that road. Maybe creating a fake asset that is the commission per share, maybe a sub-asset.
The thing is, this isn't a new problem. This isn't a ledger problem so much as an accounting problem. Accountants (in the U.S. at least) already have to deal with this situation. Does anyone know how accountants deal with this currently?
Rick
"Allowing the cost to show up inboth places would break the accounting equation; this transaction must balance."So I've been thinking about this and I think that is the fundamental problem. Technically, commission (at least in the U.S.) isn't an expense, it's an asset. It sounds strange, but think about it. In the U.S., the commission counts toward the cost basis and the cost basis is recorded with the asset. It's the whole depreciate vs. expense issue in accounting.
I'm not sure how, but I think the solution is somewhere down that road. Maybe creating a fake asset that is the commission per share, maybe a sub-asset.
The thing is, this isn't a new problem. This isn't a ledger problem so much as an accounting problem. Accountants (in the U.S. at least) already have to deal with this situation. Does anyone know how accountants deal with this currently?
On Wed, Jun 25, 2014 at 1:08 AM, Rick F <ri...@farnbach.com> wrote:"Allowing the cost to show up inboth places would break the accounting equation; this transaction must balance."So I've been thinking about this and I think that is the fundamental problem. Technically, commission (at least in the U.S.) isn't an expense, it's an asset. It sounds strange, but think about it. In the U.S., the commission counts toward the cost basis and the cost basis is recorded with the asset. It's the whole depreciate vs. expense issue in accounting.Commission is definitely not an asset.I think I see what you mean though, and I think what you mean is this (please correct me if I'm wrong):2014-06-25 * "Buying into a position"Assets:Investments:Cash -1009.95 USDAssets:Investments:Stock 10 STOCK {100 USD}Expenses:Commissions 9.95 USD2014-06-25 * "Cost basis adjustment for commission"Assets:Investments:Stock -10 STOCK {100 USD}Assets:Investments:Stock 10 STOCK {100.995 USD}Income:Investments:Rebates -9.95 USDNow, the way that I carried out the cost basis adjustment above looks a bit inconvenient: remove all shares and replace them by new ones at the adjusted cost. This is because it is just what is supported in Beancount/Ledger right now. In the example above, I use a "rebate" account to absorb the cost adjustment: you would _not_ declare this as taxable income, it's just there for balancing the transaction.2014-08-04 * "Selling haf of my position"Assets:Investments:Stock -5 STOCK {100.995 USD}Assets:Investments:Cash 540.05 USDExpenses:Commissions 9.95 USDIncome:Investments:Gains -35.075 USDOn the sale you don't have to make an adjustment, because the shares have been converted to cash.
2014-01-01 open Assets:Investments:Cash 2014-01-01 open Assets:Investments:Stock 2014-01-01 open Expenses:Commissions 2014-01-01 open Income:Investments:Rebates 2014-01-01 open Income:Investments:Gains 2014-06-25 * "Buying into a position" Assets:Investments:Cash -1009.95 USD Assets:Investments:Stock 10 STOCK {100 USD} Expenses:Commissions 9.95 USD 2014-06-25 * "Cost basis adjustment for commission" Assets:Investments:Stock -10 STOCK {100 USD} Assets:Investments:Stock 10 STOCK {100.995 USD} Income:Investments:Rebates -9.95 USD 2014-08-04 * "Selling half of my position" Assets:Investments:Stock -5 STOCK {100.995 USD} Assets:Investments:Cash 540.05 USD Expenses:Commissions 9.95 USD Income:Investments:Gains 2014-08-04 * "Cost basis adjustment for commission" Income:Investments:Rebates -9.95 USD Income:Investments:Gains
Resulting trial balance from Beancount:
|-- Assets | `-- Investments | |-- Cash -469.90 USD | `-- Stock 504.98 USD |-- Expenses | `-- Commissions 19.90 USD `-- Income `-- Investments |-- Gains -35.08 USD `-- Rebates -19.90 USD
2014-06-25 * "Cost basis adjustment for commission" Assets:Investments:Stock 10 STOCK {100 USD -> 100.995 USD} Income:Investments:Rebates -9.95 USD
2014-06-25 * "Cost basis adjustment for commission"
Assets:Investments:Stock -10 STOCK {100 USD} ; disambiguate
Assets:Investments:Stock 10 STOCK {} ; let system auto-fill
Income:Investments:Rebates -9.95 USD
Stock Cost = (Shares Purchased × Price Per Share) + Commissions + Other Transaction Fees
Notice that the commission is capitalized, not expensed. That's clearly where we have been going wrong.
Rick
Great find. Breaks all financial transactions into a series of templates to be followed. I'll definitely use that book as a reference going forward.In regards to the current conversation, here's the relevant quote.Stock Cost = (Shares Purchased × Price Per Share) + Commissions + Other Transaction Fees
Notice that the commission is capitalized, not expensed. That's clearly where we have been going wrong.
On 24.06.14,22:08, Rick F wrote:Would this then be the best way to calculate it?
> "Allowing the cost to show up in
>
> both places would break the accounting equation; this transaction must balance."
>
>
> So I've been thinking about this and I think that is the fundamental problem. Technically, commission (at least in the U.S.) isn't an expense, it's an asset. It sounds strange, but think about it. In the U.S., the commission counts toward the cost basis and the cost basis is recorded with the asset. It's the whole depreciate vs. expense issue in accounting.
>
>
> I'm not sure how, but I think the solution is somewhere down that road. Maybe creating a fake asset that is the commission per share, maybe a sub-asset.
>
>
> The thing is, this isn't a new problem. This isn't a ledger problem so much as an accounting problem. Accountants (in the U.S. at least) already have to deal with this situation. Does anyone know how accountants deal with this currently?
>
>
> Rick
>
>
> On Saturday, June 14, 2014 10:50:32 AM UTC-7, Martin Blais wrote:
> >
; Initial openings at 2014/01/012014-01-01 Opening Balance
Assets:Bank:Check Account 5000,00 €
Equity:Opening Balance
; Details of shares at 2014/01/01
;P 2014-01-01 00:00:00 ShareA 20 €Assets:Investments:Stocks:ShareA 15 ShareA @ 20 €
;P 2014-01-01 00:00:00 ShareB 100 €
2014-01-01 Details for shares
Equity:Opening Balance:Initial Investments
Assets:Investments:Stocks:ShareB 5 ShareB @ 100 €
; Details of shares at 2014/04/01P 2014-04-01 00:00:00 ShareA 30 €
P 2014-04-01 00:00:00 ShareB 120 €
; Selling 2 ShareB at 2014/04/012014-04-01 Selling 2 ShareB
Assets:Investments:Stocks:ShareB -2 ShareB @ 100 €Assets:Commission -9,90 €
Assets:Cash 2 ShareB @ 120 €
Income:Investment Gains
Assets:Investments:Stocks:ShareB -2 ShareB {100 €}
Expenses:Commission 9,90 €
Assets:Cash 230.10 €
Income:Investment Gains -40 €
; Details of shares at 2014/05/02
P 2014-05-01 00:00:00 ShareA 70 €
P 2014-05-01 00:00:00 ShareB 120 €
Selling 2 ShareA at 2014/05/01
2014-04-02 Selling 4 ShareAAssets:Commission -9,90 €
Assets:Investments:Stocks:ShareA -4 ShareA @ 20 €
Assets:Cash 2 ShareA @ 120 €
Income:Investment Gains
2014-05-01 Selling 4 ShareAExpenses:Commission 9,90 €
Assets:Investments:Stocks:ShareA -4 ShareA {20 €}
Assets:Cash 270.10 €
Income:Investment Gains