Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wtema-72 weighted-target exponential moving average #30

Merged
merged 1 commit into from
Jan 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions mining.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Expand Down Expand Up @@ -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 '''
Expand Down Expand Up @@ -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
})
}

Expand All @@ -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
Expand Down