-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathArtificialEconomy.nlogo
2475 lines (2164 loc) · 64.9 KB
/
ArtificialEconomy.nlogo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
extensions [profiler]
globals [farm-patches city-patches trade-patches]
patches-own [yield prod]
turtles-own [produce widget money age ptrade wtrade ptrade-t-1 ptrade-t-2 ptrade-t-3
ptrade-t-4 ptrade-t-5 ptrade-t-6 ptrade-t-7 wtrade-t-1 wtrade-t-2 wtrade-t-3
wtrade-t-4 wtrade-t-5 wtrade-t-6 wtrade-t-7 deposit pexchange wexchange mexchange
savings capital pdebt fdebt securities productivity pprice wprice
farmer-interest-rate professional-interest-rate withdraw
reserve-ratio produce-purchaseprice produce-saleprice widget-purchaseprice
widget-saleprice fbusiness pbusiness wealth savings_propensity bankrupt]
breed [farmers farmer]
breed [professionals professional]
breed [stores store]
breed [farmerBanks farmerBank]
breed [professionalBanks professionalBank]
to step
go
end
; msg
;
; debug method to print a message to the console
;
to msg [ txt ]
let time-tag ticks
type "debug: ticks = " type time-tag type " " type txt print " "
end
to go
msg "set-interest-rate..." set-interest-rate msg "set-interest-rate finished OK"
msg "repay starting..." repay msg "repay finished OK"
msg "disasterstarting..." disaster msg "disaster finished OK"
ifelse random 100 < 50 [ ; flip order randomly, or else store is biased toward one breed
msg "move-farmers starting..." move-farmers msg "move-farmers finished OK"
msg "move-professionals starting..." move-professionals msg "move-professionals finished OK"]
[
msg "move-professionals starting..." move-professionals msg "move-professionals finished OK"
msg "move-farmers starting..." move-farmers msg "move-farmers finished OK"]
; reproduce-farmers
; reproduce-professionals
msg "renew-fuel starting..." renew-fuel msg "renew-fuel finshed OK"
msg "store-deposit..." store-deposit msg "store-deposit finished OK"
msg "bankruptcy starting..." bankruptcy msg "bankruptcy finished OK"
msg "compound-interest starting..." compound-interest msg "compound-interest finished OK"
msg "borrow-emergency-funds starting..." borrow-emergency-funds msg "borrow-emergency-funds finished OK"
; msg "farmer-professional-switch starting..." farmer-professional-switch msg "farmer-professional-switch finished OK" ; for labor mobility
msg "update-macro-stats starting..." update-macro-stats msg "update-macro-stats finished OK"
msg "trades-last-period starting..." trades-last-period msg "trades-last-period finished OK"
updateplots
tick
end
to setup
clear-all
setup-landscape
setup-population
setup-infrastructure
setup-prices
setup-interest-rates
update-macro-stats
reset-ticks
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup-landscape
set farm-patches patches with [pxcor < 20] ; define patches
ask farm-patches [ set pcolor green ]
ask farm-patches [ set yield 1 ]
set city-patches patches with [pxcor > 20 ]
ask city-patches [set pcolor red]
ask city-patches [set yield 1]
set trade-patches patches with [pxcor = 20 ]
ask trade-patches [set pcolor blue]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup-population
create-farmers population [
set shape "person farmer"
set productivity 1
; set productivity random-normal 1 .5
; if productivity < .1 [
; set productivity .1]
move-to-empty-one-of farm-patches
set color white
set size 1
set age 1
; set farmers-reproduce 50
set money random-normal 50 20
set savings_propensity random-normal 5 2
if savings_propensity < 1 [
set savings_propensity 1]
set bankrupt 0
]
create-professionals population [
set shape "person business"
set productivity 1
; set productivity random-normal 1 .5
; if productivity < .1 [
; set productivity .1]
move-to-empty-one-of city-patches
set color white
set size 1
set age 1
; set professionals-reproduce 30
set money random-normal 50 20
set savings_propensity random-normal 5 2 if savings_propensity < 1 [
set savings_propensity 1]
set bankrupt 0
]
end
to move-to-empty-one-of [locations] ;; turtle procedure
move-to one-of locations
while [any? other turtles-here] [
move-to one-of locations
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup-infrastructure
create-stores 1
[ ; starting money stock determined with respect to total population
set shape "store"
setxy 20 20
set color white
set size 1
set produce 0
; set trade 0
set money 500 * (count professionals + count farmers)
]
create-farmerBanks 1
[
set shape "bank"
setxy 10 10
set color yellow
set size 1
]
create-professionalBanks 1
[
set shape "bank"
setxy 30 10
set color white
set size 1
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to set-productivity
ask farmers [
set productivity 1 + (widget) ^ (1 / 2) ;;Farmers use widget too get produce
] ; ; Like Cobb Douglass, L = 1
ask professionals
[ set productivity 1 + (produce) ^ (1 / 2)] ;; pros use produce to make widget
end
to setup-prices ; starting prices
ask stores[
set pprice 100
set wprice 100
]
end
to setup-interest-rates ; starting interest rates
ask farmerBanks [
set farmer-interest-rate .002]
ask professionalBanks [
set professional-interest-rate .002]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to move-farmers
ask farmers [
set age age + 1
set-productivity
ifelse produce < random-normal 50 15 [ ; farmers follow a rule of thumb, action
find-new-farmerLocation] ; is subject to minor fluctuations. Same
[next-stepf] ; for professionals.
;if random 100 < 1 [
;]
;set produce produce
set widget widget * (1 - depreciation) ;; widgets get used while farmer gathers produce
]
end
to find-new-farmerLocation
;Farmers search for green patch
let nearest-farm-patch one-of (patches with [pcolor = green] in-cone 1 360)
ifelse is-patch? nearest-farm-patch[
face nearest-farm-patch
fd 1
ask patch-here [
if pcolor = green [
set pcolor black] ]
set produce produce + (yield * productivity)
; set productivity productivity - depreciation
]
[
;; move to black patch if they cannot find a green patch
let nearest-black-patch one-of (patches with [pcolor = black] in-cone 1 360)
ifelse is-patch? nearest-black-patch [
face nearest-black-patch
fd 1
; set productivity productivity - depreciation
]
[
;; Walk to farmerbank if they get lost...
face one-of farmerBanks
fd 1]
]
end
to next-stepf
getMoney-farmer
; farmer checks if wealthy enough to purchase widget
ifelse money + savings + produce * [pprice] of one-of stores + widget * [wprice] of one-of stores - fdebt > (1 + markup) * [wprice] of one-of stores
[getWidget-farmer]
[find-new-farmerLocation]
if random 10 < 1 [deposit-farmer-savings] ; visit bank every now and again
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to move-professionals
ask professionals [
set age age + 1
set-productivity
ifelse widget < random-normal 50 15 ;; see "move-farmers"
[find-new-professionalLocation]
[next-stepp]
set produce produce * (1 - depreciation) ; produce used while making widgets
]
end
to find-new-professionalLocation
;; works like with the farmer, but with the red (yellow) patches
let nearest-city-patch one-of (patches with [pcolor = red] in-cone 1 360)
ifelse is-patch? nearest-city-patch [
fd 1
ask patch-here [
if pcolor = red [
set pcolor yellow]]
set widget widget + (yield * productivity) ;; - cost
; set productivity productivity - depreciation
]
[
let nearest-yellow-patch one-of (patches with [pcolor = yellow] in-cone 1 360)
ifelse is-patch? nearest-yellow-patch [
face nearest-yellow-patch
fd 1]
[face one-of professionalBanks ; if professional gets lost, walk toward proBank
fd 1]
]
end
to next-stepp
getMoney-professional
;professional checks to see if wealthy enough to buy produce
ifelse money + savings + produce * [pprice] of one-of stores + widget * [wprice] of one-of stores - pdebt > (1 + markup * [pprice] of one-of stores)
[ getProduce-professional]
[find-new-professionalLocation]
; Out of habit, professionals visit bank every now and then
if random 10 < 1 [deposit-professional-savings]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to getMoney-farmer
ask stores [
set-prices
; store checks if enough money to buy farmer's produce if not, withdraw savings and/or borrow
if money < pprice * [produce] of myself[
set fbusiness true
store-withdraw]
if money < pprice * [produce] of myself [
set fbusiness true
borrow-store]]
; Purchase produce until either produce is gone or store's money has run low
if produce >= 1 and ([money] of one-of stores ) >= [pprice] of one-of stores[
while [produce >= 1 and ([money] of one-of stores ) >= [pprice] of one-of stores]
[
set money money + [pprice] of one-of stores
set produce produce - 1
ask one-of stores [
set produce produce + 1
set money money - pprice
;set trade trade + 1
set produce-purchaseprice pprice
] ;; store puchased produce
]
]
end
to getWidget-Farmer
set-prices
;; check if enough money to buy widget, if not withdraw savings / borrow
if money + savings > ( 1 + markup) * [wprice] of one-of stores and money < ( 1 + markup) * [wprice] of one-of stores and [widget] of one-of stores >= 1 [
withdraw-farmer-savings]
if money < [wprice] of one-of stores [
borrow-farmer]
;Purchase widgets until no more widgets or insufficient funds.
if money >= ( 1 + markup) * [wprice] of one-of stores and ([widget] of one-of stores) >= 1 [
while [money >= ( 1 + markup) * savings_propensity * [wprice] of one-of stores and ([widget] of one-of stores) >= 1] [
set widget widget + 1
set money money - ( 1 + markup) * [wprice] of one-of stores ; store charges markeup
ask one-of stores [
set money money + ( 1 + markup) * wprice
set widget widget - 1
set wtrade wtrade + 1
set widget-saleprice ( 1 + markup) * [wprice] of one-of stores ;; store sold widget
]
]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to getMoney-professional ;See getMoney-farmer
set-prices
if [money] of one-of stores < wprice * widget [
ask stores [
set pbusiness true
store-withdraw]]
if [money] of one-of stores < wprice * widget[
ask stores [
set pbusiness true
borrow-store]]
if widget >= 1 and ([money] of one-of stores) >= wprice [
while [widget >= 1 and ([money] of one-of stores) >= wprice]
[
set money money + wprice
set widget widget - 1
ask one-of stores [
set money money - wprice
set widget widget + 1
; set trade trade + 1
set widget-purchaseprice wprice] ;; price that store bought widget
]
]
end
to getProduce-professional ; see getWidget-farmer
set-prices
if money < (1 + markup) * [pprice] of one-of stores and money + savings > (1 + markup) * [pprice] of one-of stores [
withdraw-professional-savings]
if money < (1 + markup) * [pprice] of one-of stores [
borrow-professional]
if money >= ( 1 + markup) * [pprice] of one-of stores and ([produce] of one-of stores) >= 1 [
while [money >= ( 1 + markup) * savings_propensity * [pprice] of one-of stores and ([produce] of one-of stores) >= 1]
[
set money money - ( 1 + markup) * [pprice] of one-of stores ; store charges markup on consumer purchases
set produce produce + 1
ask one-of stores [
set money money + ( 1 + markup) * pprice
set produce produce - 1
set ptrade ptrade + 1
set produce-saleprice ( 1 + markup) * pprice ;; price that store sold produce
]
]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to set-prices
; Prices are set according to the stores stock of goods. If stocks fall too low,
; prices rise. If they get too high, prices fall.
ask stores [
if wealth > 0 [
if widget > 0 and widget < 1 * widget-supply-level * (count farmers) [
set wprice wprice * 1.0001]
if widget < 2 * widget-supply-level * (count farmers)[
set wprice wprice * 1.00005]
if widget < 3 * widget-supply-level * (count farmers) [
set wprice wprice * 1.00005]]
if widget > 7 * widget-supply-level * (count farmers) [
set wprice wprice * .9999]
if widget > 8 * widget-supply-level * (count farmers) [
set wprice wprice * .9999]
if widget > 9 * widget-supply-level * (count farmers) [
set wprice wprice * .9995]
; this line necessary because of netlogo has bug when wprice < .1, so price rises an infinitesimal amount
if wprice < .1 [
set wprice wprice * 1.000000000001]
if wealth > 0 [
if produce > 0 and produce < 1 * produce-supply-level * (count professionals)[
set pprice pprice * 1.0001]
if produce < 2 * produce-supply-level * (count professionals)[
set pprice pprice * 1.00005]
if produce < 3 * produce-supply-level * (count professionals)[
set pprice pprice * 1.00005] ]
if produce > 7 * produce-supply-level * (count professionals)[
set pprice pprice * .9999]
if produce > 8 * produce-supply-level * (count professionals)[
set pprice pprice * .9999]
if produce > 9 * produce-supply-level * (count professionals)[
set pprice pprice * .9995]
; this line necessary because of netlogo has bug when pprice < .1
if pprice < .1 [set pprice pprice * 1.000000000001]
; If store is illiquid, lower price goods to accumulate funds
if money + savings - pdebt - fdebt < 0 [
set pprice pprice * .9995
set wprice wprice * .9995]
]
ask farmers[
set pprice [pprice] of one-of stores
set wprice [wprice] of one-of stores]
ask professionals[
set pprice [pprice] of one-of stores
set wprice [wprice] of one-of stores]
ask farmerBanks [
set pprice [pprice] of one-of stores
set wprice [wprice] of one-of stores]
ask professionalBanks [
set pprice [pprice] of one-of stores
set wprice [wprice] of one-of stores]
end
to trades-last-period
; if nothing sold last period, lower price. After 7 periods, 5 percent drop
ask stores [
if ticks > 20 [
; if wprice > 1[
if wtrade = wtrade-t-7[; and widget > 3 * widget-supply-level * (count farmers)[
set wprice wprice * .95]
if wtrade = wtrade-t-6[; and widget > 3 * widget-supply-level * (count farmers)[
set wprice wprice * .98]
if wtrade = wtrade-t-5[; and widget > 3 * widget-supply-level * (count farmers)[
set wprice wprice * .98]
; if wtrade = wtrade-t-4[; and widget > 3 * widget-supply-level * (count farmers)[
; set wprice wprice * .999]
; if wtrade = wtrade-t-3[; and widget > 3 * widget-supply-level * (count farmers)[
; set wprice wprice * .99]
; if wtrade = wtrade-t-2[; and widget > 3 * widget-supply-level * (count farmers)[
; set wprice wprice * .99]
; if wtrade = wtrade-t-1[; and widget > 3 * widget-supply-level * (count farmers)[
; set wprice wprice * .99] ]
; ]
; if pprice > 1 [
if ptrade = ptrade-t-7[; and produce > 3 * produce-supply-level * (count professionals) [
set pprice pprice * .95]
if ptrade = ptrade-t-6[; and produce > 3 * produce-supply-level * (count professionals)[
set pprice pprice * .98]
if ptrade = ptrade-t-5[; and produce > 3 * produce-supply-level * (count professionals)[
set pprice pprice * .98]
; if ptrade = ptrade-t-4[; and produce > 3 * produce-supply-level * (count professionals)[
; set pprice pprice * .999]
; if ptrade = ptrade-t-3[; and produce > 3 * produce-supply-level * (count professionals)[
; set pprice pprice * .99]
; if ptrade = ptrade-t-2[; and produce > 3 * produce-supply-level * (count professionals)[
; set pprice pprice * .99]
; if ptrade = ptrade-t-1[; and produce > 3 * produce-supply-level * (count professionals)[
; set pprice pprice * .99] ]
;store reandomly checks to see if it can bump up prices
if random 20 < 1 [set wprice wprice * 1.05]
if random 20 < 1 [set pprice pprice * 1.05]
set ptrade-t-7 ptrade-t-6
set wtrade-t-7 wtrade-t-6
set ptrade-t-6 ptrade-t-5
set wtrade-t-6 wtrade-t-5
set ptrade-t-5 ptrade-t-4
set wtrade-t-5 wtrade-t-4
set ptrade-t-4 ptrade-t-3
set wtrade-t-4 wtrade-t-3
set ptrade-t-3 ptrade-t-2
set wtrade-t-3 wtrade-t-2
set ptrade-t-2 ptrade-t-1
set wtrade-t-2 wtrade-t-1
set ptrade-t-1 ptrade
set wtrade-t-1 wtrade
]
]
end
to borrow-emergency-funds
ask farmerBanks
[
; borrow in units of 100
if [money] of one-of professionalBanks / ([securities] of one-of professionalBanks + .000000001) > .01 [ ;sum [savings] of farmers < 20 * [wprice] of one-of stores [ ; add decimal to avoid divde by zero
set pdebt pdebt + 100
set money money + 100
ask one-of professionalBanks [
set money money - 100
set securities securities + 100]
]
; repay some of debt if funds available
if money > .1 * pdebt [
set deposit pdebt * .1
set money money - deposit
set pdebt pdebt - deposit
ask one-of professionalBanks
[
set money money + [deposit] of myself
set securities securities - [deposit] of myself
]
]
]
ask professionalBanks [
; see above
if [money] of one-of farmerBanks / ([securities] of one-of farmerBanks + .000000001) > .01 [ ;sum [savings] of professionals < 20 * [pprice] of one-of stores and [money] of one-of farmerBanks / ([securities] of one-of farmerBanks + .000000001) > .01 [ ; add decimal to avoid divde by zero
set fdebt fdebt + 100
set money money + 100
ask one-of farmerBanks [
set money money - 100
set securities securities + 100]
]
if money > .1 * pdebt [
set deposit fdebt * .1
set money money - deposit
set fdebt fdebt - deposit
ask one-of farmerBanks [
set money money + [deposit] of myself
set securities securities - [deposit] of myself]
]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Allows for labor mobility when turned on. Farmer's become professionals or vice versa when prices diverge.
to farmer-professional-switch
ask farmers[
if random 10 < 1 and (count farmers) / (count professionals) > .1 and [pprice] of one-of stores > 0[
let price-ratio ( [wprice] of one-of stores / [pprice] of one-of stores)
if ( price-ratio ) > 2 [
set deposit 50 * price-ratio
if money > deposit [
set money money - deposit
ask one-of stores [
set money money + [deposit] of myself ]
hatch-professionals 1 [
set money money
set produce produce
set fdebt fdebt
set widget widget ;;;; you'll have to communicate through the patches
]
die
]
]
]
]
ask professionals[
if random 10 < 1 and (count professionals) / (count farmers) > .1 and [wprice] of one-of stores > 0 [
let price-ratio ( [pprice] of one-of stores / [wprice] of one-of stores)
if (price-ratio) > 2 [
set deposit 50 * price-ratio
if money > deposit [
set money money - deposit
ask one-of stores[
set money money + [deposit] of myself]
hatch-farmers 1[
set money money
set produce produce
set widget widget
set pdebt pdebt ]
die
]
]
]
]
end
;;;;;;;];;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to borrow-store
;; store is low on money and bank can afford to lend
ifelse random 100 < 50 [ ; decision for borrowing from one bank or the other is random
if fbusiness = true [
while [money < 1.1 * pprice * [produce] of myself and [money] of one-of farmerBanks / ([securities] of one-of farmerBanks + .00000000001) > .1 ; denominator cannot equal zero
and fdebt + pdebt < .9 * (produce * pprice + widget * wprice + money + savings)][
ask one-of farmerBanks [
set securities securities + [pprice] of one-of stores
set money money - [pprice] of one-of stores]
set fdebt fdebt + pprice
set money money + pprice]]]
[ if pbusiness = true [
while [money < 1.1 * wprice * [widget] of one-of stores and [money] of one-of professionalBanks / ([securities] of one-of professionalBanks + .0000000000001) > .1 and ; see above
fdebt + pdebt < .9 * (produce * pprice + widget * wprice + money + savings)][
ask one-of professionalBanks [
set securities securities + [wprice] of one-of stores
set money money - [wprice] of one-of stores]
set pdebt pdebt + wprice
set money money + wprice
]]]
end
to borrow-farmer
while[ money < (1 + markup) * wprice * [widget] of one-of stores and [money] of one-of farmerBanks > (1 + markup) * wprice and
fdebt < .99 * pprice * (produce + wprice * widget + money + savings)] [
;; farmers and pros borrow up to 90% of wealth
set fdebt fdebt + (1 + markup) * wprice
set money money + (1 + markup) * wprice
ask one-of farmerBanks [
set securities securities + (1 + markup) * wprice
set money money - (1 + markup) * wprice]
]
end
to borrow-professional
;see above
while [money < (1 + markup) * pprice * [produce] of one-of stores and [money] of one-of professionalbanks > (1 + markup) * pprice and
pdebt < .99 * (pprice * produce + wprice * widget + money + savings - pdebt)][
set pdebt pdebt + (1 + markup) * pprice
set money money + (1 + markup) * pprice
ask one-of professionalBanks [
set securities securities + (1 + markup) * pprice
set money money - (1 + markup) * pprice]
]
set-interest-rate
end
to repay
ask stores [
if money > (pprice) and fdebt > 0 and money > .1 * fdebt[
set deposit fdebt * .1
set fdebt fdebt - deposit
set money money - deposit
ask one-of farmerBanks [
set securities securities - [deposit] of myself
set money money + [deposit] of myself]
]
if fdebt > 0 and savings > .1 * fdebt[
set deposit fdebt * .1
set fdebt fdebt - deposit
set savings savings - deposit
ask one-of farmerBanks[
set securities securities -[deposit] of myself]
]
if pdebt > 0 and money > .1 * pdebt[
set deposit pdebt * .1
set pdebt pdebt - deposit
set money money - deposit
ask one-of professionalBanks [
set securities securities - [deposit] of myself
set money money + [deposit] of myself
]
]
if pdebt > 0 and savings > .1 * pdebt [
set deposit pdebt * .1
set pdebt pdebt - deposit
set savings savings - deposit
ask one-of professionalBanks[
set securities securities - [deposit] of myself]
]
]
ask farmers [
;pay debt with money
set mexchange fdebt * .05
if money > wprice and money > mexchange [
set fdebt fdebt - mexchange
set money money - mexchange
ask one-of farmerBanks [
set securities securities - [mexchange] of myself
set money money + [mexchange] of myself
]
]
; pay debt with savings
if savings > [wprice] of one-of stores and savings > mexchange[
set fdebt fdebt - mexchange
set savings savings - mexchange
ask one-of farmerbanks[
set securities securities - mexchange]
]
]
; pay debt with money
ask professionals[
set mexchange pdebt * .05
if money > pprice and money > mexchange [
set pdebt pdebt - mexchange
set money money - mexchange
ask one-of professionalBanks [
set securities securities - [mexchange] of myself
set money money + [mexchange] of myself
]
]
; pay debt with savings
if savings > [pprice] of one-of stores and savings > mexchange[
set pdebt pdebt - mexchange
set savings savings - mexchange
ask one-of farmerbanks[
set securities securities - mexchange]
]
]
end
to bankruptcy
;if agents insolvent, declare bankruptcy and liquidate assets
ask farmers [
if money + savings - fdebt + produce * [pprice] of one-of stores + widget * [wprice] of one-of stores < 0 [
ask one-of farmerBanks [
set money money + [money] of myself
set securities securities - [fdebt] of myself
; set produce produce + [produce] of myself
; set widget widget + [widget] of myself]
]; ask farmers [; set savings savings + ([savings] of myself / ((count farmers) - 1 )) ; set produce produce + ([produce] of myself / ((count farmers) - 1 )); set widget widget + ([widget] of myself / ((count farmers) - 1 )) ;]
set money 0
set savings 0
set fdebt 0
set produce 0
set widget 0
set bankrupt bankrupt + 1]
]
;]
ask professionals [
if money + savings - pdebt + produce * [pprice] of one-of stores + widget * [wprice] of one-of stores < 0 * wealth [
ask one-of professionalBanks [
set money money + [money] of myself
set securities securities - [pdebt] of myself]
;; set produce produce + [produce] of myself
;; set widget widget + [widget] of myself;;
ask professionals [
set savings savings + ([savings] of myself / ((count professionals) - 1 ))
set produce produce + ([produce] of myself / ((count professionals) - 1 ))
set widget widget + ([widget] of myself / ((count professionals) - 1 )) ]
set money 0
set savings 0
set pdebt 0
set produce 0
set widget 0
set bankrupt bankrupt + 1
]
]
end
to set-interest-rate
; banks want to hold some proportion of the stock of available base money
ask farmerBanks [
if farmer-interest-rate > .00002 and ([securities] of one-of farmerBanks) > 0 [
if money < .5 * sum [money] of farmers [
set farmer-interest-rate farmer-interest-rate * 1.0000005]
if money < .4 * sum [money] of farmers [
set farmer-interest-rate farmer-interest-rate * 1.000001]
if money < .2 * sum [money] of farmers [
set farmer-interest-rate farmer-interest-rate * 1.000002]
if money > .6 * sum [money] of farmers [
set farmer-interest-rate farmer-interest-rate * .999995]
if money > .65 * sum [money] of farmers [
set farmer-interest-rate farmer-interest-rate * .999999]
if money > .7 * sum [money] of farmers [
set farmer-interest-rate farmer-interest-rate * .999998]
; if (money / securities) < .1 [
; set farmer-interest-rate farmer-interest-rate + .000001]
; if (money / securities) < .2 [
; set farmer-interest-rate farmer-interest-rate + .000001]
; if (money / securities) > .5 [
; set farmer-interest-rate farmer-interest-rate - .000001]
; if (money / securities) < .6 [
; set farmer-interest-rate farmer-interest-rate - .000001]
; if (money / securities) < .7 [
; set farmer-interest-rate farmer-interest-rate - .0001]
; if (money / securities) < .8 [
; set farmer-interest-rate farmer-interest-rate - .0001]
]
; rate cannot equal zero or rise above 1 percent per day
if farmer-interest-rate = 0 [ set farmer-interest-rate .00001]
if farmer-interest-rate > .01 [ set farmer-interest-rate .01]
]
ask professionalBanks [
if money < .05 * sum [money] of professionals [
set professional-interest-rate professional-interest-rate * 1.000005]
if money < .1 * sum [money] of professionals [
set professional-interest-rate professional-interest-rate * 1.000001]
if money < .2 * sum [money] of professionals [
set professional-interest-rate professional-interest-rate * 1.000002]
if money > .5 * sum [money] of farmers [
set professional-interest-rate professional-interest-rate * .999995]
if money > .6 * sum [money] of farmers [
set professional-interest-rate professional-interest-rate * .999999]
if money > .7 * sum [money] of farmers [
set professional-interest-rate professional-interest-rate * .999998]
; if professional-interest-rate > .0002 and ([securities] of one-of professionalBanks) > 0 [
; if (money / securities) < .1 [
; set professional-interest-rate professional-interest-rate + .000001]
; if (money / securities) < .2 [
; set professional-interest-rate professional-interest-rate + .000001]
; if (money / securities) > .3 [
; set professional-interest-rate professional-interest-rate - .000001]
; if (money / securities) < .4 [
; set professional-interest-rate professional-interest-rate - .000001]
; if (money / securities) < .7 [
; set professional-interest-rate professional-interest-rate - .0001]
; if (money / securities) < .8 [
; set professional-interest-rate professional-interest-rate - .0001]
; ]
if professional-interest-rate < .0002 [ set professional-interest-rate professional-interest-rate * .00001]
if professional-interest-rate = 0 [ set professional-interest-rate .00001]
if professional-interest-rate > .01 [ set professional-interest-rate .01]
]
;
end
to compound-interest
ask stores [
set savings savings * (1 + professional-interest-rate )
set pdebt pdebt * (1 + professional-interest-rate)
set fdebt fdebt * (1 + farmer-interest-rate)
set securities securities * (1 + professional-interest-rate) ]
ask farmerBanks [
set savings savings * (1 + professional-interest-rate); / 40000000)
set pdebt pdebt * ( 1 + professional-interest-rate); / 20000000)
set securities securities * (1 + farmer-interest-rate)]; / 20000000)]
ask professionalBanks[
set savings savings * (1 + farmer-interest-rate); / 40000000)
set fdebt fdebt * (1 + (farmer-interest-rate)); / 20000000))
set securities securities * (1 + professional-interest-rate)]; / 20000000]
ask farmers [
set savings savings * (1 + farmer-interest-rate); / 40000000)
set fdebt fdebt * (1 + farmer-interest-rate); / 20000000)
]
ask professionals [
set pdebt pdebt * (1 + professional-interest-rate); / 20000000)
set savings savings * (1 + professional-interest-rate)
]
end
to store-deposit
;;store deposits when it holds above a minimum level fo real balances
ask stores [
; if random 200 < 1 [
; set withdraw savings * .2
; set savings savings - withdraw
; set money money + withdraw
; ask myfarmbank [
; set money money - .5 *[withdraw] of myself
; ]
; ask myprobank [
; set money money - .5 * [withdraw] of myself
; ]
; ]
ifelse random 100 < 50 and money > 5 * pprice [ ; and fdebt <= 0[
set deposit .05 * (money - 5 * pprice)
set money money - deposit
set savings savings + deposit
ask one-of farmerBanks [
set money money + [deposit] of myself
]]
[if money > 5 * wprice [; and pdebt <= 0[
set deposit .05 * (money - 5 * wprice)
set money money - deposit
set savings savings + deposit
ask one-of professionalBanks [
set money money + [deposit] of myself
]]]]
end
to store-withdraw
; withdraw when not enough funds to by available goods
if fbusiness = true [
while [money < pprice * [produce] of myself and savings >= pprice and [money] of one-of farmerBanks > pprice] [
set withdraw pprice
set money money + withdraw
set savings savings - withdraw
ask one-of farmerBanks [
set money money - [withdraw] of myself
]]]
if pbusiness = true[
while [money < wprice * [widget] of myself and savings >= wprice and [money] of one-of professionalBanks > wprice ][
set withdraw wprice
set money money + withdraw
set savings savings - withdraw
ask one-of professionalBanks [
set money money - [withdraw] of myself
]]]
set-interest-rate
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to withdraw-farmer-savings
; farmer withdraws savings when short on funds for purchase of widgets
while [ money < ( 1 + markup) * [wprice] of one-of stores * [widget] of one-of stores and savings > ( 1 + markup) * [wprice] of one-of stores and
[money] of one-of farmerBanks > ( 1 + markup) * [wprice] of one-of stores] [