mcs

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NetCashflows

func NetCashflows(cfg Config, seed uint64, cpus int) ([]float64, []float64, []float64)

NetCashflows calculates the net cashflows, cash inflows, and cash outflows for a given number of simulations, number of periods, cashflow distributions, and random source.

Types

type Cashflow

type Cashflow struct {
	Name      string
	IsOutflow bool
	Periods   string
	Dist      Randomizer
	Growth    Growth
}

Cashflow models the setup information needed for a cashflow for the Monte Carlo simulation.

func (Cashflow) String added in v0.8.2

func (cf Cashflow) String() string

type Config added in v0.5.0

type Config struct {
	Name        string     `json:"name"`
	StartPeriod int        `json:"startPeriod"`
	EndPeriod   int        `json:"endPeriod"`
	Sims        int        `json:"sims"`
	Cashflows   []Cashflow `json:"cashflows"`
}

Config models the net cashflows configuration information.

func ParseFile added in v0.5.0

func ParseFile(filename string) (Config, error)

ParseFile parses the JSON configuration file into a Config struct.

func (*Config) UnmarshalJSON added in v0.7.0

func (c *Config) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the given JSON byte slice into a Config struct.

type Fixed

type Fixed float64

Fixed is a fixed number.

func NewFixed added in v0.7.0

func NewFixed(num float64) Fixed

NewFixed returns a Fixed distribution.

func (Fixed) Randomize added in v0.4.0

func (f Fixed) Randomize(src rand.Source) Rander

Randomize a new fixed number.

func (Fixed) String added in v0.9.0

func (f Fixed) String() string

String implements the io.Stringer interface.

func (*Fixed) UnmarshalJSON added in v0.7.0

func (f *Fixed) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the given JSON data into a Fixed MCS distribution.

type Growth added in v0.3.0

type Growth struct {
	Periods string
	Dist    Randomizer
	Name    string
}

Growth models the setup information for a Growth rate.

func (Growth) String added in v0.8.2

func (g Growth) String() string

type PERT

type PERT struct {
	// contains filtered or unexported fields
}

PERT models a PERT distribution with the values min, max, mode but without a random source.

func NewPERT added in v0.7.0

func NewPERT(min, max, mode float64) PERT

NewPERT constructs a new PERT distribution without a random source using the given min, max, and mode. Constraints are min < max and min ≤ mode ≤ max.

func (PERT) Randomize added in v0.4.0

func (p PERT) Randomize(src rand.Source) Rander

Randomize sets up a new PERT distribution using the given random source.

func (PERT) String added in v0.9.0

func (p PERT) String() string

String implements the io.Stringer interface.

func (*PERT) UnmarshalJSON added in v0.7.0

func (p *PERT) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the given JSON data into a PERT MCS distribution.

type PERTOne added in v0.7.0

type PERTOne struct {
	// contains filtered or unexported fields
}

PERTOne models a PERT distribution once with the values min, max, mode, and then returns the same number each time. PERTOne does not have a random source.

func NewPERTOne added in v0.7.0

func NewPERTOne(min, max, mode float64) PERTOne

NewPERTOne constructs a new PERT distribution without a random source using the given min, max, and mode. Constraints are min < max and min ≤ mode ≤ max. Once the random number has been generated using the PERT distribution, the same number will be returned each time.

func (PERTOne) Randomize added in v0.7.0

func (po PERTOne) Randomize(src rand.Source) Rander

Randomize sets up a new one-time only PERT distribution.

func (PERTOne) String added in v0.9.0

func (po PERTOne) String() string

String implements the io.Stringer interface.

func (*PERTOne) UnmarshalJSON added in v0.7.0

func (po *PERTOne) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the given JSON data into a PERT MCS distribution.

type Rander

type Rander interface {
	Rand() float64
}

Rander is the interface that wraps the Rand method.

The Rand method returns a random sample drawn from the distribution.

type Randomizer added in v0.4.0

type Randomizer interface {
	Randomize(src rand.Source) Rander
	String() string
}

Randomizer is the interface that wraps the Randomize method.

Randomizer allows different random sources to be injected into the returned Rander interface. The ability to inject random sources is why the cashflows don't simply take a Rander but instead use a Randomizer for their distributions.

type Triangle

type Triangle struct {
	// contains filtered or unexported fields
}

Triangle is a triangle distribution with the values min, max, mode.

func NewTriangle added in v0.7.0

func NewTriangle(min, max, mode float64) Triangle

NewTriangle returns a new triangle distribution with the values min, max, and mode.

func (Triangle) Randomize added in v0.4.0

func (t Triangle) Randomize(src rand.Source) Rander

Randomize sets up a new triangle distribution.

func (Triangle) String added in v0.9.0

func (t Triangle) String() string

String implements the io.Stringer interface.

func (*Triangle) UnmarshalJSON added in v0.7.0

func (t *Triangle) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the given JSON data into a PERT MCS distribution.

type TriangleOne

type TriangleOne struct {
	// contains filtered or unexported fields
}

TriangleOne use a triangle distribution once and then returns the same number each time.

func NewTriangleOne added in v0.7.0

func NewTriangleOne(min, max, mode float64) TriangleOne

func (TriangleOne) Randomize added in v0.4.0

func (to TriangleOne) Randomize(src rand.Source) Rander

Randomize sets up a new one-time only triangle distribution.

func (TriangleOne) String added in v0.9.0

func (to TriangleOne) String() string

String implements the io.Stringer interface.

func (*TriangleOne) UnmarshalJSON added in v0.7.0

func (to *TriangleOne) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the given JSON data into a PERT MCS distribution.

type Uniform

type Uniform struct {
	// contains filtered or unexported fields
}

Uniform is a uniform distribution with the values min and max.

func NewUniform added in v0.7.0

func NewUniform(min, max float64) Uniform

NewUniform constructs a new Uniform distribution without a random source using the given min and max values.

func (Uniform) Randomize added in v0.4.0

func (u Uniform) Randomize(src rand.Source) Rander

Randomize sets up a new uniform distribution.

func (Uniform) String added in v0.9.0

func (u Uniform) String() string

String implements the io.Stringer interface.

func (*Uniform) UnmarshalJSON added in v0.7.0

func (u *Uniform) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the given JSON data into a PERT MCS distribution.

Jump to

Keyboard shortcuts

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