SLTradingAggregation.sleela
lib/advantage/trading/SLTradingAggregation.sleela · 97 line(s) · sleela
<< lib/advantage/trading/SLTradingAggregation.sleela
SLeeLa Standard Library Definition.
Definition: Fragmented supply aggregation: collect many small items into a cohesive set
and sell the set at a premium, pricing the chance it never completes. >>
#sleela 3.0
material;
artifact;
pure;
gasoline;
< Model 5 of the trading subject. An incomplete set sells for little more than >
< its parts, so completion probability is the key input. Digital: sorted coin >
< sets. Physical: matched dining chairs. Up to 256 items. >
class SLTradingAggregation {
< ---- 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 = 39006;
String metaAuthor = "Kiro Agent";
String metaDate = "2026-11-11";
String metaCopyright = "SLeeLa project";
String metaTrademark = "none";
String metaCorporation = "none";
< metaOrigin: National | <nation> | International | Galactic >
String metaOrigin = "International";
String metaBirthDate = "2026-11-11";
< metaScienceRating: maturity/robustness on a 1..10 scale >
int metaScienceRating = 6;
< metaNationalSchedule: a real, citable instrument or "none" >
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; }
< ---- shared validation, created on first use ---- >
SLTradingCheck chk;
SLTradingCheck check() {
if (chk == null) { chk = new SLTradingCheck(); }
return chk;
}
<< lotPrices holds the acquisition price of each of n items (1 to 256). The
set sells at setValue with probability completionProbability; otherwise
each item sells alone at piecemealValuePerItem. >>
SLTradingResult evaluate(double setValue, double piecemealValuePerItem,
double completionProbability, double perItemCost,
double fixedCosts, double sellFeeRate,
double holdingCostPerDay, double holdDays,
double[] lotPrices, int n) {
SLTradingCheck c = check();
if (n < 1 || n > c.maxLots()) { return c.fail(c.countMessage()); }
if (c.isAmount(setValue) == false) { return c.fail(c.rangeMessage()); }
if (c.isAmount(piecemealValuePerItem) == false) { return c.fail(c.rangeMessage()); }
if (c.isProb(completionProbability) == false) { return c.fail(c.rangeMessage()); }
if (c.isAmount(perItemCost) == false) { return c.fail(c.rangeMessage()); }
if (c.isAmount(fixedCosts) == false) { return c.fail(c.rangeMessage()); }
if (c.isRate(sellFeeRate) == false) { return c.fail(c.rangeMessage()); }
if (c.isAmount(holdingCostPerDay) == false) { return c.fail(c.rangeMessage()); }
if (c.isDays(holdDays) == false) { return c.fail(c.rangeMessage()); }
double purchases = 0.0;
int i = 0;
while (i < n) {
if (c.isPositive(lotPrices[i]) == false) { return c.fail(c.rangeMessage()); }
purchases = purchases + lotPrices[i];
i = i + 1;
}
double cost = purchases + n * perItemCost + fixedCosts
+ holdingCostPerDay * holdDays;
double expectedSale = completionProbability * setValue
+ (1.0 - completionProbability) * n * piecemealValuePerItem;
return c.finish(cost, expectedSale * (1.0 - sellFeeRate), holdDays);
}
}