mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-06 07:26:47 +00:00
CI: Fix golangci-lint linter issues, add prealloc linter and bump version depends for Go 1.18 (#915)
* Bump CI versions * Specifically set go version as 1.17.x bumps it to 1.18 * Another * Adjust AppVeyor * Part 1 of linter issues * Part 2 * Fix various linters and improvements * Part 3 * Finishing touches * Tests and EqualFold * Fix nitterinos plus bonus requester jobs bump for exchanges with large number of tests * Fix nitterinos and bump golangci-lint timeout for AppVeyor * Address nits, ensure all books are returned on err due to syncer regression * Fix the wiggins * Fix duplication * Fix nitterinos
This commit is contained in:
@@ -89,9 +89,9 @@ func InformationRatio(returnsRates, benchmarkRates []float64, averageValues, ave
|
||||
if len(benchmarkRates) != len(returnsRates) {
|
||||
return 0, errInformationBadLength
|
||||
}
|
||||
var diffs []float64
|
||||
diffs := make([]float64, len(returnsRates))
|
||||
for i := range returnsRates {
|
||||
diffs = append(diffs, returnsRates[i]-benchmarkRates[i])
|
||||
diffs[i] = returnsRates[i] - benchmarkRates[i]
|
||||
}
|
||||
stdDev, err := PopulationStandardDeviation(diffs)
|
||||
if err != nil {
|
||||
@@ -135,11 +135,11 @@ func SampleStandardDeviation(values []float64) (float64, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
var superMean []float64
|
||||
superMean := make([]float64, len(values))
|
||||
var combined float64
|
||||
for i := range values {
|
||||
result := math.Pow(values[i]-mean, 2)
|
||||
superMean = append(superMean, result)
|
||||
superMean[i] = result
|
||||
combined += result
|
||||
}
|
||||
avg := combined / (float64(len(superMean)) - 1)
|
||||
@@ -232,9 +232,9 @@ func SharpeRatio(movementPerCandle []float64, riskFreeRatePerInterval, average f
|
||||
if totalIntervals == 0 {
|
||||
return 0, errZeroValue
|
||||
}
|
||||
var excessReturns []float64
|
||||
excessReturns := make([]float64, len(movementPerCandle))
|
||||
for i := range movementPerCandle {
|
||||
excessReturns = append(excessReturns, movementPerCandle[i]-riskFreeRatePerInterval)
|
||||
excessReturns[i] = movementPerCandle[i] - riskFreeRatePerInterval
|
||||
}
|
||||
standardDeviation, err := PopulationStandardDeviation(excessReturns)
|
||||
if err != nil {
|
||||
@@ -284,9 +284,9 @@ func DecimalInformationRatio(returnsRates, benchmarkRates []decimal.Decimal, ave
|
||||
if len(benchmarkRates) != len(returnsRates) {
|
||||
return decimal.Zero, errInformationBadLength
|
||||
}
|
||||
var diffs []decimal.Decimal
|
||||
diffs := make([]decimal.Decimal, len(returnsRates))
|
||||
for i := range returnsRates {
|
||||
diffs = append(diffs, returnsRates[i].Sub(benchmarkRates[i]))
|
||||
diffs[i] = returnsRates[i].Sub(benchmarkRates[i])
|
||||
}
|
||||
stdDev, err := DecimalPopulationStandardDeviation(diffs)
|
||||
if err != nil && !errors.Is(err, ErrInexactConversion) {
|
||||
@@ -339,11 +339,11 @@ func DecimalSampleStandardDeviation(values []decimal.Decimal) (decimal.Decimal,
|
||||
if err != nil {
|
||||
return decimal.Zero, err
|
||||
}
|
||||
var superMean []decimal.Decimal
|
||||
superMean := make([]decimal.Decimal, len(values))
|
||||
var combined decimal.Decimal
|
||||
for i := range values {
|
||||
pow := values[i].Sub(mean).Pow(decimal.NewFromInt(2))
|
||||
superMean = append(superMean, pow)
|
||||
superMean[i] = pow
|
||||
combined.Add(pow)
|
||||
}
|
||||
avg := combined.Div(decimal.NewFromInt(int64(len(superMean))).Sub(decimal.NewFromInt(1)))
|
||||
@@ -380,9 +380,7 @@ func DecimalGeometricMean(values []decimal.Decimal) (decimal.Decimal, error) {
|
||||
// DecimalPow is lovely because shopspring decimal cannot
|
||||
// handle ^0.x and instead returns 1
|
||||
func DecimalPow(x, y decimal.Decimal) decimal.Decimal {
|
||||
fX, _ := x.Float64()
|
||||
fY, _ := y.Float64()
|
||||
pow := math.Pow(fX, fY)
|
||||
pow := math.Pow(x.InexactFloat64(), y.InexactFloat64())
|
||||
return decimal.NewFromFloat(pow)
|
||||
}
|
||||
|
||||
@@ -405,7 +403,7 @@ func DecimalFinancialGeometricMean(values []decimal.Decimal) (decimal.Decimal, e
|
||||
// as we cannot have negative or zero value geometric numbers
|
||||
// adding a 1 to the percentage movements allows for differentiation between
|
||||
// negative numbers (eg -0.1 translates to 0.9) and positive numbers (eg 0.1 becomes 1.1)
|
||||
modVal, _ := values[i].Add(decimal.NewFromInt(1)).Float64()
|
||||
modVal := values[i].Add(decimal.NewFromInt(1)).InexactFloat64()
|
||||
product *= modVal
|
||||
}
|
||||
prod := 1 / float64(len(values))
|
||||
@@ -461,9 +459,9 @@ func DecimalSharpeRatio(movementPerCandle []decimal.Decimal, riskFreeRatePerInte
|
||||
if totalIntervals.IsZero() {
|
||||
return decimal.Zero, errZeroValue
|
||||
}
|
||||
var excessReturns []decimal.Decimal
|
||||
excessReturns := make([]decimal.Decimal, len(movementPerCandle))
|
||||
for i := range movementPerCandle {
|
||||
excessReturns = append(excessReturns, movementPerCandle[i].Sub(riskFreeRatePerInterval))
|
||||
excessReturns[i] = movementPerCandle[i].Sub(riskFreeRatePerInterval)
|
||||
}
|
||||
standardDeviation, err := DecimalPopulationStandardDeviation(excessReturns)
|
||||
if err != nil && !errors.Is(err, ErrInexactConversion) {
|
||||
|
||||
@@ -184,9 +184,9 @@ func TestInformationRatio(t *testing.T) {
|
||||
t.Error(avgComparison)
|
||||
}
|
||||
|
||||
var eachDiff []float64
|
||||
eachDiff := make([]float64, len(figures))
|
||||
for i := range figures {
|
||||
eachDiff = append(eachDiff, figures[i]-comparisonFigures[i])
|
||||
eachDiff[i] = figures[i] - comparisonFigures[i]
|
||||
}
|
||||
stdDev, err := PopulationStandardDeviation(eachDiff)
|
||||
if err != nil {
|
||||
@@ -583,9 +583,9 @@ func TestDecimalInformationRatio(t *testing.T) {
|
||||
t.Error(avgComparison)
|
||||
}
|
||||
|
||||
var eachDiff []decimal.Decimal
|
||||
eachDiff := make([]decimal.Decimal, len(figures))
|
||||
for i := range figures {
|
||||
eachDiff = append(eachDiff, figures[i].Sub(comparisonFigures[i]))
|
||||
eachDiff[i] = figures[i].Sub(comparisonFigures[i])
|
||||
}
|
||||
stdDev, err := DecimalPopulationStandardDeviation(eachDiff)
|
||||
if err != nil && !errors.Is(err, ErrInexactConversion) {
|
||||
@@ -703,14 +703,13 @@ func TestDecimalStandardDeviation2(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
var superMean []decimal.Decimal
|
||||
superMean := make([]decimal.Decimal, len(r))
|
||||
for i := range r {
|
||||
result := r[i].Sub(mean).Pow(decimal.NewFromInt(2))
|
||||
superMean = append(superMean, result)
|
||||
superMean[i] = result
|
||||
}
|
||||
superMeany := superMean[0].Add(superMean[1].Add(superMean[2].Add(superMean[3].Add(superMean[4].Add(superMean[5]))))).Div(decimal.NewFromInt(5))
|
||||
fSuperMeany, _ := superMeany.Float64()
|
||||
manualCalculation := decimal.NewFromFloat(math.Sqrt(fSuperMeany))
|
||||
manualCalculation := decimal.NewFromFloat(math.Sqrt(superMeany.InexactFloat64()))
|
||||
var codeCalcu decimal.Decimal
|
||||
codeCalcu, err = DecimalSampleStandardDeviation(r)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user