differential analysis and Python math

33 views
Skip to first unread message

Randy

unread,
Dec 9, 2019, 10:37:51 AM12/9/19
to Ledger

Hi, group,


I’m trying to find a way to use Ledger to do differential analysis.


More specifically, I’m trying to use math to calculate an automated transaction's posting's factor from the value of another account. Below is an example.


Given this transaction which represents the total fixed costs for the year:


2019-12-09 transaction
    Expenses:Fixed costs  $120,000
    Owner's Equity

I want to allocate the fixed costs to each product category, with some pseudo automated transaction that looks like this:


= /^Expenses:Fixed costs$/
    $account:Product A     ((amount(account Income:Sales:Product A) / amount(Income:Sales)) * amount(Expenses:Fixed costs))
    $account:Product B     ((amount(account Income:Sales:Product B) / amount(Income:Sales)) * amount(Expenses:Fixed costs))
    $account:Product C     ((amount(account Income:Sales:Product C) / amount(Income:Sales)) * amount(Expenses:Fixed costs))
    $account               -1.0

This is clearly a bit much to stick in an automated transaction, but I understand that Ledger can be extended with Python. Would that be a good way to do the math above? I know a bit about coding, but I don’t know where I would start to tackle this challenge. Does anyone know where I might start with this?


Thanks for any help you can give!

dim

unread,
Dec 9, 2019, 1:42:54 PM12/9/19
to Ledger
You could try Python numpy or scipy. https://scipy.org/scipylib/faq.html#what-is-scipy

Dustin Alandzes

unread,
Dec 9, 2019, 3:21:24 PM12/9/19
to Ledger
Check out the python library, although the documentation is lacking:
https://github.com/ledger/ledger/wiki/Ledger-Python-Bindings
https://github.com/ledger/ledger/blob/master/python/demo.py

Seems like the first step would be to load your data into lists/dictionaries.

Randy

unread,
Dec 9, 2019, 9:24:47 PM12/9/19
to Ledger
Thanks for the links, I'll go through them and see if I can't put something together.

Randy

unread,
Dec 9, 2019, 9:25:31 PM12/9/19
to Ledger
Hi dim,

thanks for the recommendation, I'll take a look.
Reply all
Reply to author
Forward
0 new messages