money

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package money provides money management and position sizing

Index

Constants

View Source
const DefaultStepSize = 0.01

DefaultStepSize is the default step size (rounding) for position sizes.

Variables

This section is empty.

Functions

This section is empty.

Types

type FixedSizer

type FixedSizer struct {
	FixedCapital decimal.Decimal
	StepSize     float64
}

FixedSizer is a fixed position sizing strategy. Size is fixed capital divided by price (rounded to StepSize).

func NewFixedSizer

func NewFixedSizer(capital decimal.Decimal) *FixedSizer

NewFixedSizer returns a new FixedSizer with the given fixed capital and a default step size.

func (*FixedSizer) Size

func (s *FixedSizer) Size(price, capital, risk decimal.Decimal) decimal.Decimal

Size returns the fixed capital divided by price (rounded to StepSize). Returns 0 if size is NaN/Inf.

type SafeFSizer

type SafeFSizer struct {
	InitialCapital decimal.Decimal
	F              float64
	ScaleF         float64
	StepSize       float64
}

SafeFSizer is a Sizer that uses a fixed fraction method (e.g. Kelly / OptimalF) with a safety margin.

func NewSafeFSizer

func NewSafeFSizer(initialCapital decimal.Decimal, f, scaleF float64) *SafeFSizer

NewSafeFSizer returns a new SafeFSizer with the given initial capital, fixed fraction, scale factor, and step size.

func (*SafeFSizer) Size

func (s *SafeFSizer) Size(price, capital, risk decimal.Decimal) decimal.Decimal

Size moderates a fixed fraction position size by:

- scaling f using the ScaleF fraction (typically 0.5)

- only using the square root of the profits as trading capital.

type Sizer

type Sizer interface {
	Size(price, capital, risk decimal.Decimal) decimal.Decimal
}

Sizer is the interface for position sizing.

Jump to

Keyboard shortcuts

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