News for hackers. Stuff that matters.
Re:Leo Editor by fspeech on Wednesday August 15, 2018 @11:22PM (#17771650)
I have been using it forever (over 10 years) to organize financial data and do taxes. While I should credit Python because these are Python programs after all, it is really Leo that enables me to easily keep data organized. Queries can be ran by easily running Python scripts inside of Leo with results directed to the log panel, turning Leo into a light-weight IDE.

For example the top node for accounting is like this:

  #@killcolor
  # accounting

  from datetime import date
  import pprint
  import math

  <<defs>>

  year = 2006

  <<2006>>

  inc_year()
  <<2007>>

  inc_year()
  <<2008>>

  ... more data

  inc_year()
  <<2018>>

  inc_year(0) #update certain yearly balance records without 
  advancing

  def runacct(argv):
      if len(argv) > 1:
        if argv[1] == 'q':
            transquery(argv[2].upper())
        elif argv[1] == 'g':
            groupquery(argv[2].upper())
        elif argv[1] == 'h':
            holdingquery(argv[2].upper())
        elif argv[1] == 'm':
            if len(argv) == 3:
                monthquery(int(argv[2]))
            else:
                monthquery(int(argv[2]), int(argv[3]))
        elif ... many other query options
      else:
        balancequery()

  if __name__ == '__main__':
      from sys import argv
      runacct(argv)
Re:Leo Editor by jtoledo on Thursday August 16, 2018 @07:38AM (#17773737)
Interesting! How do you keep transaction records?
Re:Leo Editor by fspeech on Thursday August 16, 2018 @01:27PM (#17776703)
I use two classes to track accounts and transactions:

  class acct(object):
    # bank and brokerage account
    allacct = []

    def __init__(self, name, balance, holdings=None):
        self.name = name
        self.balance = balance
        self.holdings = holdings
        self.xferamt = 0
        self.accum = 0 # used to track cumulation ad hoc values
        acct.allacct.append(self)

    def buy(self, sec, amt, cost, day):
        rec = trans(('buy', sec, amt), -cost, day, self)
        self.balance -= cost
        if not self.holdings.has_key(sec):
            self.holdings[sec] = [0]
        self.holdings[sec][0] += amt
        self.holdings[sec].append(rec)
  ......

  class trans(object):
    # transaction record object track cash invovled in each transaction

    allrec = []

    def __init__(self, t, amt, day, where):
        try:
            self.type = t
            self.amt = amt
            self.date = date(year, month, day)
            self.where = where

            trans.allrec.append(self)
        except Exception as err:
            print t, amt, year, month, day, where
            raise err            
Then for each data line I just do any of the following:

  SOMEACCT.buy(...)
  SOMEACCT.sell(...)
  SOMEACCT.credit(...)
  SOMEACCT.debit(...)
  SOMEACCT.xfer(...)
  # classified by tax categories:
  SOMEACCT.int(...)
  SOMEACCT.div(...)
  SOMEACCT.fdiv(...)
  SOMEACCT.mint(...)
  SOMEACCT.mdiv(...)
Then it is easy to query and do computations in any way one cares to write a function to do.
Re:Leo Editor by jtoledo on Thursday August 16, 2018 @03:00PM (#17777560)
Thanks! Today I use Excel to track my accounts, but I've been looking for alternatives... Now I'll evaluate your idea.
Re:Leo Editor by fspeech on Thursday August 16, 2018 @04:25PM (#17778159)
You are welcome. This approach has worked well for me with over 10 thousand transactions tracked so far. It is very flexible as you can write your own IIR computation or match capital gains etc.