Version: v0.1.1 Latest Latest

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

Go to latest
Published: Jan 16, 2023 License: MIT Imports: 6 Imported by: 0



Package calculations implements various finance equations used in the rest of the package.

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.




View Source
const (
	PeriodsPerYear = 252.0


This section is empty.


func AnnualizeRisk

func AnnualizeRisk(risk, periodsPerYear float64) float64

func AnnualizedArithmeticReturn

func AnnualizedArithmeticReturn(returnValues []float64) float64

AnnualizedArithmeticReturn must receive at least 2 returns otherwise it returns 0

func AnnualizedTimeWeightedReturn

func AnnualizedTimeWeightedReturn(returnValues []float64, periods float64) float64

func CorrelationMatrix

func CorrelationMatrix(values [][]float64) *mat.Dense

func DenseMatrixToFloatSlices

func DenseMatrixToFloatSlices(dense *mat.Dense) [][]float64

func ExpectedRisk

func ExpectedRisk(risks, weights []float64, correlations *mat.Dense) float64

func HoldingPeriodReturns

func HoldingPeriodReturns(quotes []float64) []float64

HoldingPeriodReturns calculates the holding period returns between the given quotes The Return's Time field remains the zero value.

func NumberOfBets

func NumberOfBets(weightedAverageRisk float64, portfolioRisk float64) (float64, error)

func Risk

func Risk(risks, weights []float64, correlations [][]float64) (float64, error)

func RiskFromRiskContribution

func RiskFromRiskContribution(risks, weights []float64, correlations *mat.Dense) (float64, []float64, []float64)

func RiskFromStdDev

func RiskFromStdDev(values []float64) float64
risk := RiskFromStdDev([]float64{-0.1, 0.1, -0.1, 0.1, -0.1, 0.1, -0.1, 0.1})
fmt.Printf("%.2f", risk)


func TimeWeightedReturn

func TimeWeightedReturn(returns []float64) float64

func WeightedAverageRisk

func WeightedAverageRisk(weights, risks []float64) float64


This section is empty.

Jump to

Keyboard shortcuts

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