2021-10-23 12:42:55 +00:00
|
|
|
package com.alttd.objects;
|
|
|
|
|
|
|
|
|
|
import com.alttd.util.Utilities;
|
2021-12-17 19:44:38 +00:00
|
|
|
import org.apache.commons.math3.analysis.function.StepFunction;
|
|
|
|
|
import org.apache.commons.math3.analysis.integration.TrapezoidIntegrator;
|
2021-10-23 12:42:55 +00:00
|
|
|
|
2021-11-10 15:58:47 +00:00
|
|
|
public final class Price {
|
|
|
|
|
private final double price;
|
|
|
|
|
private final int points;
|
|
|
|
|
|
2021-12-23 22:00:59 +00:00
|
|
|
private static final double[] xMult = {Integer.MIN_VALUE, -4000, -2000, -500, 500, 2000, 4000};
|
|
|
|
|
private static final double[] yMultSell = {2.5, 1.75, 1.25, 1, 1.5, 2.5, 5};
|
|
|
|
|
private static final double[] yMultBuy = {5, 2.5, 1.5, 1, 1.25, 1.75, 2.5};
|
|
|
|
|
|
|
|
|
|
private static final StepFunction multiplierModelBuy = new StepFunction(xMult, yMultBuy);
|
|
|
|
|
private static final StepFunction multiplierModelSell = new StepFunction(xMult, yMultSell);
|
2021-12-17 19:44:38 +00:00
|
|
|
|
2021-11-10 15:58:47 +00:00
|
|
|
public Price(double price) {
|
|
|
|
|
this.price = price;
|
2021-12-21 02:18:06 +00:00
|
|
|
this.points = (int) price;
|
2021-11-10 15:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-23 12:42:55 +00:00
|
|
|
public static Price addPrice(Price one, Price two) {
|
2021-11-10 15:58:47 +00:00
|
|
|
return (new Price(Utilities.round(one.getPrice(1) + two.getPrice(1), 2)));
|
2021-10-23 12:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double getPrice(int multiplier) {
|
|
|
|
|
return (Utilities.round(price * multiplier, 2));
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-23 22:00:59 +00:00
|
|
|
public double calculatePriceThing(int oldPoints, int transPts, boolean buying) {
|
2021-12-17 19:44:38 +00:00
|
|
|
// Compute numerical integration to determine price
|
|
|
|
|
TrapezoidIntegrator trapez = new TrapezoidIntegrator();
|
2021-12-23 22:00:59 +00:00
|
|
|
if (buying) {
|
|
|
|
|
return (Utilities.round(price * trapez.integrate(10, multiplierModelBuy, oldPoints, oldPoints + transPts), 2));
|
|
|
|
|
} else {
|
|
|
|
|
return (Utilities.round(price * trapez.integrate(10, multiplierModelSell, oldPoints - transPts, oldPoints), 2));
|
|
|
|
|
}
|
2021-12-17 19:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
2021-11-08 19:28:25 +00:00
|
|
|
public int getPoints() {
|
|
|
|
|
return (points);
|
2021-10-23 12:42:55 +00:00
|
|
|
}
|
2021-11-10 15:58:47 +00:00
|
|
|
|
2021-10-23 12:42:55 +00:00
|
|
|
}
|