Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

55
LINES

< > BotCompany Repo | #1036256 // Trading Strategy Include (old)

JavaX fragment (include)

1  
  double unrealizedProfit() {
2  
    double sum = 0;
3  
    for (p : openPositions())
4  
      sum += p.profit();
5  
    ret sum;
6  
  }
7  
  
8  
  double openMargins() {
9  
    double sum = 0;
10  
    for (p : openPositions())
11  
      sum += p.margin();
12  
    ret sum;
13  
  }
14  
  
15  
  double unrealizedCoinProfit() {
16  
    double sum = 0;
17  
    for (p : openPositions)
18  
      sum += p.coinProfit();
19  
    ret sum;
20  
  }
21  
  
22  
  L<Position> positionsInDirection(int direction) {
23  
    ret filter(openPositions, p -> p.direction == direction);
24  
  }
25  
  
26  
  L<Position> longPositions() { ret positionsInDirection(1); }
27  
  L<Position> shortPositions() { ret positionsInDirection(-1); }
28  
  
29  
  L<Position> shortPositionsAtOrBelowPrice(double openingPrice) {
30  
    ret filter(openPositions, p -> p.isShort() && p.openingPrice <= openingPrice);
31  
  }
32  
  
33  
  L<Position> longPositionsAtOrAbovePrice(double openingPrice) {
34  
    ret filter(openPositions, p -> p.isLong() && p.openingPrice >= openingPrice);
35  
  }
36  
  
37  
  L<Position> negativePositions() {
38  
    ret filter(openPositions, p -> p.profit() < 0);
39  
  }
40  
  
41  
  double debt() {
42  
    ret max(0, -unrealizedCoinProfit());
43  
  }
44  
  
45  
  double profit() {
46  
    ret realizedProfit+unrealizedProfit();
47  
  }
48  
  
49  
  double coinProfit() {
50  
    ret realizedCoinProfit+unrealizedCoinProfit();
51  
  }
52  
  
53  
  S formatProfit(double x) {
54  
    ret plusMinusFix(formatDouble1(x));
55  
  }

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mqqgnosmbjvj, wnsclhtenguj

No comments. add comment

Snippet ID: #1036256
Snippet name: Trading Strategy Include (old)
Eternal ID of this version: #1036256/2
Text MD5: 4cb3b929802d3053c3f4bcc7c20db145
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-11-05 20:13:46
Source code size: 1383 bytes / 55 lines
Pitched / IR pitched: No / No
Views / Downloads: 58 / 69
Version history: 1 change(s)
Referenced in: [show references]