Home /Modules/advantage/SLTradingCounsel.sleela

SLTradingCounsel.sleela

lib/advantage/trading/SLTradingCounsel.sleela · 134 line(s) · sleela

<< lib/advantage/trading/SLTradingCounsel.sleela
   SLeeLa Standard Library Definition.
   Definition: Counsel over trading approaches: ranks approaches best-first by their honest
   score and reports the cautions that go with each. >>
#sleela 3.0
material;
artifact;
pure;
gasoline;
< Ranks up to 64 SLTradingApproach entries by mean advantage x confidence x >
< trust, deterministically (ties keep insertion order). >
class SLTradingCounsel {
  < ---- 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 = 39015;
  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 = 7;
  < 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; }


  << ---- the approaches being compared ----
     The array holds custom-class elements, so every method that calls through
     an element binds it to a typed local first. >>
  SLTradingApproach[] items;
  int count = 0;

  void init() {
    items = new SLTradingApproach[64];
    count = 0;
  }

  int size() { return count; }

  boolean add(SLTradingApproach a) {
    if (count >= 64) { return false; }
    items[count] = a;
    count = count + 1;
    return true;
  }

  SLTradingApproach at(int i) {
    SLTradingApproach a = items[i];
    return a;
  }

  << Positions best-first by score. Ties keep insertion order (a stable
     selection), so the ranking is deterministic. The result array holds
     indexes into the approaches; only the first size() entries are meaningful. >>
  int[] rank(double prior) {
    double[] sc = new double[64];
    int[] used = new int[64];
    int[] order = new int[64];
    < new array elements start as null, not zero, so initialise them first >
    int z = 0;
    while (z < 64) {
      sc[z] = 0.0;
      used[z] = 0;
      order[z] = 0;
      z = z + 1;
    }
    int i = 0;
    while (i < count) {
      SLTradingApproach a = items[i];
      sc[i] = a.score(prior);
      i = i + 1;
    }
    int pos = 0;
    while (pos < count) {
      int best = -1;
      int j = 0;
      while (j < count) {
        if (used[j] == 0) {
          if (best < 0) {
            best = j;
          } else {
            if (sc[j] > sc[best]) { best = j; }
          }
        }
        j = j + 1;
      }
      order[pos] = best;
      used[best] = 1;
      pos = pos + 1;
    }
    return order;
  }

  < One ranked line for a position in the order returned by rank(). >
  String line(int position, int[] order, double prior) {
    SLTradingApproach a = items[order[position]];
    return (position + 1) + ". " + a.describe(prior);
  }

  String cautionsFor(int position, int[] order, double prior, int minEvidence) {
    SLTradingApproach a = items[order[position]];
    return a.cautions(prior, minEvidence);
  }
}