Documentation ¶
Overview ¶
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.
Index ¶
- Constants
- func AnnualizeRisk(risk, periodsPerYear float64) float64
- func AnnualizedArithmeticReturn(returnValues []float64) float64
- func AnnualizedTimeWeightedReturn(returnValues []float64, periods float64) float64
- func CorrelationMatrix(values [][]float64) *mat.Dense
- func DenseMatrixToFloatSlices(dense *mat.Dense) [][]float64
- func ExpectedRisk(risks, weights []float64, correlations *mat.Dense) float64
- func HoldingPeriodReturns(quotes []float64) []float64
- func NumberOfBets(weightedAverageRisk float64, portfolioRisk float64) (float64, error)
- func Risk(risks, weights []float64, correlations [][]float64) (float64, error)
- func RiskFromRiskContribution(risks, weights []float64, correlations *mat.Dense) (float64, []float64, []float64)
- func RiskFromStdDev(values []float64) float64
- func TimeWeightedReturn(returns []float64) float64
- func WeightedAverageRisk(weights, risks []float64) float64
Examples ¶
Constants ¶
const (
PeriodsPerYear = 252.0
)
Variables ¶
This section is empty.
Functions ¶
func AnnualizeRisk ¶
func AnnualizedArithmeticReturn ¶
AnnualizedArithmeticReturn must receive at least 2 returns otherwise it returns 0
func CorrelationMatrix ¶
func HoldingPeriodReturns ¶
HoldingPeriodReturns calculates the holding period returns between the given quotes The Return's Time field remains the zero value.
func NumberOfBets ¶
func RiskFromStdDev ¶
Example ¶
risk := RiskFromStdDev([]float64{-0.1, 0.1, -0.1, 0.1, -0.1, 0.1, -0.1, 0.1}) fmt.Printf("%.2f", risk)
Output: 0.11
func TimeWeightedReturn ¶
func WeightedAverageRisk ¶
Types ¶
This section is empty.