returns

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: MIT Imports: 14 Imported by: 2

Documentation

Overview

Package returns implements data structures and convenience methods for interacting with a list of returns or sets of date-aligned returns.

Please remember, investing carries inherent risks including but not limited to the potential loss of principal. Past performance is no guarantee of future results. The data, equations, and calculations in these docs and code are for informational purposes only and should not be considered financial advice. It is important to carefully consider your own financial situation before making any investment decisions. You should seek the advice of a licensed financial professional before making any investment decisions. You should seek code review of an experienced software developer before consulting this library (or any library that imports it) to make investment decisions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColumnGroup

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

func (ColumnGroup) Length

func (group ColumnGroup) Length() int

func (ColumnGroup) MarshalBSON added in v0.2.0

func (group ColumnGroup) MarshalBSON() ([]byte, error)

func (ColumnGroup) MarshalJSON added in v0.2.0

func (group ColumnGroup) MarshalJSON() ([]byte, error)

func (*ColumnGroup) UnmarshalBSON added in v0.2.0

func (group *ColumnGroup) UnmarshalBSON(buf []byte) error

func (*ColumnGroup) UnmarshalJSON added in v0.2.0

func (group *ColumnGroup) UnmarshalJSON(buf []byte) error

type ErrorNoReturns

type ErrorNoReturns struct{}

func (ErrorNoReturns) Error

func (err ErrorNoReturns) Error() string

type List

type List []Return

func (List) AnnualizedArithmeticReturn

func (list List) AnnualizedArithmeticReturn() float64

func (List) AnnualizedRisk

func (list List) AnnualizedRisk() float64

AnnualizedRisk must receive at least 2 returns otherwise it returns 0

func (List) AnnualizedTimeWeightedReturn

func (list List) AnnualizedTimeWeightedReturn() float64

AnnualizedTimeWeightedReturn must receive at least 2 returns otherwise it returns 0

func (List) Between

func (list List) Between(t1, t0 time.Time) List

Between returns a slice of a list. You may want pass result into slices.Clone() before using any mutating functions (such as Insert).

func (List) EndAndStartDate

func (list List) EndAndStartDate() (end, start time.Time, _ error)

func (List) Excess

func (list List) Excess(other List) List

func (List) First

func (list List) First() Return

func (List) FirstTime

func (list List) FirstTime() time.Time

func (List) Insert

func (list List) Insert(newReturn Return) List

Insert correctly places newReturn in List. If newReturn.Time is the same as an existing return in s, the value of the existing return is overwritten.

func (List) Last

func (list List) Last() Return

func (List) LastTime

func (list List) LastTime() time.Time

func (List) Len

func (list List) Len() int

func (List) Less

func (list List) Less(i, j int) bool

func (List) Returns

func (list List) Returns() List

func (List) Reverse

func (list List) Reverse()

func (List) Risk

func (list List) Risk() float64

Risk calls calculations.RiskFromStdDev

func (List) Sort

func (list List) Sort()

func (List) Swap

func (list List) Swap(i, j int)

func (List) TimeWeightedReturn

func (list List) TimeWeightedReturn() float64

func (List) Times

func (list List) Times() []time.Time

func (List) Value

func (list List) Value(t time.Time) (float64, bool)

func (List) Values

func (list List) Values() []float64

type Return

type Return struct {
	Value float64   `json:"value" bson:"value"`
	Time  time.Time `json:"time" bson:"time"`
}

func New

func New(t time.Time, v float64) Return

type Table

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

func AlignTables

func AlignTables(tables ...Table) (_ []Table, end, start time.Time, _ error)

AlignTables may be used to ensure multiple tables are date-aligned.

func NewTable

func NewTable(list []List) Table

func (Table) AddColumn

func (table Table) AddColumn(list List) Table

func (Table) AddColumnGroup

func (table Table) AddColumnGroup(lists []List) (ColumnGroup, Table)

func (Table) AddColumns

func (table Table) AddColumns(lists []List) Table

