Giter Site home page Giter Site logo

transaction-simulation's Introduction

Transaction simulation

This is a simple transaction simulation model which operates on four inputs: number of players, a transaction function, an iteration count, and an initial wealth distributor.

To run the simulation, make sure you have Haskell installed and simply do cabal sandbox init, cabal install, and cabal run.

Running the simulation will report a gini for the starting and ending worlds, as well as the starting and ending percentiles of the players who ended up the most wealthy.

Transaction function

A transaction function is a function MonadRandom m => (Wealth , Wealth) -> m (Wealth , Wealth), which means it's a function in the MonadRandom monad which accepts two wealth inputs, one for each party to the transaction, and returns two wealth outputs, again, one for each party.

-- example transaction function
-- | Transaction function where a random amount of wealth both parties can afford is gambled
randomLimitByNegotiatingPower :: MonadRandom m => (Wealth , Wealth) -> m (Wealth , Wealth)
randomLimitByNegotiatingPower (w1 , w2) = do

  v <- getRandomR (0.0 , min w1 w2)

  k :: Bool <- getRandom

  pure $ if k then (w1 + v , w2 - v) else (w1 - v , w2 + v)

Initial wealth

Initial wealth is simply a MonadRandom m => m Wealth:

genWealth :: MonadRandom m => m Wealth
genWealth =
  -- uniform wealth scale (low start gini)
  getRandomR (1000 , 2000000)

transaction-simulation's People

Contributors

identicalsnowflake avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.