SLTradingRegional.sleela
lib/advantage/trading/SLTradingRegional.sleela · 107 line(s) · sleela
<< lib/advantage/trading/SLTradingRegional.sleela
SLeeLa Standard Library Definition.
Definition: Regional and geofenced arbitrage: buy in one place, move it, sell in another,
pricing the chance the move fails or damages the goods. >>
#sleela 3.0
material;
artifact;
pure;
gasoline;
< Model 4 of the trading subject. The edge is spatial; the friction is the >
< move. Digital: a country-exclusive premium. Physical: estate-sale furniture >
< sold in a dense urban market. >
class SLTradingRegional {
< ---- 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 = 39005;
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;
}
< Regional premium = sell / buy - 1 (0.05 means a 5 percent premium). >
< Check pricesOk first: premium returns -2.0 for invalid prices, and a real >
< premium can never be below -1. >
boolean pricesOk(double buyPrice, double sellPrice) {
SLTradingCheck c = check();
return c.isPositive(buyPrice) && c.isPositive(sellPrice);
}
double premium(double buyPrice, double sellPrice) {
if (pricesOk(buyPrice, sellPrice) == false) { return -2.0; }
return sellPrice / buyPrice - 1.0;
}
<< Buy where cheap, move it, sell where dear. The move can fail or damage
the goods: lossProbability is the chance of that, and salvageRate is the
fraction of the buy value recovered if it happens. >>
SLTradingResult evaluate(double buyPrice, double sellPrice, double quantity,
double buyFeeRate, double sellFeeRate,
double transportCostPerUnit, double fixedCosts,
double holdingCostPerDay, double transitDays,
double lossProbability, double salvageRate) {
SLTradingCheck c = check();
if (c.isPositive(buyPrice) == false) { return c.fail(c.rangeMessage()); }
if (c.isPositive(sellPrice) == false) { return c.fail(c.rangeMessage()); }
if (c.isPositive(quantity) == false) { return c.fail(c.rangeMessage()); }
if (c.isRate(buyFeeRate) == false) { return c.fail(c.rangeMessage()); }
if (c.isRate(sellFeeRate) == false) { return c.fail(c.rangeMessage()); }
if (c.isAmount(transportCostPerUnit) == false) { return c.fail(c.rangeMessage()); }
if (c.isAmount(fixedCosts) == false) { return c.fail(c.rangeMessage()); }
if (c.isAmount(holdingCostPerDay) == false) { return c.fail(c.rangeMessage()); }
if (c.isDays(transitDays) == false) { return c.fail(c.rangeMessage()); }
if (c.isProb(lossProbability) == false) { return c.fail(c.rangeMessage()); }
if (c.isProb(salvageRate) == false) { return c.fail(c.rangeMessage()); }
double cost = quantity * buyPrice * (1.0 + buyFeeRate)
+ quantity * transportCostPerUnit + fixedCosts
+ holdingCostPerDay * transitDays;
double okProceeds = quantity * sellPrice * (1.0 - sellFeeRate);
double lostProceeds = quantity * buyPrice * salvageRate;
double proceeds = (1.0 - lossProbability) * okProceeds
+ lossProbability * lostProceeds;
return c.finish(cost, proceeds, transitDays);
}
}