func (Table) AddTable added in v0.2.0

func (table Table) AddTable(other Table) (Table, ColumnGroup)

func (Table) AnnualizedArithmeticReturn added in v0.2.0

func (table Table) AnnualizedArithmeticReturn(column int) float64

func (Table) AnnualizedArithmeticReturns

func (table Table) AnnualizedArithmeticReturns() []float64

func (Table) AnnualizedRisk added in v0.2.0

func (table Table) AnnualizedRisk(column int) float64

func (Table) AnnualizedRisks

func (table Table) AnnualizedRisks() []float64

func (Table) Between

func (table Table) Between(last, first time.Time) Table

func (Table) ColumnGroup added in v0.2.0

func (table Table) ColumnGroup() ColumnGroup

func (Table) ColumnGroupAsTable

func (table Table) ColumnGroupAsTable(group ColumnGroup) Table

func (Table) ColumnGroupColumnIndex

func (table Table) ColumnGroupColumnIndex(group ColumnGroup, groupIndex int) (columnIndex int)

func (Table) ColumnGroupLists

func (table Table) ColumnGroupLists(group ColumnGroup) []List

func (Table) ColumnGroupValues

func (table Table) ColumnGroupValues(group ColumnGroup) [][]float64

func (Table) ColumnValues

func (table Table) ColumnValues() [][]float64

func (Table) CorrelationMatrix

func (table Table) CorrelationMatrix() *mat.Dense

func (Table) CorrelationMatrixValues

func (table Table) CorrelationMatrixValues() [][]float64

func (Table) EndAndStartDates

func (table Table) EndAndStartDates() (end, start time.Time, _ error)

func (Table) Equal added in v0.2.0

func (table Table) Equal(other Table) bool

func (Table) ExpectedRisk

func (table Table) ExpectedRisk(weights []float64) float64

func (Table) FirstTime

func (table Table) FirstTime() time.Time

func (Table) HasRow

func (table Table) HasRow(tm time.Time) bool

func (Table) Join

func (table Table) Join(other Table) Table

func (Table) LastTime

func (table Table) LastTime() time.Time

func (Table) List

func (table Table) List(columnIndex int) List

func (Table) Lists

func (table Table) Lists() []List

func (Table) MarshalBSON

func (table Table) MarshalBSON() ([]byte, error)

func (Table) MarshalJSON

func (table Table) MarshalJSON() ([]byte, error)

func (Table) MostRecentValues

func (table Table) MostRecentValues() []float64

func (Table) NumberOfColumns

func (table Table) NumberOfColumns() int

func (Table) NumberOfRows

func (table Table) NumberOfRows() int

func (Table) RangeIndexes

func (table Table) RangeIndexes(last, first time.Time) (end int, start int)

RangeIndexes is a helper to be used to align additional non-return columns to a table

func (Table) RiskFromStdDev added in v0.2.0

func (table Table) RiskFromStdDev(column int) float64

func (Table) RisksFromStdDev added in v0.2.0

func (table Table) RisksFromStdDev() []float64

func (Table) Row

func (table Table) Row(tm time.Time) ([]float64, bool)

func (Table) TimeAfter

func (table Table) TimeAfter(tm time.Time) (time.Time, bool)

func (Table) TimeBefore

func (table Table) TimeBefore(tm time.Time) (time.Time, bool)

func (Table) TimeWeightedReturn added in v0.2.0

func (table Table) TimeWeightedReturn(column int) float64

func (Table) TimeWeightedReturns

func (table Table) TimeWeightedReturns() []float64

func (Table) Times

func (table Table) Times() []time.Time

func (*Table) UnmarshalBSON

func (table *Table) UnmarshalBSON(buf []byte) error

func (*Table) UnmarshalJSON

func (table *Table) UnmarshalJSON(buf []byte) error

func (Table) WriteCSV added in v0.2.0

func (table Table) WriteCSV(w io.Writer, columnNames []string) error

Jump to

Keyboard shortcuts

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