Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a model of the banking system in software #6

Open
nicksellen opened this issue Apr 23, 2015 · 7 comments
Open

Create a model of the banking system in software #6

nicksellen opened this issue Apr 23, 2015 · 7 comments

Comments

@nicksellen
Copy link
Owner

  • How much of the system should it model? (modelling the electronic door opening button at my local bank branch would certainly be too far, but at which point to stop and why?)
  • Which language? Probably Javascript as @serapath (and me) like it, it is widely known, and can be easily readable, and easy to run, etc...
  • Which source references to use? (a small number of technical and complete references would be best)

And why?

  • Allows reuse of code literacy to understand "banking literacy"
  • Allows a more interactive understanding of banking
  • Provides a more tangible focus and discussion point for the topic
  • Why not?
@serapath
Copy link

/******************************************************************************
  DEPENDENCIES
  - Copy & Paste from: https://wzrd.in/standalone/getval
******************************************************************************/
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();
else if("function"==typeof define&&define.amd)define([],e);else{var f;
"undefined"!=typeof window?f=window:"undefined"!=typeof global?
f=global:"undefined"!=typeof self&&(f=self),f.getval=e()}}(function(){var define,module,exports;
return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;
if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");
throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){
var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;
for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
module.exports = function resolve (root, path, delimiter) {
  var tmp = root, keys = (''+path).split(delimiter||'.');
  try { for (idx in keys) { tmp = tmp[keys[idx]]; }
  } catch (e) { return; }
  return tmp;
};},{}]},{},[1])(1)});
/******************************************************************************
  INITIALIZE ECONOMIC HISTORY
******************************************************************************/
var history    = [];
var Tnow       = 0;
var Tnext      = 1;
history[Tnow]  = { economy: {}, journal: [] };
history[Tnext] = { economy: {}, journal: [] };
var BALANCE = {
  ASSETS       : {
    PROPERTY     : {
      TANGIBLES     : { FIXED: {}, CURRENT: {} },
      INTANGIBLES   : { FIXED: {}, CURRENT: {} },
    },
    STOCKS       : {},
    MONEY        : { CLAIMS: {}, CASH: {} }
  },
  OWNERSHIP    : {
    EQUITY       : {},
    LIABILITIES  : {}
  }
};
function actor (name) {
  if (history[Tnext].economy[name]) return;
  history[Tnext].economy[name] = JSON.parse(JSON.stringify(BALANCE));
}
function execute (transactions) {
  function batch (trans) {
    var target = getval(currentEconomy, trans[0]);
    var current = target[trans[1]];
    target[trans[1]]  = current ? current+=trans[2] : trans[2];
    console.log(trans[0]+'.'+trans[1]+ ':' + trans[2]);
  }
  transactions.forEach(batch);
}
var currentEconomy, currentJournal, transaction;
/******************************************************************************
  INITIALIZE & EXECUTE NEXT ECONOMIC PERIOD
******************************************************************************/
// Initialize
currentEconomy = history[Tnext].economy;
currentJournal = history[Tnow].journal;
// New Persons
actor('BANK');
actor('alex');
// All Transactions
transactions  = [
  // alex drills a well in the desert
  ['alex.ASSETS.PROPERTY.TANGIBLES.FIXED','well', +1000],
  ['alex.OWNERSHIP.EQUITY',               'value',+1000],
  // alex takes a loan, because he needs money to buy food
  ['alex.OWNERSHIP.LIABILITIES',          'BANK', +1000], // interest maybe 5% each year
  ['alex.ASSETS.MONEY.CASH',              'value',+1000],
  ['BANK.ASSETS.MONEY.CLAIMS',            'alex', +1000], // takes alex "WELL" as security
  ['BANK.OWNERSHIP.LIABILITIES','alexBankAccount',+1000]
];
execute(transactions);
// Finish Current Period
Tnow++; Tnext++;
history[Tnext] = {
  economy: JSON.parse(JSON.stringify(history[Tnow].economy)),
  journal: []
};
/******************************************************************************
  INITIALIZE & EXECUTE NEXT ECONOMIC PERIOD
******************************************************************************/
// Initialize
currentEconomy = history[Tnext].economy;
currentJournal = history[Tnow].journal;
// New Persons
actor('BANK');
actor('alex');
actor('nick');
// All Transactions
transactions  = [
  // nick goes to the forrest, collects wood and builds a table
  ['nick.ASSETS.PROPERTY.TANGIBLES.CURRENT','table',          +500],
  ['nick.OWNERSHIP.EQUITY',                 'value',          +500],
  // nick sells table to alex
  ['nick.ASSETS.MONEY.CASH',                'value',          +700],
  ['nick.ASSETS.PROPERTY.TANGIBLES.CURRENT','table',          -500],
  ['nick.OWNERSHIP.EQUITY',                 'value',          +200],
  ['BANK.OWNERSHIP.LIABILITIES',            'alexBankAccount',-700],
  ['BANK.OWNERSHIP.LIABILITIES',            'nickBankAccount',+700],
  ['alex.ASSETS.MONEY.CASH',                'value',          -700],
  ['alex.ASSETS.PROPERTY.TANGIBLES.CURRENT','table',          +700]
];
execute(transactions);
// Finish Current Period
Tnow++; Tnext++;
history[Tnext] = {
  economy: JSON.parse(JSON.stringify(history[Tnow].economy)),
  journal: []
};

@serapath
Copy link

Maybe you can play arround with that and simplify the code and maybe even create modules for it for certain parts for it.

What we need to do next is:

  • if possible, simplify the way to write down transactions
  • adapt the code, so that it can handle different var BALANCE structures
  • enable to add constraints, so that it throws if transactions are illegal
  • maybe add the option to add contracts that add automated transactions in each periods until they are fullfilled

If the code above leaves a lot of questions, then lets maybe start with those first :-)

@nicksellen
Copy link
Owner Author

Maybe could use https://github.com/nicksellen/worldview for representing state (would allow adding a watcher for my bank balance for example) - I should probably add explicit batched transactions to it first though (it currently does batching for performance - but the underlying mechanism is the same, it's just implicit vs explicit).

It of course shows me that I do need to do a bit more "homework" before I can meaningfully contribute to the business logic. I can play code though.

Thanks for this though, it's a great start :)

@nicksellen
Copy link
Owner Author

It would be nice to target browser and nodejs environments too. I'm imaging a pretty web visualization one day (with some d3 in there of course).

@serapath
Copy link

https://github.com/serapath/economy
Maybe fork and create a pull request if you think worldview makes sense, add it :-)
It works in the browser and in node for now.
If you add "dom stuff", we have to see :-)

@nicksellen
Copy link
Owner Author

Don't worry, DOM stuff can go in a separate module :) - this is just the engine we're talking about...

@serapath
Copy link

Currently it lacks "rules/constraints" for whether transactions are legal or not.
And it lacks functionality for setting up contracts which are then automatically executed in every period.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants