From 035969eb57224a1a1c6400e2cb00f1249ea1133b Mon Sep 17 00:00:00 2001 From: Tom Harding Date: Mon, 1 Jan 2018 16:50:11 -0800 Subject: [PATCH] Weighted-target exponential moving average Add support for a new WTEMA DAA characterized by a single "alpha" parameter and no fixed window size. --- mining.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mining.py b/mining.py index a1a4956..3dee24a 100755 --- a/mining.py +++ b/mining.py @@ -89,6 +89,9 @@ def target_to_hex(target): states = [] +# This could be prettier if algorithms were classes +wtema_target = 0 + def print_headers(): print(', '.join(['Height', 'FX', 'Block Time', 'Unix', 'Timestamp', 'Difficulty (bn)', 'Implied Difficulty (bn)', @@ -278,6 +281,13 @@ def next_bits_wt_compare(msg, block_count): assert(next_bits == next_bits_py) return next_bits +def next_bits_wtema(msg, alpha_recip): + global wtema_target + block_time = states[-1].timestamp - states[-2].timestamp + target = bits_to_target(states[-1].bits) + weighted_target = target // IDEAL_BLOCK_TIME * block_time + wtema_target = weighted_target // alpha_recip + wtema_target // alpha_recip * (alpha_recip - 1) + return target_to_bits(wtema_target) def next_bits_dgw3(msg, block_count): ''' Dark Gravity Wave v3 from Dash ''' @@ -473,6 +483,9 @@ def next_step(algo, scenario, fx_jump_factor): }), 'ema-1d' : Algo(next_bits_ema, { 'window': 24 * 60 * 60, + }), + 'wtema-72' : Algo(next_bits_wtema, { + 'alpha_recip': 104, # floor(1/(1 - pow(.5, 1.0/72))), # half-life = 72 }) } @@ -490,7 +503,9 @@ def next_step(algo, scenario, fx_jump_factor): } def run_one_simul(algo, scenario, print_it): + global wtema_target states.clear() + wtema_target = bits_to_target(INITIAL_BCC_BITS) # Initial state is afer 2020 steady prefix blocks N = 2020