math

package
v0.0.0-...-83dca6d Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoNegativeResults is returned when no negative results are allowed
	ErrNoNegativeResults = errors.New("cannot calculate with no negative values")
	// ErrInexactConversion is returned when a decimal does not convert to float exactly
	ErrInexactConversion = errors.New("inexact conversion from decimal to float detected")
)

Functions

func ArithmeticMean

func ArithmeticMean(values []float64) (float64, error)

ArithmeticMean is the basic form of calculating an average. Divide the sum of all values by the length of values

func CalculateAmountWithFee

func CalculateAmountWithFee(amount, fee float64) float64

CalculateAmountWithFee returns a calculated fee included amount on fee

func CalculateFee

func CalculateFee(amount, fee float64) float64

CalculateFee returns a simple fee on amount

func CalculateNetProfit

func CalculateNetProfit(amount, priceThen, priceNow, costs float64) float64

CalculateNetProfit returns net profit

func CalculatePercentageDifference

func CalculatePercentageDifference(amount, secondAmount float64) float64

CalculatePercentageDifference returns the percentage of difference between multiple time periods

func CalculatePercentageGainOrLoss

func CalculatePercentageGainOrLoss(priceNow, priceThen float64) float64

CalculatePercentageGainOrLoss returns the percentage rise over a certain period

func CalmarRatio

func CalmarRatio(highestPrice, lowestPrice, average, riskFreeRateForPeriod float64) (float64, error)

CalmarRatio is a function of the average compounded annual rate of return versus its maximum drawdown. The higher the Calmar ratio, the better it performed on a risk-adjusted basis during the given time frame, which is mostly commonly set at 36 months

func CompoundAnnualGrowthRate

func CompoundAnnualGrowthRate(openValue, closeValue, intervalsPerYear, numberOfIntervals float64) (float64, error)

CompoundAnnualGrowthRate Calculates CAGR. Using years, intervals per year would be 1 and number of intervals would be the number of years Using days, intervals per year would be 365 and number of intervals would be the number of days

func DecimalArithmeticMean

func DecimalArithmeticMean(values []decimal.Decimal) (decimal.Decimal, error)

DecimalArithmeticMean is the basic form of calculating an average. Divide the sum of all values by the length of values

func DecimalCalmarRatio

func DecimalCalmarRatio(highestPrice, lowestPrice, average, riskFreeRateForPeriod decimal.Decimal) (decimal.Decimal, error)

DecimalCalmarRatio is a function of the average compounded annual rate of return versus its maximum drawdown. The higher the Calmar ratio, the better it performed on a risk-adjusted basis during the given time frame, which is mostly commonly set at 36 months

func DecimalCompoundAnnualGrowthRate

func DecimalCompoundAnnualGrowthRate(openValue, closeValue, intervalsPerYear, numberOfIntervals decimal.Decimal) (decimal.Decimal, error)

DecimalCompoundAnnualGrowthRate Calculates CAGR. Using years, intervals per year would be 1 and number of intervals would be the number of years Using days, intervals per year would be 365 and number of intervals would be the number of days

func DecimalFinancialGeometricMean

func DecimalFinancialGeometricMean(values []decimal.Decimal) (decimal.Decimal, error)

DecimalFinancialGeometricMean is a modified geometric average to assess the negative returns of investments. It accepts It adds +1 to each This does impact the final figures as it is modifying values It is still ultimately calculating a geometric average which should only be compared to other financial geometric averages

func DecimalGeometricMean

func DecimalGeometricMean(values []decimal.Decimal) (decimal.Decimal, error)

DecimalGeometricMean is an average which indicates the central tendency or typical value of a set of numbers by using the product of their values The geometric average can only process positive numbers

func DecimalInformationRatio

func DecimalInformationRatio(returnsRates, benchmarkRates []decimal.Decimal, averageValues, averageComparison decimal.Decimal) (decimal.Decimal, error)

DecimalInformationRatio The information ratio (IR) is a measurement of portfolio returns beyond the returns of a benchmark, usually an index, compared to the volatility of those returns. The benchmark used is typically an index that represents the market or a particular sector or industry.

func DecimalPopulationStandardDeviation

func DecimalPopulationStandardDeviation(values []decimal.Decimal) (decimal.Decimal, error)

DecimalPopulationStandardDeviation calculates standard deviation using population based calculation

func DecimalPow

func DecimalPow(x, y decimal.Decimal) decimal.Decimal

DecimalPow is lovely because shopspring decimal cannot handle ^0.x and instead returns 1

func DecimalSampleStandardDeviation

func DecimalSampleStandardDeviation(values []decimal.Decimal) (decimal.Decimal, error)

DecimalSampleStandardDeviation standard deviation is a statistic that measures the dispersion of a dataset relative to its mean and is calculated as the square root of the variance

func DecimalSharpeRatio

func DecimalSharpeRatio(movementPerCandle []decimal.Decimal, riskFreeRatePerInterval, average decimal.Decimal) (decimal.Decimal, error)

DecimalSharpeRatio returns sharpe ratio of backtest compared to risk-free

func DecimalSortinoRatio

func DecimalSortinoRatio(movementPerCandle []decimal.Decimal, riskFreeRatePerInterval, average decimal.Decimal) (decimal.Decimal, error)

DecimalSortinoRatio returns sortino ratio of backtest compared to risk-free

func FinancialGeometricMean

func FinancialGeometricMean(values []float64) (float64, error)

FinancialGeometricMean is a modified geometric average to assess the negative returns of investments. It accepts It adds +1 to each This does impact the final figures as it is modifying values It is still ultimately calculating a geometric average which should only be compared to other financial geometric averages

func GeometricMean

func GeometricMean(values []float64) (float64, error)

GeometricMean is an average which indicates the central tendency or typical value of a set of numbers by using the product of their values The geometric average can only process positive numbers

func InformationRatio

func InformationRatio(returnsRates, benchmarkRates []float64, averageValues, averageComparison float64) (float64, error)

InformationRatio The information ratio (IR) is a measurement of portfolio returns beyond the returns of a benchmark, usually an index, compared to the volatility of those returns. The benchmark used is typically an index that represents the market or a particular sector or industry.

func PopulationStandardDeviation

func PopulationStandardDeviation(values []float64) (float64, error)

PopulationStandardDeviation calculates standard deviation using population based calculation

func RoundFloat

func RoundFloat(x float64, prec int) float64

RoundFloat rounds your floating point number to the desired decimal place

func SampleStandardDeviation

func SampleStandardDeviation(values []float64) (float64, error)

SampleStandardDeviation standard deviation is a statistic that measures the dispersion of a dataset relative to its mean and is calculated as the square root of the variance

func SharpeRatio

func SharpeRatio(movementPerCandle []float64, riskFreeRatePerInterval, average float64) (float64, error)

SharpeRatio returns sharpe ratio of backtest compared to risk-free

func SortinoRatio

func SortinoRatio(movementPerCandle []float64, riskFreeRatePerInterval, average float64) (float64, error)

SortinoRatio returns sortino ratio of backtest compared to risk-free

Types

This section is empty.

Jump to

Keyboard shortcuts

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