double unrealizedProfit() { double sum = 0; for (p : openPositions()) sum += p.profit(); ret sum; } double openMargins() { double sum = 0; for (p : openPositions()) sum += p.margin(); ret sum; } double unrealizedCoinProfit() { double sum = 0; for (p : openPositions) sum += p.coinProfit(); ret sum; } L<Position> positionsInDirection(int direction) { ret filter(openPositions, p -> p.direction == direction); } L<Position> longPositions() { ret positionsInDirection(1); } L<Position> shortPositions() { ret positionsInDirection(-1); } L<Position> shortPositionsAtOrBelowPrice(double openingPrice) { ret filter(openPositions, p -> p.isShort() && p.openingPrice <= openingPrice); } L<Position> longPositionsAtOrAbovePrice(double openingPrice) { ret filter(openPositions, p -> p.isLong() && p.openingPrice >= openingPrice); } L<Position> negativePositions() { ret filter(openPositions, p -> p.profit() < 0); } double debt() { ret max(0, -unrealizedCoinProfit()); } double profit() { ret realizedProfit+unrealizedProfit(); } double coinProfit() { ret realizedCoinProfit+unrealizedCoinProfit(); } S formatProfit(double x) { ret plusMinusFix(formatDouble1(x)); }
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: | 158 / 171 |
Version history: | 1 change(s) |
Referenced in: | -