収益率統計

作者: リン・ハーン春兄さん, 日付: 2016-08-01 00:29:26
タグ:ツール

統計的収益率

BotVSの収益統計は,曲線のみを記録する.技術分析を行うことはできません.このテンプレートは,最近1日,前1日,最近7日,前7日,最近30日,前30日,およびすべての時間の収益,収益率,月間収益率,年収率,最大引き戻し率を自動的に統計することができます.

使用方法: このテンプレートに導入し,元のポリシーを$.LogProfitに置き換える.そして,LogStatusの場所に $.ProfitSummary (初始資金) の返却文字列を追加する.

例えば: main ((() {という関数 {while (true) } {while (true) } {while (true) } {while (true) } {while (true) } {while (true) } 変数で変数で変数で変数で変数で $t.Last; $t.LogProfit (t.Last); $t.LogProfit (t.Last); $t.LogProfit (t.Last) について ログステータス (($.ProfitSummary ((10000)); スリープ (3600000) {cH00ffff} {cH00ffff}

画像を表示する

1日:收収-78.44元 ((-0.537%),月化-16.781%,年化-204.169%,撤収1.106% 前1日:収収176.08元 (※1.221%),月収38.226%,年収465.087%,引き上げ1.236% 7日:収収771.74元 ((5,599%),月化24.141%,年化293.719%,撤収1.517% 過去7日: 223.15元 (※1.64%),月額7.071%,年収86.039%,引き下げ0.9% 30日:収収1570.31元 ((12.094%),月化12.111%,年化147.352%,撤収3.251% 過去30日:収収200.12元 ((1.565%),月収1.567%,年収19.076%,撤収1.521% 総額: 4554.11元 ((45.541%),最大回収は3.251%,統計時間は74日23時間


$.LogProfit = function(profit) {
    var args = Array.prototype.slice.call(arguments);
    if (SYS_LOGPROFIT) {
        LogProfit.apply(this, args);
    } else {
        args.unshift('收益');
        Log.apply(this,args);
    }

    var _history = $.GetAllProfit();
    _history.push([ Math.floor(new Date().getTime()/1000), profit]);
    _G('profit_history', JSON.stringify(_history));
};

$.GetAllProfit = function() {
	var old = _G('profit_history') || '[]';
    try {
    	var _history = JSON.parse(old);
    	return _history;
    } catch(e) {
    	_G('profit_history', null);
    	return [];
    }
};

function filterProfit(from, to) {
	var arr = $.GetAllProfit();
	if (!arr || arr.length === 0) return;
	var re, maxdrawback=0, lastProfit=0, maxProfit=false, maxdrawbackProfit=0;
	var earlest, latest;
	for(var i=0;i<arr.length;i++) {
		if (!arr[i]) continue;
		if (arr[i][0] > from && arr[i][0] <= to) {
			var profit = arr[i][1];
			if (!earlest) earlest = arr[i];
			latest = arr[i];
			if (!lastProfit) lastProfit = profit;
			if (maxProfit === false || maxProfit < profit) maxProfit = profit;
			var drawback = maxProfit - profit;
			if (drawback > maxdrawback) {
				maxdrawback = drawback;
				maxdrawbackProfit = maxProfit;
			}
		}
	}
	if (!earlest || !latest) return;
	return [earlest, latest, maxdrawback, maxdrawbackProfit];
}

function daysProfit(offset, days) {
	var from = getDaySecond( -offset+days);
	var to = getDaySecond(-offset);
	var arr = filterProfit( from, to );
	if (!arr || !arr[0] || !arr[1]) return;
	var profitTime = arr[1][0] - arr[0][0];
	if (!profitTime) return;
	var periodTime = to - from;
	var profit = arr[1][1] - arr[0][1];
	var realPercent = profitTime*100 / periodTime;
	var expectedProfit = profit * 100 / realPercent;
	return {
		profit:profit, 
		expectedProfit:expectedProfit,
		profitTime:profitTime,
		periodTime:periodTime,
		open: arr[0][1],
		close: arr[1][1],
		drawback: arr[2],
		drawbackProfit: arr[3]
	};
}

function getDaySecond(days) {
	var d = new Date();
	var now = d.getTime();
	now -= days*86400000;
	d.setTime(now);
	return Math.floor(d.getTime() / 1000);
} 

$.DaysProfit = function(days) {
	return filterProfit(days)[2];
};

$.ProfitSummary = function(initialBalance) {
	if (!initialBalance) return '没有传入初始资金';

	var day = daysProfit(0, 1);
	var lastDay = daysProfit(-1, 1);
	var week = daysProfit(0,7);
	var lastWeek = daysProfit(-7,7);
	var month = daysProfit(0,30);
	var lastMonth = daysProfit(-30,30);
	var all = daysProfit(0, 10000);
	if (!all) return '';
	var _days = Math.floor(all.profitTime / 86400);

	var text = [];
	var t = profitSummary(day, initialBalance);
	if (t) text.push('1日: '+t);
	t = profitSummary(lastDay, initialBalance);
	if (t) text.push('上1日: '+t);
	t = profitSummary(week, initialBalance);
	if (t && _days >= 7) text.push('7日: '+t);
	t = profitSummary(lastWeek, initialBalance);
	if (t) text.push('上7日: '+t);
	t = profitSummary(month, initialBalance);
	if (t && _days>=30) text.push('30日: '+t);
	t = profitSummary(lastMonth, initialBalance);
	if (t) text.push('上30日: '+t);
	
	if (all) {
		var _days = Math.floor(all.profitTime / 86400);
		all.profitTime %= 86400;
		var _hours = Math.floor(all.profitTime / 3600);
		var drawback = _N( all.drawback*100/(all.drawbackProfit+initialBalance), 3 )+'%';
		text.push('总: 收'+_N(all.close,2)+'元('+_N(all.close*100/initialBalance,3)+'%),最大回撤'+drawback+',统计时间'+_days+'天'+_hours+'小时');
	}
	return text.join('\n');
};

function profitSummary(p, base) {
	if (!p) return '';
	var text = [];
	text.push('收'+_N(p.profit,2)+'元('+_N(p.profit*100/(base+p.open), 3)+'%)');
	var month = expectProfit(p, 30, base);
	if (month) {
		text.push('月化'+month.percent+'%');
	}
	var year = expectProfit(p, 365, base);
	if (year) {
		text.push('年化'+year.percent+'%');
	}
	text.push('回撤'+ _N( p.drawback*100/(p.drawbackProfit+base), 3 )+'%' );
	return text.join(',');
}


function expectProfit(p, days, base) {
	var expectSeconds = days*86400;
	if (expectSeconds < p.profitTime) return;
	return {
		profit: _N(p.profit * expectSeconds / p.profitTime, 2),
		percent: _N(p.profit * expectSeconds *100 / (p.profitTime * (base+p.open)),3)
	};
}

function main() {
    while(true) {
        var t = exchange.GetTicker();
        $.LogProfit(t.Last);
        LogStatus($.ProfitSummary(10000));
        Sleep(3600000);
    }
}

関連性

もっと

クンフェン91このテンプレートを使用すると,復元速度が遅い.

nxtプレーヤーありがとうございました.

ロガ連絡先を頼むか

イワックスありがとうございました.

モモックス支持