Here you can find the source of getProfit(BigDecimal ask, BigDecimal bid, BigDecimal fee)
Parameter | Description |
---|---|
ask | The ask price |
bid | The bid price |
fee | The fee P = (A/B) * (1-F)^2 - 1 Where: A = Ask F = Fees B = Bid |
public static BigDecimal getProfit(BigDecimal ask, BigDecimal bid, BigDecimal fee)
//package com.java2s; //License from project: Open Source License import java.math.BigDecimal; import java.math.RoundingMode; public class Main { /**//from w w w. ja v a 2 s.c om * 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; } }