Although I learned a lot from my first two attempts at economy simulator, they failed as projects.
In the first iteration, the world had no dimensions, no concept of place, no distances. It simplified things a lot but it was hard to visualize anything.
A world had resources like forest, hunting ground or berry field which could be extracted wood, food or animal skin. Each human had daily need for food, wood, cloth and he had to have this in inventory to be able to live. There were predefined processes like hunting, woodcutting, spear making which required different resources and items to produce some other item. Each human could take one action per day. He could gather resources, craft something, rest or reproduce. So once the basic needs were covered he could rest to increase happiness, reproduce to increase the number of people or craft something. Crafted tools would increase productivity of any process and using a process would increase the skill of using that process.
But the simulation immediately hit the Malthusian trap, everybody competed to survive on the most basic level. The only viable tactic was to use the resources as much as you can. If you try to invest in skills or tools, you'll most likely die of hunger.
If all critical resources are shared but scarce, there is no economy, just basic survival. What I needed was some kind of private property over the resources but current engine was not able to do it so I wanted to base it on better foundation.
The second attempt abstracted too much and economy was falling. I want describe the internals but I got one important insight. Basic of the economy is sustenance without trade. You need to be able to produce your own food and then decide if you want to trade or not. If you are forced to trade to survive, the prices fluctuate too much.
I still didn't figure how to do money.
I'm just wondering if my static publisher is still working. I just noticed that I eat my own dog food (that's Spolsky's term - google it, I don't know how to add links now). In the last few years I wrote some applications that I use often, some of them daily, and they just work.
Hm, the problem is that I don't know my markup syntax anymore. Well, let's do the plain-text only now.
Static publisher - I'm using it to post articles on the blog and they are formated exactly as I want them. I didn't use it fore some time but if you are reading this online then it works.
Car sharing monitor - I have a web app that crawls facebook car sharing groups to find me a ride when I need one. Without that app, I would have to monitor facebook groups and manually search for rides on my route. If I am too slow, on busy days rides get full in minutes. This app monitors groups for me and alerts me if it finds the ride on my route. I'm usualy able to reserve my ride before anybody else.
Stock monitoring app - Not the live monitoring, I don't need that. I'm trying to be a value investor. This app downloads financial information about companies, their fundamentals and price. I wrote a formula that scores the stock depending on its value and selects what should my portfolio look like and compares to the current state. Of course, the hard part was to learn everything about investing. This app is my knowledge base. It's also fun to apply math to finances.
N3R (Not Really an Rss Reader) - my most used app ever. When Google pulled the plug on their RSS reader (Google reader?) I was in trouble. For years I currated my list of blogs that are worth reading. It shouldn't be a problem to switch to another Rss reader, right? But it is, because what I expect from Rss and what they all provide is so different. I just need a notification that there is a new article, and when i click on it it should open the article in a new window, in full context of the website and mark the item as read. And now I have the app for that.
- read Writemonkey files
- create static html file for every article
- create static html file for all articles combined
- recognized markup: H, UL, LI
- one click publish to local folder or ftp
- local index of file - upload only changes
- delete surplus files on destination and ftp
- categories, tags, types
- service that publishes in background
- probably should use third party markup to html converter
- mark some texts as tweets or facebook posts and automatically post or tweet them to my timeline
- create rss
To implement money in the simulator, first I need to know what money is. Last time I wrote why it was invented and why it is necessery. But how does it work and how it did emerged?
You can google it yourself and find many plausible theories, I'll just sumarize the parts I think are important.
First, imagine the world without money where you trade by bartering; it's possible but problematic. A farmer can trade some apples with a toolmaker for a new tool. But he can't trade apples for strawberies because when strawberries are ripe, apples are not yet fully grown. What he can do is to promise he'll give some apples in a few month for strawberies he will get now. So, the root of money is a promise, you can call it debt. If two farmers trust eachother, they can make such trade.
In a small community, it is quite possible to trade without money, only on promises. But how many promises can I give to someone? Can a farmer promise he'll give tons of apples? He can, but only if he has a large apple orchard. He actually have a credit rating to his promises. The more productive he is now, the more promises he can make. So you don't need money to have debt, credit and credit rating. That seems to be inherent to the trade system.
Society is pretty limited with only resource gathering and consumption. Everybody is just scavenging for the basic resources and spending them or resting if they have enough.
To reach a more complex society, we need two main ingredients:
- specialization: instead of everybody doing everything, people can specialize and become experts in they field thus producing more
- trade: if expert in one field can exchange products with expert in another field they both have more of both than if they didn't specialize
First version of trade is barter where products are exchanged directly: one unit of food for one unit of stone, one axe for three units of wood. Problem with such arrangement is that both buyer and seller have to want each other's product or trade is not possible. As a seller, you need to find not only someone who wants your product but he have to have something you want (Coincidence of wants).
That's way money was invented: it is necessary. In money trade, as a seller you just need to find somebody who needs your product and has the money. Then you can use it later to buy what you need from person completely unrelated to the first trade. Naturally, I tried to implement it too. But to implement the money naturally, without some unknown force printing money and putting it into the economy (like state is doing now), definitely it's not an easy task.
Quick summary of the project structure so far:
- there is a world that contains a list of resources and a list of human agents
- resources are renewable sources of products (forest gives wood, quarry gives stone...) with defined capacity and regeneration speed
- processes are activities that require input and produce outputs, input being a resource or product and output being another product (stone cutting require query and produce stone, axe making require wood and stone and produce stone axe...)
- humans are agents that can decide to run a process once per tick (world is ticking)
- humans have basic needs that must be satisfied regularly to keep living: they have to spend food to eat, wood to warm up and cloth to dress
- humans can reproduce when they decide to
- executing a process takes time, this is simulated with cooldown time during which human cannot do any action
- when human decide to do nothing, it's considered rest and counts as increase in quality of life
- whem human executes a process, it gains skill in this process, meaning it takes less time to do it (shorter cooldown time)
With this framework in place, I can create various implementations of human and test how they fare in the world. They differ in how they make decisions, do they just consume everything they find or do thy plan in long term, how they behave in abundance of resources and what they do when resources are scarce.
In previous articles I defined and explained the Malthusian trap. But somehow we avoided it and the conditions are improving for humanity. What happened?
Let's try the island example from previous example. When people discovered agriculture, island could support 3000 people. Current 1000 inhabitants had to work harder but they lived comfortably and multiplied. When they reached population of 3000, conditions again dropped to bare survival, they still had to work hard and destroy the environment. How could they avoid that?
First and obvious option is to stop multiplying. But without harsh imposed limits on personal freedom that wouldn't be possible. But if in period of time when population was between 1000 and 3000 when island could support its population, somebody invented even better technology that could support even more population, they could avoid Malthusian trap. When population reach 3000, new population limit is 4000. When 4000 is reached, new limit is 5000. And so on.
Exactly that happened in Europe. From neolithic revolution to first industrial revolution (6000 - 10000 years), average living conditions didn't improve significantly. Break from Malthusian trap started with industrial revolution around 1800. Technology improved significantly and average income and wealth increased. As always, population increased; but before living conditions dropped, technology improved again. And then again, thus allowing us to keep or improve standard of living although the world population grew six time.
It seams we are now dependent on technology. Not only on current state of it, but we are dependent on growth. Without constant technological development we would return to bare survival. The question is, how much further can technology grow?
In short, Malthusian trap is an explanation for a problem happening to humanity where we tend to live constantly on the brink of starvation. Whenever we find the way to produce more food (or wealth) from natural resources, we tend to multiply until again everybody lives in misery.
Let's try to explain it with hypothetical example. Imagine an uninhabited island that can support 1000 people, hunter gatherer style. Now, 100 primitive people arrive on the island. What happens? They live in harmony with nature, they gather fruits from bushes and trees, they hunt for meat. They enjoy their lives, they are healthy, nurtured and happy. They live in egalitarian communities. And they multiply...
Soon, island have 1200 inhabitants and problems arise. There isn't enough food for everybody. People are malnourished, sometimes desperate and they start to fight. Population stagnates as more children do not survive to adulthood. Even worse, as climate fluctuates sometimes island can support even more people and population grows. But then, when climate changes, mass starvations occur regularly.
Some smart people try and succeed in growing plants, inventing the agriculture. Invention spreads, it is simple and everybody adopts it. It is much more efficient than just gathering what nature provides and now the island can support 3000 people. They don't live in harmony with nature anymore as they cut the threes whenever they need more land. They are working more and harder but they are again properly nourished as there is enough food for everyone. Technology made their lives better (or at least less miserable). And they multiply...
Funny things happen when you want to write code but first have to grasp the problem domain. And thoroughly so that you gotta learn something in the way. Supply, demand, elasticity... Simple stuff. I learn that in school. But programming the economy raises some new questions, like:
- When does economy begin?
- How does world without economy looks like?
- Why can't we all be rich and prosperous?
Answers on first two questions are simple. Economy begins when resources are scarce. That's why you have economy for food but not for air. Air is still abundant, but food is not. Once air runs out in some way, there will be economy around it. Same happened with water. Selling water was unheard of two generation ago but it became completely normal to this generation.
Early hunter-gatherer society did not have food economy, anybody who was hungry could just pick or hunt something, there was enough of it. So, the questions is:
- if there was enough for everybody and everybody was happy, why it didn't stay like that?
Well, humanity is in the trap: Malthusian trap.
Writing an economy simulator is a kind of a project I always wanted to create but somehow I never did. Not that I do not try, I just never persist long enough for it to became more than quick attempt. I think I have two problems:
- I can't define the scope
- I don't understand the mechanisms
This are the problems on which I have to have some answers before I get to coding. They look simple only if you're ignorant enough. I strive not to be, so it seems I'm into serious research project if I want any results.
I strive for years to write regularly on topics I'm interested in, but it seems I just can't do it. On one side, I'm perfectionist but on the other I'm not skilled yet in writing and also not quite fluent in English. That means I'm in constant deadlock where my every article is not quite good enough to publish it. Without publishing, there is no point in writing as you don't get any returns and without writing, my writing skills stagnate. So, either I won't write or I have to lower my criteria. This is the result: I'm writing my first article and publishing it as it is.
After settling down over my perfectionism obstacle, I need to simplify my workflow. I want to be able to fire up Writemonkey, spew my thoughts in it and be done with it. Current workflow that is based on copying text to Wordpress is too distracting. I want my workflow with my rules - and that's why I'm writing static site generator/publisher. With it I'll just write, and it will handle everything else. And as a bonus, I have first topic and few things to say about it.
And blog format just doesn't feel right. Sometimes I just want to create a short mind dump, like tweet or just a little longer, maybe I'll merge articles later. Sometimes I'll incoherently rumble about topic I don't fully understand. Other times I want to write a well structured research article. All those just aren't on the same level and publishing platform should respect this.
After a day of coding and fiddling with css, ftp and html (those didn't feel like coding), I finally made basic functional publisher.
It goes like this:
- Fire up Writemonkey, write something and save it to source directory as text
- Run publisher
Simple enough. It creates one html file for every txt file and one common that serves as an index page. There is a lot of work left but I can add features incrementally while I'm using the software from the first day.