Here you can find the source of isProfitable(BigDecimal ask, BigDecimal bid, BigDecimal fee, BigDecimal minProfit)
Parameter | Description |
---|---|
ask | The ask price |
bid | The bid price |
fee | The fees charged in the bid and ask |
minProfit | Minimum desired profit |
public static boolean isProfitable(BigDecimal ask, BigDecimal bid, BigDecimal fee, BigDecimal minProfit)
//package com.java2s; //License from project: Open Source License import java.math.BigDecimal; import java.math.RoundingMode; public class Main { /***/* w w w .j a va 2s . c o m*/ * Returns if a combined bid/ask operation is profitable for the specified fees and desired profit * @param ask The ask price * @param bid The bid price * @param fee The fees charged in the bid and ask * @param minProfit Minimum desired profit * @return */ public static boolean isProfitable(BigDecimal ask, BigDecimal bid, BigDecimal fee, BigDecimal minProfit) { BigDecimal profit = getProfit(ask, bid, fee); boolean result = profit.compareTo(minProfit) >= 0; return result; } /** * Get the profit of an operation from its ask/bid and fees values * @param ask The ask price * @param bid The bid price * @param fee The fee * * * P = (A/B) * (1-F)^2 - 1 * * Where: * * A = Ask * F = Fees * B = Bid * * @return */ public static BigDecimal getProfit(BigDecimal ask, BigDecimal bid, BigDecimal fee) { BigDecimal one = new BigDecimal(1); BigDecimal oneMinusFee = one.subtract(fee); BigDecimal omfPow = oneMinusFee.multiply(oneMinusFee); BigDecimal profit = ask.divide(bid, 8, RoundingMode.FLOOR) .multiply(omfPow).subtract(one); return profit; } }