On Thursday, January 4, 2018 at 2:16:16 PM UTC+7, Martin Blais wrote: 
>
> But I'm not sure that bean-query is flexible enough to let me do what I 
>> want here and only look at lots that still exist and are under water. So 
>> I'm back to being stumped about how to proceed. Do I just need to drop into 
>> python to get what I want?
>>
>
> I don't think you do, use select sum(position) and you should be on your 
> way, if you want to drop to Python accumulate the Position instances to an 
> Inventory and print those contents
>

For the record, I gave up trying to do it in bean-query since my brain 
apparently wasn't able to wrap around what I needed to. Doing this in 
python was straightforward:


import beancount.loader 
import beancount.core 
from beancount.reports import holdings_reports 

import argparse 
parser = argparse.ArgumentParser(description='List lots that have negative 
value and are available for tax loss harvesting.') 
parser.add_argument('bean') 
parser.add_argument('-i', '--ignore-account', action='append') 
args = parser.parse_args() 

TEMPLATE = '{currency}\t{number:,}\t{total_loss:,}\t\t({account})' 

entries, errors, options = beancount.loader.load_file(args.bean) 
holdings, price_map = holdings_reports.get_assets_holdings(entries, 
options) 
print('\tunits\tloss\t\t\taccount') 
print('--------------------------------------------------') 

for h in holdings: 
    if h.account in args.ignore_account: continue 
    if h.market_value < h.book_value:
        print(TEMPLATE.format(total_loss = (h.market_value - h.book_value), 
**h._asdict())) 

-- 
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/46aed62b-7571-475e-b666-ac6f75d4417d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to