1
1
package mtgban
2
2
3
3
import (
4
+ "math"
4
5
"strconv"
5
6
"strings"
6
7
@@ -72,6 +73,10 @@ type ArbitOpts struct {
72
73
// It returns a custom factor to be applied on the buylist price,
73
74
// and whether the entry shoul be skipped
74
75
CustomCardFilter func (co * mtgmatcher.CardObject ) (float64 , bool )
76
+
77
+ // Constant used to offset prices (the higher the value, the less impactful
78
+ // lower prices will be)
79
+ ProfitabilityConstant float64
75
80
}
76
81
77
82
type ArbitEntry struct {
@@ -98,13 +103,18 @@ type ArbitEntry struct {
98
103
99
104
// Amount of cards that can be applied
100
105
Quantity int
106
+
107
+ // The higher the number the better the arbit is. Using this formula
108
+ // Profitability Index (PI) = (Difference / (Sell Price + 10)) * log(1 + Spread) * sqrt(Units)
109
+ Profitability float64
101
110
}
102
111
103
112
func Arbit (opts * ArbitOpts , vendor Vendor , seller Seller ) (result []ArbitEntry , err error ) {
104
113
minDiff := 0.0
105
114
minSpread := 0.0
106
115
useTrades := false
107
116
rate := 1.0
117
+ profitabilityConstant := 10.0
108
118
109
119
minPrice := 0.0
110
120
minBuyPrice := 0.0
@@ -134,6 +144,9 @@ func Arbit(opts *ArbitOpts, vendor Vendor, seller Seller) (result []ArbitEntry,
134
144
if opts .Rate != 0 {
135
145
rate = opts .Rate
136
146
}
147
+ if opts .ProfitabilityConstant > 0 {
148
+ profitabilityConstant = opts .ProfitabilityConstant
149
+ }
137
150
useTrades = opts .UseTrades
138
151
139
152
minPrice = opts .MinPrice
@@ -306,6 +319,11 @@ func Arbit(opts *ArbitOpts, vendor Vendor, seller Seller) (result []ArbitEntry,
306
319
}
307
320
}
308
321
322
+ profitability := (difference / (price + profitabilityConstant )) * math .Log (1 + spread )
323
+ if qty > 1 {
324
+ profitability *= math .Sqrt (float64 (qty ))
325
+ }
326
+
309
327
res := ArbitEntry {
310
328
CardId : cardId ,
311
329
BuylistEntry : blEntry ,
@@ -314,6 +332,7 @@ func Arbit(opts *ArbitOpts, vendor Vendor, seller Seller) (result []ArbitEntry,
314
332
AbsoluteDifference : difference * float64 (qty ),
315
333
Spread : spread ,
316
334
Quantity : qty ,
335
+ Profitability : profitability ,
317
336
}
318
337
result = append (result , res )
319
338
}
@@ -417,6 +436,7 @@ func Mismatch(opts *ArbitOpts, reference Seller, probe Seller) (result []ArbitEn
417
436
maxSpread := 0.0
418
437
minPrice := 0.0
419
438
minQty := 0
439
+ profitabilityConstant := 10.0
420
440
filterFoil := false
421
441
filterOnlyFoil := false
422
442
filterRLOnly := false
@@ -434,6 +454,9 @@ func Mismatch(opts *ArbitOpts, reference Seller, probe Seller) (result []ArbitEn
434
454
if opts .MinSpread != 0 {
435
455
minSpread = opts .MinSpread
436
456
}
457
+ if opts .ProfitabilityConstant > 0 {
458
+ profitabilityConstant = opts .ProfitabilityConstant
459
+ }
437
460
438
461
minPrice = opts .MinPrice
439
462
maxSpread = opts .MaxSpread
@@ -559,13 +582,19 @@ func Mismatch(opts *ArbitOpts, reference Seller, probe Seller) (result []ArbitEn
559
582
}
560
583
}
561
584
585
+ profitability := (difference / (price + profitabilityConstant )) * math .Log (1 + spread )
586
+ if qty > 1 {
587
+ profitability *= math .Sqrt (float64 (qty ))
588
+ }
589
+
562
590
res := ArbitEntry {
563
591
CardId : cardId ,
564
592
InventoryEntry : invEntry ,
565
593
ReferenceEntry : refEntry ,
566
594
Difference : difference ,
567
595
Spread : spread ,
568
596
Quantity : qty ,
597
+ Profitability : profitability ,
569
598
}
570
599
result = append (result , res )
571
600
}
0 commit comments