diff --git a/CHANGELOG.md b/CHANGELOG.md index dde36c5..483d4a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.4.0 +- Adds conditional cash recovery: minimum units that must sell at the observed listing price to recover acquisition outlay and one failed posting's estimated deposit on unsold units. Unsold stock is assigned no cash proceeds, not zero asset value. +- Unknown deposits remain unknown; listing quantity is not demand. + ## 0.3.4 - Rejects malformed, undated, future-dated and stale comparison records. - Estimated profit is conditional on selling the listed quantity; unknown deposits and buy quantities are labelled. diff --git a/NeutralFlip.lua b/NeutralFlip.lua index 46310dc..7c9300c 100644 --- a/NeutralFlip.lua +++ b/NeutralFlip.lua @@ -231,6 +231,25 @@ local function route(itemID, buy, sell, cut, from, to, now, bags) } end +-- Cash recovery scenario: unsold stock is assigned zero cash proceeds, not zero asset value. +-- Deposit is refundable on units sold; one failed posting per unsold unit. +function NF.CashScenario(o, sold) + if not o or not o.deposit or not o.qty or o.qty <= 0 or type(sold) ~= "number" or sold < 0 or sold > o.qty or sold ~= math.floor(sold) then return nil end + local capital = o.buy * o.qty + local lost = math.ceil(o.deposit * (o.qty - sold) / o.qty) + return sold * o.net - capital - lost +end + +function NF.RecoveryUnits(o) + if not o or not o.qty or o.qty <= 0 or not o.deposit then return nil end + local lo, hi = 0, o.qty + while lo < hi do + local mid = math.floor((lo + hi) / 2) + if NF.CashScenario(o, mid) >= 0 then hi = mid else lo = mid + 1 end + end + if NF.CashScenario(o, lo) >= 0 then return lo end +end + -- Both routes for one item (0, 1 or 2 entries). function NF.ItemRoutes(itemID, now, bags) local fac = playerFaction() @@ -272,6 +291,8 @@ function NF.FormatLine(i, o) local notes = { ("%s %s %s, %s %s %s"):format(NF.KindLabel(o.from), L["price"], ago(o.buyAge), NF.KindLabel(o.to), L["price"], ago(o.sellAge)) .. " " .. L["old"] } if not o.qtyKnown then notes[#notes + 1] = "quantity at lowest buy price unknown" end if o.deposit then notes[#notes + 1] = "deposit at risk " .. C.Money(o.deposit) else notes[#notes + 1] = "deposit unknown" end + local recovery = NF.RecoveryUnits(o) + if recovery then notes[#notes + 1] = ("cash recovery: sell %d/%d (one posting)"):format(recovery, o.qty) end if o.carried > 0 then notes[#notes + 1] = "you carry " .. o.carried end if o.thin then notes[#notes + 1] = "THIN MARKET: check by hand" end return s .. " [" .. table.concat(notes, ", ") .. "]" diff --git a/NeutralFlip.toc b/NeutralFlip.toc index d5bd47c..66d5244 100644 --- a/NeutralFlip.toc +++ b/NeutralFlip.toc @@ -2,7 +2,7 @@ ## Title: NeutralFlip ## Notes: Compares your faction AH with the neutral (Booty Bay / Gadgetzan / Everlook) AH and lists buys worth carrying across, after the 5%/15% cuts. You press every button. ## Author: Kenny -## Version: 0.3.4 +## Version: 0.4.0 ## SavedVariables: KennyNeutralFlipDB ## OptionalDeps: PriceLog, MatTooltip, LibDataBroker-1.1, TomTom ## X-License: MIT diff --git a/README.md b/README.md index 98a7107..23f29c2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@

NeutralFlip logo

-# NeutralFlip (WoW: Forever) v0.3.4 +# NeutralFlip (WoW: Forever) v0.4.0 + +The list includes conditional cash recovery when the deposit is known: how many units need to sell to recover acquisition outlay and one failed posting on unsold units. This is not a probability of sale. [![MasterRed](https://img.shields.io/badge/MasterRed-Play%20smarter%20%7C%20Know%20more-DB353A?labelColor=141416)](https://github.com/masterred92) ![Independent developer](https://img.shields.io/badge/Independent-Developer-E7E7EA?labelColor=141416) diff --git a/tests/test_neutralflip.lua b/tests/test_neutralflip.lua index 1b01e9a..d9ed231 100644 --- a/tests/test_neutralflip.lua +++ b/tests/test_neutralflip.lua @@ -52,6 +52,11 @@ check(o and o.deposit == math.floor(db.rates.neutral * 5 * 30), "deposit at risk -- Peacebloom: neutral 150 (qty unknown) vs home 200: list home at 199*0.95=189, profit 39 < minProfit 50 -> none for _, x in ipairs(list) do check(x.itemID ~= 2447, "small Peacebloom gap filtered") end check(not o.thin, "19x ratio not thin") +check(NF.CashScenario(o, 0) == -o.buy * o.qty - o.deposit, "zero sales cash exposure") +check(NF.CashScenario(o, o.qty) == o.total, "all sales recover deposit") +local recover = NF.RecoveryUnits(o) +check(recover and NF.CashScenario(o, recover) >= 0 and NF.CashScenario(o, recover - 1) < 0, "minimum cash recovery units") +check(NF.RecoveryUnits({qty = 3}) == nil, "unknown deposit stays unknown") local text = NF.ListText() check(text:find("BUY at Alliance AH") and text:find("LIST at neutral AH"), "list text: " .. text)