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

55
LINES

< > BotCompany Repo | #1036526 // LivePullbackToProfitAnalysis (backup with single PTP)

JavaX fragment (include)

persistable sclass LivePullbackToProfitAnalysis {
  settable double pullbackLimit = 1.0;
  settable double adversity = 0.2;
  settable boolean isShort;
  settable long startTime;
  settable double openingPrice;
  settable double crest = 0;
  settable double maxPullback;
  settable PullbackToProfit ptp;
  
  double priceToProfit(double price) {
    var profit = asPercentIncrease(price, openingPrice());
    if (isShort()) profit = neg(profit);
    ret profit-adversity();
  }
  
  void add aka feed(PricePoint pp) {
    if (startTime == 0) {
      startTime(pp.time());
      openingPrice(pp.price());
    }
    
    var price = pp.price();
    var time = pp.time();
    var profit = priceToProfit(price);
            
    crest = max(crest, profit);
    var pullback = crest-profit;
    maxPullback = max(maxPullback, pullback);
      
    if (done()) ret;
      
    var result = new PullbackToProfit().pullback(maxPullback).profit(crest-maxPullback);
      
    if (ptp == null || !ptp.replaces(result))
      ptp(result
        .isShort(isShort)
        .timestamp(time)
        .startTime(startTime()));
  }
  
  double cleanness() {
    ret ptp == null ? 0 : ptp.cleanness();
  }
  
  double profit() {
    ret ptp == null ? negativeInfinity() : ptp.profit();
  }
  
  bool done() {
    ret maxPullback >= pullbackLimit();
  }
  
  toString { ret ptp == null ? "Unstarted PTP analysis" : str(ptp); }
}

Author comment

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: 158 / 165
Referenced in: