Apama Capital Markets Foundation Documentation : Capital Markets Foundation : Market Data Management : Synthetic datasources : Price spreader/skewer : Calculating spread and skew prices
This section describes the formulas used to spread and skew incoming prices. The spreader can be used in two different modes of operation, Top of Book or VWAP.
Top of Book
To calculate using Top of the Book mode, follow these steps:
1. Check that the bid and ask price are not 0, if yes then the price and the quantity for both the sides is set to 0.
2. To spread direction towards bid:
a. Check whether bid and ask quantities are greater than the spreadMinQtyLimit. If either is not, the price and quantity for both the sides are set to 0, if both are greater than the spreadMinQtyLimit, the prices are spread.
spread bid price = mathUtil.subtract(bid price,
c. Check whether bid and ask quantities exceed spreadMaxQtyLimit. If yes, the exceeding quantity is set to the spreadMaxQuantityLimit parameter value.
3. To skew the prices towards bid:
skewed bid price = mathUtil.subtract(spread bid price,
*skew percentage /100)
*skew percentage /100)
a. Check whether bid and ask quantities are greater than the spreadMinQtyLimit. If either of them is not, the price and quantity for both the sides are set to 0, if both are greater than the spreadMinQtyLimit, the prices are spread.
c. Check that the bid and ask quantities do not exceed spreadMaxQtyLimit. If yes, the exceeding quantity is set to the spreadMaxQtyLimit parameter value.
5. To skew the prices towards bid:
6. Skew direction is set off:
a. Check whether bid and ask quantities are greater than the spreadMinQtyLimit. If either of them is not, the price and quantity for both the sides are set to 0, if both the quantities are greater than the spreadMinQtyLimit then the prices are spread.
b. Spread the price as following :
c. Check that the bid and ask quantities do not exceed spreadMaxQtyLimit. If they do, the exceeding quantity is set to the spreadMaxQtyLimit parameter value.
Bid price = spreaded Bid price -
Bid price = spreaded Bid price +
8. If the value of the parameter minBBASpread is not 0 then check that the applied spread to the bid and ask prices is appropriate.
Bid price = round(10.0.pow(-1.0 * decimalPlaces.toFloat()), true, Bid price)
Reverting Top of the Book
Reverting Prices from the Spreaded/Skewed Prices
Spread and/or skewed prices can be reverted back to original values using the parameters provided. The only mode which supports reverting the prices is Top of the Book and the prices cannot be reverted if either the bid or the ask price is 0.
The calculations are as follows:
1. Skew direction is towards bid :
unskewed bid price = mathUtil.add(skewed bid price, mathUtil.subtract
( skewed ask price, skewed bid price*skew percentage/100)
( skewed bid price, skewed ask price*skew percentage/100)
2. Skew direction is towards ask:
unskewed bid price = mathUtil.subtract(skewed bid price,
mathUtil.subtract(skewed ask price, skewed bid price)*
skew percentage/100)
mathUtil.subtract(skewed bid price,
Original bid price = mathUtil.add(unskewed bid price,
mathUtil.subtract(unskewed ask price, unskewed bid price) /
mathUtil.subtract (unskewed ask price, unskewed bid price) /
VWAP
1. Iterate over the bid side and keep a counter for the quantity and if the total quantity is less than the vwapVol then:
mathUtil.add (Total bid price, quantity.toFloat() * bid price)
When the total quantity becomes greater than the vwapVol, break the loop and the total bid price is calculated as:
mathUtil.subtract(quantity counter, VwapVol)).toFloat()*
bid price)
2. If the available liquidity for the bid side is less than the specified VWAP volume, the VWAP price and quantity is set to 0. Otherwise, the VWAP bid price is calculated as:
VWAP bid price = Total bid price / vwapVol.toFloat()
3. Iterate over the ask side and keep a counter for the quantity and if the total quantity is less than the vwapVol, then:
When the total quantity becomes greater than the vwapVol, break the loop and the total ask price is calculated as:
4. If the available liquidity for the ask side is less than the specified VWAP volume then the VWAP the price and quantity is set to 0 otherwise the VWAP ask price is calculated as:
5. Check that the bid and ask prices are not 0, if yes then the price and quantity for both the sides is set to 0.
6. Skew direction towards bid:
a. Check the bid and ask quantities are greater than the spreadMinQtyLimit. If either of them is not then the price and quantity for both the sides are set to 0, if both the quantities are greater than the spreadMinQtyLimit then the prices are spread.
b. Spread the prices as following :
spread bid price = mathUtil.subtract(bid price,
percentage/100)/2)
c. Check the bid and ask quantities do not exceed spreadMaxQtyLimit. If yes, the exceeding quantity is set to the spreadMaxQtyLimit parameter value.
7. Skew the prices towards bid:
Skewed bid price = mathUtil.subtract(spread bid price,
skew percentage / 100)
skew percentage / 100)
a. Check the bid and ask quantities are greater than the spreadMinQtyLimit. If either of them is not then the price and quantity for both the sides are set to 0, if both the quantities are greater than the spreadMinQtyLimit then the prices are spread.
b. Spread the price as following:
bid price, (mathUtil.subtract(ask price, bid price)
c. Check that the bid and ask quantities do not exceed spreadMaxQtyLimit. If yes, the exceeding quantity is set to the spreadMaxQtyLimit parameter value.
9. Skew the prices toward ask: