Skip to content

Commit 29c2abb

Browse files
[REFACTOR] epsilon added in rebalancing
1 parent e160dd2 commit 29c2abb

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ build :
2222

2323
doc:
2424
@echo "Generating godoc documentation..."
25-
@godoc -http=:6060 &
25+
@go doc -http=:6060

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/quick-trade/xoney
22

3-
go 1.21.6
3+
go 1.22.0

test/toolkit/rebalancer_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func CurrentWeights(portfolio common.BaseDistribution) toolkit.PortfolioWeights
5454
weights[currency] = toolkit.BaseWeight(amount / totalCapital)
5555
}
5656

57-
dist, err := toolkit.NewPortfolioWeights(weights)
57+
dist, err := toolkit.NewPortfolioWeights(weights, 0)
5858
if err != nil {
5959
panic(err)
6060
}
@@ -246,7 +246,7 @@ func TestRebalanceMarketOrders(t *testing.T) {
246246
}
247247

248248
// Create new PortfolioWeights with desired weights
249-
portfolioWeights, err := toolkit.NewPortfolioWeights(desiredWeights)
249+
portfolioWeights, err := toolkit.NewPortfolioWeights(desiredWeights, 0)
250250
if err != nil {
251251
t.Fatalf("Error creating portfolio weights: %v", err)
252252
}

toolkit/grid.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ type GridGenerator interface {
227227
Next(candle data.Candle) ([]GridLevel, error) // new levels can be nil
228228
}
229229

230-
type GridBot struct {
230+
type GridBot struct { // TODO: debug
231231
grid grid
232232
strategy GridGenerator
233233
instrument data.Instrument

toolkit/rebalancer.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ type (
1919
PortfolioWeights map[data.Currency]BaseWeight
2020
)
2121

22-
func NewPortfolioWeights(distribution map[data.Currency]BaseWeight) (*PortfolioWeights, error) {
22+
func NewPortfolioWeights(distribution map[data.Currency]BaseWeight, epsilon float64) (*PortfolioWeights, error) {
2323
weights := PortfolioWeights(distribution)
24-
if err := weights.isValid(); err != nil {
24+
if err := weights.isValid(epsilon); err != nil {
2525
return nil, err
2626
}
2727
return &weights, nil
2828
}
2929

30-
func (f PortfolioWeights) isValid() error {
30+
func (f PortfolioWeights) isValid(epsilon float64) error {
3131
sumWeights := 0.0
3232

3333
for _, weight := range f {
3434
sumWeights += math.Abs(float64(weight))
3535
}
3636

37-
if sumWeights != 1 {
37+
if math.Abs(sumWeights-1) > epsilon {
3838
return errors.NewInvalidWeightsError(sumWeights)
3939
}
4040

0 commit comments

Comments
 (0)