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 @@
