Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

42
LINES

< > BotCompany Repo | #1036227 // PriceDigitizer2

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (10586L/58K).

persistable srecord noeq PriceDigitizer2(PriceCells cells) {
  settable int cellNumber = Int.MIN_VALUE;
  settable int lastCellNumber = Int.MIN_VALUE;
  settable bool verbose;
  settable new UpDownSequence upDownSequence;
  
  // returns new digitized price
  double digitize(double price) {
    double cn = cells.toCellNumber(price);
    if (cellNumber == Int.MIN_VALUE) {
      cellNumber = lastCellNumber = iround(cn);
    } else {
      lastCellNumber = cellNumber;
      cellNumber = iroundTowardsWithOutwardEpsilon(cn, cellNumber, epsilon());
      
      // TODO: assuming there are only 1-steps
      if (cellNumber > lastCellNumber)
        upDownSequence?.addUp();
      else if (cellNumber < lastCellNumber)
        upDownSequence?.addDown();
    }
    ret digitizedPrice();
  }
  
  double epsilon() { ret 1e-4; }
  
  double digitizedPrice() { ret cells.fromCellNumber(cellNumber); }
  double lastDigitizedPrice() { ret cells.fromCellNumber(lastCellNumber); }
  
  // digitize price without looking at history
  double digitizeIndividually(double price) {
    double cn = cells.toCellNumber(price);
    ret cells.fromCellNumber(round(cn));
  }
  
  PriceCells priceCells() { ret cells; }
  
  // brave
  void swapPriceCells(PriceCells newPriceCells) {
    cells = newPriceCells;
  }
}

Author comment

Began life as a copy of #1036208

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1036227
Snippet name: PriceDigitizer2
Eternal ID of this version: #1036227/12
Text MD5: 5292a0a88a6e5bdae1d0e43ed5769ed3
Transpilation MD5: 6556963eac8366b30e188fbc7225379a
Author: stefan
Category: javax / trading
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-11-21 10:36:25
Source code size: 1338 bytes / 42 lines
Pitched / IR pitched: No / No
Views / Downloads: 47 / 105
Version history: 11 change(s)
Referenced in: [show references]