Documentation
¶
Overview ¶
Package calculate 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, periods float64) float64
- func AnnualizedTimeWeightedReturn(returnValues []float64, periods float64) float64
- func BetaToBenchmark(portfolio, benchmark []float64) float64
- func CalmarRatio(portfolio, riskFree []float64, maxDrawdown, periodsPerYear float64) float64
- func CorrelationMatrix(values [][]float64) [][]float64
- func DownsideVolatility(values []float64, periodsPerYear float64) float64
- func EqualInverseVolatilityWeights(ws []float64, vols []float64)
- func EqualRiskContributionWeights(ctx context.Context, ws []float64, vols []float64, correlations [][]float64) error
- func EqualVolatilityWeights(ws []float64, vols []float64)
- func EqualWeights(ws []float64)
- func HoldingPeriodReturns(quotes []float64) []float64
- func InformationRatio(portfolio, benchmark []float64, periodsPerYear float64) float64
- func InverseVarianceWeights(ws []float64, vols []float64)
- func MaxDrawdown(values []float64) (float64, int)
- func NumberOfBets(weightedAverageRisk float64, portfolioRisk float64) (float64, error)
- func PortfolioVolatility(weights, stdDevs []float64, correlations [][]float64) (float64, []float64)
- func RiskFromStdDev(values []float64) float64
- func RiskWeights(portfolioVol float64, riskContributions []float64) []float64
- func SharpeRatio(portfolioReturnValues, riskFreeReturnValues []float64, periods float64) float64
- func SortinoRatio(portfolio, riskFree []float64, downsideVol, periodsPerYear float64) float64
- func TimeWeightedReturn(returns []float64) float64
- func TrackingError(excessReturns []float64, periodsPerYear float64) float64
- func UlcerIndex(values []float64, periodsPerYear float64) float64
- func ValueAtRisk(values []float64, portfolioValue, confidenceLevel, periodsPerYear float64) float64
- func Variance(volatility 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 BetaToBenchmark ¶ added in v0.7.0
func CalmarRatio ¶ added in v0.7.0
func CorrelationMatrix ¶
func DownsideVolatility ¶ added in v0.7.0
func EqualVolatilityWeights ¶
func EqualWeights ¶
func EqualWeights(ws []float64)
func HoldingPeriodReturns ¶
HoldingPeriodReturns calculates the holding period returns between the given quotes The Return's Time field remains the zero value.
func InformationRatio ¶ added in v0.7.0
func InverseVarianceWeights ¶
func MaxDrawdown ¶ added in v0.7.0
func NumberOfBets ¶
func PortfolioVolatility ¶
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 RiskWeights ¶
func SharpeRatio ¶
func SortinoRatio ¶ added in v0.7.0
func TimeWeightedReturn ¶
func TrackingError ¶ added in v0.7.0
func UlcerIndex ¶ added in v0.7.0
func ValueAtRisk ¶ added in v0.7.0
func WeightedAverageRisk ¶
Types ¶
This section is empty.