Sizing Geometric Grid Orders to Target a Weighted Average Entry Price
Summary
The document describes a way to size orders across a geometric price grid so that the average execution price approaches a chosen target. It starts with equally sized orders, whose average price differs from the target, then adjusts each order’s weight linearly by its position in the grid. A single adjustment factor is calculated from the difference between the equal-weight average and the target, scaled by the price-weighted order positions.
The example applies this method to ten prices between 100 and 200 and targets an average entry price of 135. The resulting weights decrease from the lowest price level to the highest and produce the stated target when used in a weighted average. The response supplies pseudocode rather than tested implementation, and it does not show how to convert the weights into quote-currency amounts under the stated budget. Users would also need to check that adjusted weights remain nonnegative and meet exchange order constraints for different inputs.
Key ideas
- A geometric progression can distribute grid prices evenly in percentage terms across a range.
- Equal order sizes may produce an average execution price different from the desired target.
- Linearly changing weights by grid position can shift the weighted average toward a specified price.
- The example uses decreasing weights across higher price levels to target an average of 135.
- The pseudocode does not translate weights into funded order amounts or handle all possible inputs.
Tags
Full text
# Generate grid for orders
# Generate grid for orders
I want to build some function that will generate a grid of orders with some conditions. I want to generate 10 orders with a base asset price of 100 to 200. I'm using geometric progression for it
```
minPrice = 100
maxPrice = 200
orders = 10
k = (maxPrice/minPrice) ** (1/ (orders-1))
prices = [minPrice]
for i in range (orders-1):
minPrice = minPrice * k
prices.append(minPrice)
print([round(price,2) for price in prices])
>>> [100, 108.01, 116.65, 125.99, 136.08, 146.97, 158.74, 171.45, 185.17, 200.0]
```
I have a limit of quote currency - $1000.
So for now I need to define the base/quote amount for each price level. My purpose that after all limit orders filled my entry price need to be around 135. I need some common algo that would work with any price range and orders amount and put my entry price on 35% in min/max price range.
## Answer by nbbo2 (score 3)
https://quant.stackexchange.com/a/65840
I will write some pseudocode.
```
N = 10 /* number of orders */
prices = [100, 108.01, 116.65, 125.99, 136.08, 146.97, 158.74, 171.45, 185.17, 200.0] /* these are the given prices */
ones = [1,1,1,1,1,1,1,1,1,1] /* N ones */
staircase = [0,1,2,3,4,5,6,7,8,9] /* starts at 0 and counts up by 1 until N-1 */
desired_avg_price = 135
avg_price_eqweighted = AVERAGE(prices) /* average price when all orders are of size 1 */
print(avg_price_eqweighted) => 144.906...
trial = SUMPRODUCT(prices, staircase)/N /* average with staircase as weights */
print(trial) => 743.24
delta = (desired_avg_price-avg_price_eqweighted)/trial
print(delta) => -0.013328131
weights = ones+delta*staircase
print(weights) => [1.0000, 0.9867 ,0.9733, 0.9600, 0.9467, 0.9334, 0.9200, 0.9067, 0.8934, 0.8800]
```
It is a bit clumsy but it does the job. It needs to be rewritten in proper Python and tested.
```
print(SUMPRODUCT(prices,weights)/N) => 135
```Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.