Libraryless. Click here for Pure Java version (142L/1K).
1 | persistable sclass RegularPriceCells is PriceCells {
|
2 | // cell size |
3 | settable double interval; |
4 | |
5 | // one of the cell limits |
6 | settable double base; |
7 | |
8 | *(double *interval) {}
|
9 | *(double *base, double *interval) {}
|
10 | |
11 | double remainder(double price) {
|
12 | ret mod(price-base, interval); |
13 | } |
14 | |
15 | // TODO: not sure if this logic has rounding problems |
16 | |
17 | public bool isCellLimit(double price) {
|
18 | ret remainder(price) == 0; |
19 | } |
20 | |
21 | public double nextCellLimit(double price) {
|
22 | double r = remainder(price); |
23 | ret price+interval-r; |
24 | } |
25 | |
26 | public double previousCellLimit(double price) {
|
27 | double r = remainder(price); |
28 | ret price-(r == 0 ? interval : r); |
29 | } |
30 | |
31 | public double nCellLimitsDown(double price, int n) {
|
32 | ret previousCellLimit(price)-(n-1)*interval; |
33 | } |
34 | |
35 | public double nCellLimitsUp(double price, int n) {
|
36 | ret nextCellLimit(price)+n*interval; |
37 | } |
38 | |
39 | public double priceToCellNumber(double price) {
|
40 | ret (price-base)/interval; |
41 | } |
42 | |
43 | public double cellNumberToPrice(double cellNumber) {
|
44 | ret cellNumber*interval+base; |
45 | } |
46 | } |
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: | 691 / 869 |
| Version history: | 9 change(s) |
| Referenced in: | [show references] |