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 PullbackToProfit ptp; |
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 | } |
22 | |
23 | var price = pp.price(); |
24 | var time = pp.time(); |
25 | var profit = priceToProfit(price); |
26 | |
27 | crest = max(crest, profit); |
28 | var pullback = crest-profit; |
29 | maxPullback = max(maxPullback, pullback); |
30 | |
31 | if (done()) ret; |
32 | |
33 | var result = new PullbackToProfit().pullback(maxPullback).profit(crest-maxPullback); |
34 | |
35 | if (ptp == null || !ptp.replaces(result)) |
36 | ptp(result |
37 | .isShort(isShort) |
38 | .timestamp(time) |
39 | .startTime(startTime())); |
40 | } |
41 | |
42 | double cleanness() { |
43 | ret ptp == null ? 0 : ptp.cleanness(); |
44 | } |
45 | |
46 | double profit() { |
47 | ret ptp == null ? negativeInfinity() : ptp.profit(); |
48 | } |
49 | |
50 | bool done() { |
51 | ret maxPullback >= pullbackLimit(); |
52 | } |
53 | |
54 | toString { ret ptp == null ? "Unstarted PTP analysis" : str(ptp); } |
55 | } |
Began life as a copy of #1036519
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): elmgxqgtpvxh, mqqgnosmbjvj, wnsclhtenguj
No comments. add comment
Snippet ID: | #1036526 |
Snippet name: | LivePullbackToProfitAnalysis (backup with single PTP) |
Eternal ID of this version: | #1036526/1 |
Text MD5: | e242a57c4d4be891928318b4cf0c6267 |
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:02:05 |
Source code size: | 1463 bytes / 55 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 159 / 166 |
Referenced in: | [show references] |