On Fri, Dec 1, 2017 at 1:25 PM, Zhuoyun Wei <[email protected]> wrote:
> Hi, > > I've been using Beancount to track trading activities. With > "beancount.plugins.unrealized" plugin enabled, I can see a few special > transactions inserted for unrealized PnL. The special transactions are > always inserted as the last transactions in the journal. > > I am wondering if there is a BQL or something to compute the unrealized > PnL day-by-day. Id est, if I close the position on Nov 25, the PnL is X > USD; if I close the position on Nov 26, the PnL is Y USD. > > I have tried: > > select date, account, position, balance from close on 2017-XX-XX clear > where account ~ 'Unrealized'; > > but it does not work as expected. Is that because the plugin runs before > the "CLOSE" syntax takes effect? > > Currently the only way I can think of, is to comment out / remove latest > "price" entries from price database to force Beancount to compute > unrealized PnL for a different date. > There's no way to do this right now, unless you resort to some Python (but it's doable with Python for sure, as long as you have frequent enough price directives, you have all the required data already). See the net-worth-over-time.py script, for example. I've written about this previously on the mailing-list (see archive), but I see two ways to report unrealized profit / market value: (1) Implement the feature in all reporting routines, recognizing its first-class need and accept the extra complexity, or (2) Automatically insert the unrealized gains as transactions and avoid the need to talk about it in reporting. What you have in this plugin is (2). The elegance is that reports don't know about unrealized profits. It turns out it's not that great (it was a bit of an exploration anyhow). I think the better way is for all the reporting routines to support valuation at market value and if needed, cost basis reporting as well. I don't think creating fake realization entries like this is viable long-term. Creating more frequent realizing entries also causes other problems. -- 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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/CAK21%2BhNYFhKc8162SQiaqpsv4H55Hr_ejyF_FYd0xg%2BaeAhXvw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
