risk

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: 5 Imported by: 0

Documentation

Overview

Package risk offers an API to evaluate trade risk. Used in conjunction with the money package to size positions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FullRisker

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

FullRisker assumes that the current price is the maximum downside risk. This is equivalent to assumming a position size of 1 and no stopp loss.

func NewFullRisker

func NewFullRisker() *FullRisker

NewFullRisker returns a new FullRisker.

func (*FullRisker) ReceivePrice

func (r *FullRisker) ReceivePrice(ctx context.Context, price market.Kline) error

ReceivePrice updates the FullRisker with the next price.

func (*FullRisker) Risk

func (r *FullRisker) Risk() decimal.Decimal

Risk returns a unitary measure of risk based on the current price. Will always be the current price.

func (*FullRisker) Valid

func (r *FullRisker) Valid() bool

Valid returns true if the risker has enough data to be calculated. Will always return true.

type Risker

type Risker interface {
	// ReceivePrice updates the risker with the next price.
	market.Receiver

	// Risk returns a unitary measure of risk based on the current price.
	Risk() decimal.Decimal

	// Valid returns true if the risker has enough data to be calculated.
	Valid() bool
}

Risker is an interface that defines the methods needed to evaluate trade risk.

type SDRisker

type SDRisker struct {
	SD *ta.SD
}

SDRisker is a Risker that uses the standard deviation of a moving window.

func NewSDRisker

func NewSDRisker(length int, factor float64) *SDRisker

NewSDRisker returns a new SDRisker.

func (*SDRisker) ReceivePrice

func (r *SDRisker) ReceivePrice(ctx context.Context, price market.Kline) error

ReceivePrice updates the SDRisker with the next price.

func (*SDRisker) Risk

func (r *SDRisker) Risk() decimal.Decimal

Risk returns a unitary measure of risk based on the current price.

func (*SDRisker) Valid

func (r *SDRisker) Valid() bool

Valid returns true if the risker has enough data to be calculated.

Jump to

Keyboard shortcuts

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