Java BigDecimal getProfit(BigDecimal ask, BigDecimal bid, BigDecimal fee)

Here you can find the source of getProfit(BigDecimal ask, BigDecimal bid, BigDecimal fee)

Description

Get the profit of an operation from its ask/bid and fees values

License

Open Source License

Parameter

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

Declaration

public static BigDecimal getProfit(BigDecimal ask, BigDecimal bid,
        BigDecimal fee) 

Method Source Code

//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;
    }
}

Related

  1. getNumberOfDecimalPlaces(BigDecimal bigDecimal)
  2. getParamBigDecimal(Map paramMap, String paramName)
  3. getPercent(BigDecimal numerator, BigDecimal denominator)
  4. getPercentage(BigDecimal amount, BigDecimal percent)
  5. getPercentageValue(BigDecimal price, double amount)
  6. getProzentWert(BigDecimal zahl, BigDecimal prozentsatz, int nachkommastellen)
  7. getRandomBigDecimal(BigDecimal a, BigDecimal b)
  8. getRandomBigDecimal(int maxValue, int scale)
  9. getRandomPriceChangeFactor(BigDecimal currentPrice)