Libraryless. Click here for Pure Java version (10586L/58K).
1 | persistable srecord noeq PriceDigitizer2(PriceCells cells) { |
2 | settable int cellNumber = Int.MIN_VALUE; |
3 | settable int lastCellNumber = Int.MIN_VALUE; |
4 | settable bool verbose; |
5 | settable new UpDownSequence upDownSequence; |
6 | |
7 | // returns new digitized price |
8 | double digitize(double price) { |
9 | double cn = cells.toCellNumber(price); |
10 | if (cellNumber == Int.MIN_VALUE) { |
11 | cellNumber = lastCellNumber = iround(cn); |
12 | } else { |
13 | lastCellNumber = cellNumber; |
14 | cellNumber = iroundTowardsWithOutwardEpsilon(cn, cellNumber, epsilon()); |
15 | |
16 | // TODO: assuming there are only 1-steps |
17 | if (cellNumber > lastCellNumber) |
18 | upDownSequence?.addUp(); |
19 | else if (cellNumber < lastCellNumber) |
20 | upDownSequence?.addDown(); |
21 | } |
22 | ret digitizedPrice(); |
23 | } |
24 | |
25 | double epsilon() { ret 1e-4; } |
26 | |
27 | double digitizedPrice() { ret cells.fromCellNumber(cellNumber); } |
28 | double lastDigitizedPrice() { ret cells.fromCellNumber(lastCellNumber); } |
29 | |
30 | // digitize price without looking at history |
31 | double digitizeIndividually(double price) { |
32 | double cn = cells.toCellNumber(price); |
33 | ret cells.fromCellNumber(round(cn)); |
34 | } |
35 | |
36 | PriceCells priceCells() { ret cells; } |
37 | |
38 | // brave |
39 | void swapPriceCells(PriceCells newPriceCells) { |
40 | cells = newPriceCells; |
41 | } |
42 | } |
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: | 157 / 260 |
Version history: | 11 change(s) |
Referenced in: | [show references] |