Warning: session_start(): open(/var/lib/php/sessions/sess_8suu8ph0g2nkvhkklgo1ufkj31, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
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 L ptpList;
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());
ptpList(new L);
}
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);
var prev = last(ptpList);
if (prev != null)
if (prev.replaces(result))
ret;
else if (result.replaces(prev))
popLast(ptpList);
ptpList.add(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 startTime == 0 ? "Unstarted PTP analysis" : joinWithComma(ptp); }
double maxCleanness() {
run();
ret doubleMax(map(ptpList(), ptp -> ptp.cleanness());
}
PullbackToProfit cleanestPTP() {
run();
ret highestBy(ptpList(), ptp -> ptp.cleanness());
}
}