Home /Modules/advantage/SLBilateralNewsvendor.sleela

SLBilateralNewsvendor.sleela

lib/advantage/math/SLBilateralNewsvendor.sleela · 114 line(s) · sleela

<< lib/advantage/math/SLBilateralNewsvendor.sleela
   SLeeLa Standard Library Definition.
   Definition: Bilateral newsvendor -- overage/underage costs on both ends and
   the centralized critical ratio that avoids double marginalization. >>
#sleela 3.0
material;
artifact;
pure;
gasoline;
< Model 3 of the advantage trade subject. When the inventory faces uncertain >
< end-market demand but both parties' holding and shortage costs are >
< transparent, the profit curves are governed by overage and underage costs on >
< each side: >
<   Seller overage  c_o,S = cs - vs   (production cost minus seller salvage) >
<   Seller underage c_u,S = P  - cs   (wholesale price minus production cost) >
<   Buyer  overage  c_o,B = P  - vb   (wholesale price minus buyer salvage) >
<   Buyer  underage c_u,B = r  - P    (retail price minus wholesale price) >
< The CENTRALIZED critical ratio sets the system-wide service level F(Q*): >
<   F(Q*) = c_u,system / (c_u,system + c_o,system) >
<         = (r - cs) / ((r - cs) + (cs - vb)). >
< This is the Arrow-Harris-Marschak newsvendor result applied to the whole >
< channel, preventing "double marginalization" (both parties hedging separately >
< and restricting inventory too much). >
class SLBilateralNewsvendor {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
     or catalog can read and (where appropriate) override this record.
     Values are faithful to the subject's real origin where publicly known. >>
  String metaVersion = "1.0.0";
  int metaId = 10524;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-11-08";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  String metaBirthDate = "2026-11-08";
  int metaScienceRating = 8;
  << metaNationalSchedule: the newsvendor critical-ratio optimum is the
     Arrow-Harris-Marschak result (Econometrica 1951); an academic result,
     not a statute. >>
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }

  < ---- Per-side overage and underage costs ---- >
  double overageSeller(double cs, double vs)      { return cs - vs; }
  double underageSeller(double price, double cs)  { return price - cs; }
  double overageBuyer(double price, double vb)    { return price - vb; }
  double underageBuyer(double r, double price)    { return r - price; }

  << Centralized critical ratio -- the system-wide service level F(Q*):
       F(Q*) = (r - cs) / ((r - cs) + (cs - vb)).
     System underage r - cs is the full channel margin lost on a stockout;
     system overage cs - vb is the production cost unrecovered beyond buyer
     salvage. Clamped to [0,1]; 0 if the denominator is non-positive. >>
  double criticalRatio(double r, double cs, double vb) {
    double cu = r - cs;
    double co = cs - vb;
    double denom = cu + co;
    if (denom <= 0.0) { return 0.0; }
    double f = cu / denom;
    if (f < 0.0) { return 0.0; }
    if (f > 1.0) { return 1.0; }
    return f;
  }

  << A standalone buyer, facing only its OWN costs, targets
       F_B = (r - P) / ((r - P) + (P - vb)),
     which sits below the centralized F(Q*) -- that shortfall IS double
     marginalization. A buyback or revenue-sharing contract lifts F_B up to
     F(Q*). Returns the gap (>= 0 means the buyer under-orders and a
     coordinating contract is warranted). >>
  double coordinationGap(double r, double cs, double price, double vb) {
    double system = criticalRatio(r, cs, vb);
    double cuB = r - price;
    double coB = price - vb;
    double denomB = cuB + coB;
    double fb = 0.0;
    if (denomB > 0.0) { fb = cuB / denomB; }
    double gap = system - fb;
    if (gap < 0.0) { return 0.0; }
    return gap;
  }

  String describe(double r, double cs, double vb) {
    return "BilateralNewsvendor: F(Q*)=" + criticalRatio(r, cs, vb)
         + " (system underage=" + (r - cs) + " overage=" + (cs - vb) + ")";
  }
}