Libraryless. Click here for Pure Java version (142L/1K).
persistable sclass RegularPriceCells is PriceCells { // cell size settable double interval; // one of the cell limits settable double base; *(double *interval) {} *(double *base, double *interval) {} double remainder(double price) { ret mod(price-base, interval); } // TODO: not sure if this logic has rounding problems public bool isCellLimit(double price) { ret remainder(price) == 0; } public double nextCellLimit(double price) { double r = remainder(price); ret price+interval-r; } public double previousCellLimit(double price) { double r = remainder(price); ret price-(r == 0 ? interval : r); } public double nCellLimitsDown(double price, int n) { ret previousCellLimit(price)-(n-1)*interval; } public double nCellLimitsUp(double price, int n) { ret nextCellLimit(price)+n*interval; } public double priceToCellNumber(double price) { ret (price-base)/interval; } public double cellNumberToPrice(double cellNumber) { ret cellNumber*interval+base; } }
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1036206 |
Snippet name: | RegularPriceCells - infinitely many price cells at linear intervals |
Eternal ID of this version: | #1036206/10 |
Text MD5: | 7aeafdbc54ac7361d11d986d1a67907f |
Transpilation MD5: | 52b5cae8b9ae4585f5d59af91f034edc |
Author: | stefan |
Category: | javax / trading |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-10-26 02:40:12 |
Source code size: | 1117 bytes / 46 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 143 / 247 |
Version history: | 9 change(s) |
Referenced in: | #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167) #1036214 - GeometricPriceCells - infinitely many price cells at a constant ratio between adjacent prices |