Documentation ¶
Index ¶
- Variables
- func ArithmeticMean(values []float64) (float64, error)
- func CalculateAmountWithFee(amount, fee float64) float64
- func CalculateFee(amount, fee float64) float64
- func CalculateNetProfit(amount, priceThen, priceNow, costs float64) float64
- func CalculatePercentageDifference(amount, secondAmount float64) float64
- func CalculatePercentageGainOrLoss(priceNow, priceThen float64) float64
- func CalmarRatio(highestPrice, lowestPrice, average, riskFreeRateForPeriod float64) (float64, error)
- func CompoundAnnualGrowthRate(openValue, closeValue, intervalsPerYear, numberOfIntervals float64) (float64, error)
- func DecimalArithmeticMean(values []decimal.Decimal) (decimal.Decimal, error)
- func DecimalCalmarRatio(highestPrice, lowestPrice, average, riskFreeRateForPeriod decimal.Decimal) (decimal.Decimal, error)
- func DecimalCompoundAnnualGrowthRate(openValue, closeValue, intervalsPerYear, numberOfIntervals decimal.Decimal) (decimal.Decimal, error)
- func DecimalFinancialGeometricMean(values []decimal.Decimal) (decimal.Decimal, error)
- func DecimalGeometricMean(values []decimal.Decimal) (decimal.Decimal, error)
- func DecimalInformationRatio(returnsRates, benchmarkRates []decimal.Decimal, ...) (decimal.Decimal, error)
- func DecimalPopulationStandardDeviation(values []decimal.Decimal) (decimal.Decimal, error)
- func DecimalPow(x, y decimal.Decimal) decimal.Decimal
- func DecimalSampleStandardDeviation(values []decimal.Decimal) (decimal.Decimal, error)
- func DecimalSharpeRatio(movementPerCandle []decimal.Decimal, ...) (decimal.Decimal, error)
- func DecimalSortinoRatio(movementPerCandle []decimal.Decimal, ...) (decimal.Decimal, error)
- func FinancialGeometricMean(values []float64) (float64, error)
- func GeometricMean(values []float64) (float64, error)
- func InformationRatio(returnsRates, benchmarkRates []float64, ...) (float64, error)
- func PopulationStandardDeviation(values []float64) (float64, error)
- func RoundFloat(x float64, prec int) float64
- func SampleStandardDeviation(values []float64) (float64, error)
- func SharpeRatio(movementPerCandle []float64, riskFreeRatePerInterval, average float64) (float64, error)
- func SortinoRatio(movementPerCandle []float64, riskFreeRatePerInterval, average float64) (float64, error)
Constants ¶
This section is empty.
Variables ¶
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") // ErrPowerDifferenceTooSmall when values are too close when calculating the exponent value, // it returns zero ErrPowerDifferenceTooSmall = errors.New("calculated power is too small to use") )
Functions ¶
func ArithmeticMean ¶
ArithmeticMean is the basic form of calculating an average. Divide the sum of all values by the length of values
func CalculateAmountWithFee ¶
CalculateAmountWithFee returns a calculated fee included amount on fee
func CalculateFee ¶
CalculateFee returns a simple fee on amount
func CalculateNetProfit ¶
CalculateNetProfit returns net profit
func CalculatePercentageDifference ¶
CalculatePercentageDifference returns the percentage of difference between multiple time periods
func CalculatePercentageGainOrLoss ¶
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 ¶
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 ¶
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 ¶
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 ¶
DecimalPopulationStandardDeviation calculates standard deviation using population based calculation
func DecimalPow ¶
DecimalPow is lovely because shopspring decimal cannot handle ^0.x and instead returns 1
func DecimalSampleStandardDeviation ¶
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 ¶
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 ¶
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 ¶
PopulationStandardDeviation calculates standard deviation using population based calculation
func RoundFloat ¶
RoundFloat rounds your floating point number to the desired decimal place
func SampleStandardDeviation ¶
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
Types ¶
This section is empty.