Libraryless. Click here for Pure Java version (10779L/60K).
1 | persistable sclass LivePullbackToProfitAnalysis {
|
2 | settable double pullbackLimit = 1.0; |
3 | settable double adversity = 0.2; |
4 | settable boolean isShort; |
5 | settable long startTime; |
6 | settable double openingPrice; |
7 | settable double crest = 0; |
8 | settable double maxPullback; |
9 | settable L<PullbackToProfit> ptpList; |
10 | |
11 | double priceToProfit(double price) {
|
12 | var profit = asPercentIncrease(price, openingPrice()); |
13 | if (isShort()) profit = neg(profit); |
14 | ret profit-adversity(); |
15 | } |
16 | |
17 | void add aka feed(PricePoint pp) {
|
18 | if (startTime == 0) {
|
19 | startTime(pp.time()); |
20 | openingPrice(pp.price()); |
21 | ptpList(new L); |
22 | } |
23 | |
24 | var price = pp.price(); |
25 | var time = pp.time(); |
26 | var profit = priceToProfit(price); |
27 | |
28 | crest = max(crest, profit); |
29 | var pullback = crest-profit; |
30 | maxPullback = max(maxPullback, pullback); |
31 | |
32 | if (done()) ret; |
33 | |
34 | var result = new PullbackToProfit().pullback(maxPullback).profit(crest-maxPullback); |
35 | |
36 | var prev = last(ptpList); |
37 | if (prev != null) |
38 | if (prev.replaces(result)) |
39 | ret; |
40 | else if (result.replaces(prev)) |
41 | popLast(ptpList); |
42 | |
43 | ptpList.add(result |
44 | .isShort(isShort) |
45 | .timestamp(time) |
46 | .startTime(startTime())); |
47 | } |
48 | |
49 | /*double cleanness() {
|
50 | ret ptp == null ? 0 : ptp.cleanness(); |
51 | } |
52 | |
53 | double profit() {
|
54 | ret ptp == null ? negativeInfinity() : ptp.profit(); |
55 | }*/ |
56 | |
57 | bool done() {
|
58 | ret maxPullback >= pullbackLimit(); |
59 | } |
60 | |
61 | toString {
|
62 | ret startTime == 0 ? "Unstarted PTP analysis" : joinWithComma(ptpList); |
63 | } |
64 | |
65 | double maxCleanness() {
|
66 | ret doubleMax(map(ptpList(), ptp -> ptp.cleanness()); |
67 | } |
68 | |
69 | PullbackToProfit cleanestPTP() {
|
70 | ret highestBy(ptpList(), ptp -> ptp.cleanness()); |
71 | } |
72 | } |
Began life as a copy of #1036515
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): mqqgnosmbjvj, wnsclhtenguj
No comments. add comment
| Snippet ID: | #1036519 |
| Snippet name: | LivePullbackToProfitAnalysis |
| Eternal ID of this version: | #1036519/9 |
| Text MD5: | b4ac65bbe1e338ea6441c36178bc67b2 |
| Transpilation MD5: | 6f455482771afb8e717f58f4d116f7fa |
| Author: | stefan |
| Category: | javax / trading |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2023-01-22 17:05:23 |
| Source code size: | 1848 bytes / 72 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 670 / 850 |
| Version history: | 8 change(s) |
| Referenced in: | [show references] |