ergo

package module
v0.0.0-...-89088f0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package ergo allows running an ergodicity economics experiment by Ole Peters Get players to all bet $100 dollars and repeatedly flip a coin: 1. Heads their wealth increases by 50% 2. Tails their wealth decreases by 40%

A great bet on the surface.

While collective wealth increases by 5% (compounds) at every coin flip, the vast majority of players end up skint with only few big winners; wealth aggregation (though ultimately it's a zero sum gain). It's by no means a representation of a the real world, but Ole Peters uses it to demonstrate the difference between _ensemble average_ and _time average_ (and how economics does not understand that).

Import the package with

"github.com/go-ergo/ergo"

Then play a "game," pass it the number of players, the number of coin tosses, and the starting amount of cash of each player

g := ergo.Play(50, 100, 1000)

You can also compute the ensemble average

g.EnsembleAvg()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ensemble

type Ensemble struct {
	Time   []int     `json:"stepIndex"`
	Amount []float32 `json:"cash"`
}

Ensemble average of all players over time

type Game

type Game struct {
	Players []Player `json:"players"`
}

Game a game object containing players

func Play

func Play(players, steps int, starting float32) *Game

Play run the simulation

func (*Game) EnsembleAvg

func (game *Game) EnsembleAvg() Ensemble

EnsembleAvg avreage of all players over time

func (*Game) Roll

func (g *Game) Roll(step int)

Roll run the game one step

func (*Game) RollAll

func (g *Game) RollAll(steps int)

RollAll run all steps

type Player

type Player struct {
	ID    int    `json:"id"`
	Steps []Step `json:"steps"`
}

Player a player in the game and its steps

type Step

type Step struct {
	Time   int     `json:"stepIndex"`
	Amount float32 `json:"cash"`
}

Step defines a time step

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL