Skip to content

Commit b7fc0a0

Browse files
committed
fix calculation of middle between old and new stock in buying price formula
1 parent 18545d0 commit b7fc0a0

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/towns/ware-prices/buying-price.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ where \\(w\_i\\) is the amount being bought from \\(i\\) and \\(f\\) is defined
2323
\\[
2424
\begin{aligned}
2525
f\_4 &= 0.6\\\\
26-
f_{i} &= m_i - v_i \underbrace{\frac{w\_{relative\\_stock} - w\_{relative\\_remain}}{2 * \text{interval_width}}}\_{\in [0; 1]}
26+
f_{i} &= m_i - v_i \underbrace{\frac{w\_{relative\\_stock} + w\_{relative\\_remain}}{2 * \text{interval_width}}}\_{\in [0; 1]}
2727
\end{aligned}
2828
\\]
2929

src/towns/ware-prices/selling-price.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,21 @@ def tests():
156156
price = get_price(stock, sell_amount, SAMPLE_THRESHOLDS, PIG_IRON_BASE_PRICE, 2)
157157
assert price == pytest.approx(1566.400097608566)
158158

159+
stock = 0
160+
sell_amount = 50 * 2000
161+
price = get_price(stock, sell_amount, SAMPLE_THRESHOLDS, PIG_IRON_BASE_PRICE, 0)
162+
assert price == pytest.approx(47740.00297486782)
163+
159164
stock = 0
160165
sell_amount = 50 * 2000
161166
price = get_price(stock, sell_amount, SAMPLE_THRESHOLDS, PIG_IRON_BASE_PRICE, 1)
162167
assert price == pytest.approx(46860.00292003155)
163168

169+
stock = 0
170+
sell_amount = 50 * 2000
171+
price = get_price(stock, sell_amount, SAMPLE_THRESHOLDS, PIG_IRON_BASE_PRICE, 2)
172+
assert price == pytest.approx(45980.00286519527)
173+
164174
stock = 17000
165175
sell_amount = 1 * 2000
166176
price = get_price(stock, sell_amount, SAMPLE_THRESHOLDS, PIG_IRON_BASE_PRICE, 1)

0 commit comments

Comments
 (0)