reddit / emacs
Can i use org-mode tables for accounting trading transactions?
velvergft · 2022-08-20 07:28
Hi
Can i use org-mode tables (or something like that for Emacs) for accounting trading transactions? (now i'm using Joplin with Markdown)
https://preview.redd.it/cppm0oeamti91.png?width=400&format=png&auto=webp&s=38970aeb6ae54c11871e7ce3f54e50638a3bf2c8
Like on screenshot:
\- Save time
\- Summarize daily earnings
e.t.c
​
And most important:
1) I want it to automatically calculate profit / losses. I known that Emacs can do some arithmetic operations with tables, using patterns like that:
​
\#+TBLFM: $3=($2 - u/-1$2)/7::$5=$Weeks\*$Rent; %.2f
​
2) And i want automatically create tables or just string that show me, how much i win and lose, summarizing week and month (profit / lose).
Example:
Week: -10$
Month: +100$
​
I'm just wondering, it is generally possible or not. I really like Emacs ecosystem and its flexibility. Markdown is very limited in comparison with Org-Mode, plus Joplin is pretty bloated software...
​
P.S. Sorry for my English, I hope, you understood me. Thanks! :-)
__Atla5_82__ · 2022-08-20 08:06
I would suggest creating a capture template to create those entries, with a table as the content. The table with each of the columns and maybe one row created, then already have the table arithmetic setup and maybe a file hook to trigger `org-table-recalculate-buffer-tables`.
I'm not too sure how the summarizing could be setup, other than creating custom functions.
This isn't technically Emacs specific, but you could look into [Plain Text Accounting](https://plaintextaccounting.org/). I use [ledger](https://www.ledger-cli.org/) combined with [ledger-mode](https://github.com/ledger/ledger-mode) on Emacs, however there is a more up-to-date one called [hledger](https://hledger.org/), with [hledger-mode](https://github.com/narendraj9/hledger-mode). You can have these setup in an org file and export into a plain text file if you would like, but personally I recommend just using one of those modes and editing a ledger file directly.
velvergft · 2022-08-20 08:07
Thank you!
periodscratchcomma · 2022-08-20 16:11
Have you tried ledger and ledger-mode?
NoisyFrequency · 2022-08-20 16:33
I'd be careful using programming oriented tools to represent currencies, [because floats are not exact enough for this](https://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency). It might be that `org-mode` takes care of this but in doubt, I'd still check.
WallyMetropolis · 2022-08-20 17:35
A capture template for this is a great idea.
Leger and ledger-mode were going to be my recommendation.
WallyMetropolis · 2022-08-20 17:37
Great advice. Track currency in pennies, not dollars!
Imaltont · 2022-08-20 20:57
Ledger mode is an option. Another non-emacs one but still GNU/Free Software would be GNU Cash, which is made around things like this, and has reports written in Scheme.
It all just depends on your needs, if you don't need much you could very likely create a nice workflow around it in emacs just as is with some templates/automation with org-mode, otherwise I would get a tool made for it, like ledger, GNU Cash or commercial ones if those doesn't fit your needs either. Relational databases and similar I also find really handy for these kinds of data compared to just storing in org-mode tables/excel/calc, as I find it much more convenient to search for at get what you want back from it with various queries. GNU Recutils is an alternative if you still want the database in plain text.
zelphirkaltstahl · 2022-08-20 21:17
Formulas for org-mode tables can make use of GNU Calc. GNU Calc apparently has means to increase precision: <https://www.gnu.org/software/emacs/manual/html_node/calc/Precision.html>. However, I don't know how to access or use that from inside a formula.
dpoggio · 2022-08-20 23:38
This is indeed the way unless the language provides fixed point data types and arithmetic. The issue may be dealing with really big numbers. Also, consider this in Elisp: `(/ 1 3)` gives 0. This happens also in fixed point arithmetic as results are usually truncated to fit the type, but may give you weird results when used to compute taxes and so. So, be careful, there are no magic solutions.
yantar92 · 2022-08-21 00:19
By default, Org tables are using calc.el - an algebra system for Emacs. It provides arbitrary precision floats and integers. You do not need to care about huge numbers of precision cutoffs. Emacs' Calc is not limited by system float/integer types. Check out `[[info:calc#What is Calc]]`
yantar92 · 2022-08-21 00:20
Not GNU calc, M-x calc. M-x calc is totally different beast. It is closer to Maxima.
zelphirkaltstahl · 2022-08-21 16:05
Can you point to any information, which says that there is something else than "GNU Emacs Calc" being used inside Emacs in org-mode?
I am thinking it is exactly, what I linked to. I also have used functions from that documentation I linked to in the past, inside org-mode table formulas.
EDIT: There is even this reference card, which calls it "GNU Calc" on the official Emacs documentation website: https://www.gnu.org/software/emacs/refcards/pdf/calccard.pdf.
What is "GNU calc" then, if not "GNU Emacs calc"?
yantar92 · 2022-08-21 22:27
I am sorry. You are indeed right. For some reason, I was thinking about GNU bc as about calc (https://www.gnu.org/software/bc/bc.html).
WallyMetropolis · 2022-08-22 13:39
Good points. It can also be helpful to use a rational-number type for the results of division.
dpoggio · 2022-08-22 13:55
I prefer integers. Fixed points are integers with extra steps. You may use one on the cents for accounts and transactions, and other on the 1/1000s if needed, to hold the intermediate results and cut the errors on currency conversion and taxation, until you have the final number. But you need to understand where truncation occurs and what the impact is. You WILL have errors at some point. In the end, you need a balance procedure to put your numbers in order and some analysis to get feedback on how your calculations are affecting the big picture.