Dealing with futures

103 views
Skip to first unread message

Dan Andersson

unread,
Dec 5, 2023, 5:10:03 PM12/5/23
to Beancount
Hi,

For stocks (and even options), you pay for a thing (or short sell a thing) and cash leaves (or comes into) your cash account. Very clear. The cash is price * quantity * multiplier.

Futures are different. No cash leaves/arrives in the beginning. Basically the value starts at zero. Only price differences over time matter and only when closing position does realized PnL bring cash in/out of cash account.

How to deal with this in Beancount? Should I set the Beancount price to zero at first (and e.g. for informational purposes put the actual market price into the comment)?

(I realize there is margin but that's just a virtual allocation of sorts (cash is still in the cash account), cannot really be determined from the price, plus it varies from time to time depending on volatility etc.)

Thanks,
Dan

Dan Andersson

unread,
Dec 8, 2023, 1:06:57 PM12/8/23
to Beancount
I think I can get a fully customizable experience by using "NONE" and zero cost basis. Please critique this:

;----------
2014-05-20 open Assets:Futures:GOLD-DEC-24 GOLD-DEC-24 "NONE"
2014-05-20 open Assets:Citibank:Cash USD
2014-05-20 open Income:CapitalGains USD
2014-05-20 open Expenses:CapitalLosses USD

2014-05-20 * "Buy GOLD-DEC-24 @1000.0"
  Assets:Futures:GOLD-DEC-24  2 GOLD-DEC-24  { 0 USD }

2014-05-21 * "Sell GOLD-DEC-24 @1010.0"
  Assets:Futures:GOLD-DEC-24  -1 GOLD-DEC-24  { 0 USD }
  Assets:Citibank:Cash 10 USD
  Income:CapitalGains -10 USD

2014-05-22 * "Sell GOLD-DEC-24 @990.0"
  Assets:Futures:GOLD-DEC-24  -1 GOLD-DEC-24  { 0 USD }
  Assets:Citibank:Cash -10 USD
  Expenses:CapitalLosses 10 USD
;----------

Advantage: Full control.

Drawbacks:
  1. The cost basis is just a dummy value (only to "enable a custom experience").
  2. I lose Beancount's automatic mismatch checks on futures quantity vs. cash.
  3. I also lose Beancount's automatic matching; have to do matching and PnL calculations myself.
  4. Beancount reporting doesn't automatically reflect unrealized gains.
Is this on the right track? (Point 4 is very unfortunate but I could alleviate that by e.g. annual (December 31) entry to record unrealized gains.)

Thanks,
Dan

Dan Andersson

unread,
Dec 8, 2023, 3:24:52 PM12/8/23
to Beancount
I just found another approach: https://groups.google.com/g/beancount/c/OIjyBo-Ehu0/m/b3ujN_oMAQAJ

If I understand correctly, he simply has a phantom account that offsets the initial notional value and track only PnL afterwards. This phantom account offers a nice hack to deal with futures. However, for some reason he calls this "margin" (not sure why, maybe this is special Ameritrade terminology).

Martin Blais

unread,
Dec 8, 2023, 4:21:21 PM12/8/23
to bean...@googlegroups.com
Sorry for the late reply, I've been busy.

Yeah, maybe I shouldn't have called it "margin," it's inaccurate.
In particular, this method doesn't actually track the margin usage (which seems unnecessary).
Maybe it should be some Equity account.

There's some other discussion about futures contracts here:

The other problem is inferring the multiplier. That's not done.
I'm thinking the instrument names maybe should have a multiplier in them, or we should have some global option to register a prefix-to-multiplier mapping.




--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/2aabf18c-ce90-4475-9b07-0c4023e0f657n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages