This commit is contained in:
Markus 2018-12-13 14:22:33 -02:00
parent 437fd81f08
commit d9c1b50de9
13 changed files with 0 additions and 2888 deletions

View File

@ -1,220 +0,0 @@
from decimal import Decimal
import numpy as np
from datetime import timedelta
from SimCAD import configs
from SimCAD.configuration import Configuration
from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \
ep_time_step
seed = {
'z': np.random.RandomState(1)
}
# Signals
# Pr_signal
beta = Decimal('0.25') # agent response gain
beta_LT = Decimal('0.1') # LT agent response gain
alpha = Decimal('0.091') # 21 day EMA forgetfullness between 0 and 1, closer to 1 discounts older obs quicker, should be 2/(N+1)
max_withdraw_factor = Decimal('0.9')
external_draw = Decimal('0.01') # between 0 and 1 to draw Buy_Log to external
# Stochastic process factors
correction_factor = Decimal('0.01')
volatility = Decimal('5.0')
# Buy_Log_signal =
# Z_signal =
# Price_signal =
# TDR_draw_signal =
# P_Ext_Markets_signal =
# Behaviors per Mechanism
# BEHAVIOR 1: EMH Trader
EMH_portion = Decimal('0.250')
EMH_Ext_Hold = Decimal('42000.0')
def b1m1(step, sL, s):
print('b1m1')
theta = (s['Z']*EMH_portion*s['Price'])/(s['Z']*EMH_portion*s['Price'] + EMH_Ext_Hold * s['P_Ext_Markets'])
if s['Price'] < (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
buy = beta * theta*EMH_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EMH_portion*(1-theta))
return {'buy_order1': buy}
elif s['Price'] > (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
return {'buy_order1': 0}
else:
return {'buy_order1': 0}
def b1m2(step, sL, s):
print('b1m2')
theta = (s['Z']*EMH_portion*s['Price'])/(s['Z']*EMH_portion*s['Price'] + EMH_Ext_Hold * s['P_Ext_Markets'])
if s['Price'] < (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
return {'sell_order1': 0}
elif s['Price'] > (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
sell = beta * theta*EMH_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EMH_portion*(1-theta))
return {'sell_order1': sell}
else:
return {'sell_order1': 0}
# BEHAVIOR 3: Herding
# BEHAVIOR 4: HODLers
HODL_belief = Decimal('10.0')
HODL_portion = Decimal('0.250')
HODL_Ext_Hold = Decimal('4200.0')
def b4m2(step, sL, s):
print('b4m2')
theta = (s['Z']*HODL_portion*s['Price'])/(s['Z']*HODL_portion*s['Price'] + HODL_Ext_Hold * s['P_Ext_Markets'])
if s['Price'] < 1/HODL_belief*(theta*HODL_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*HODL_portion*(1-theta)):
sell = beta * theta*HODL_Ext_Hold * s['P_Ext_Markets']/(s['Price']*HODL_portion*(1-theta))
return {'sell_order2': sell}
elif s['Price'] > (theta*HODL_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*HODL_portion*(1-theta)):
return {'sell_order2': 0}
else:
return {'sell_order2': 0}
# STATES
# ZEUS Fixed Supply
def s1m1(step, sL, s, _input):
y = 'Z'
x = s['Z'] #+ _input # / Psignal_int
return (y, x)
def s2m1(step, sL, s, _input):
y = 'Price'
x = (s['P_Ext_Markets'] - _input['buy_order1']) / s['Z'] * 10000
#x= alpha * s['Z'] + (1 - alpha)*s['Price']
return (y, x)
def s3m1(step, sL, s, _input):
y = 'Buy_Log'
x = _input['buy_order1'] # / Psignal_int
return (y, x)
def s4m2(step, sL, s, _input):
y = 'Sell_Log'
x = _input['sell_order1'] + _input['sell_order2'] # / Psignal_int
return (y, x)
def s3m3(step, sL, s, _input):
y = 'Buy_Log'
x = s['Buy_Log'] + _input # / Psignal_int
return (y, x)
# Price Update
def s2m3(step, sL, s, _input):
y = 'Price'
#var1 = Decimal.from_float(s['Buy_Log'])
x = s['Price'] + s['Buy_Log'] * 1/s['Z'] - s['Sell_Log']/s['Z']
#+ np.divide(s['Buy_Log'],s['Z']) - np.divide() # / Psignal_int
return (y, x)
def s6m1(step, sL, s, _input):
y = 'P_Ext_Markets'
x = s['P_Ext_Markets'] - _input
#x= alpha * s['Z'] + (1 - alpha)*s['Price']
return (y, x)
def s2m2(step, sL, s, _input):
y = 'Price'
x = (s['P_Ext_Markets'] - _input) /s['Z'] *10000
#x= alpha * s['Z'] + (1 - alpha)*s['Price']
return (y, x)
# Exogenous States
proc_one_coef_A = -125
proc_one_coef_B = 125
# A change in belief of actual price, passed onto behaviors to make action
def es4p2(step, sL, s, _input):
y = 'P_Ext_Markets'
x = s['P_Ext_Markets'] + bound_norm_random(seed['z'], proc_one_coef_A, proc_one_coef_B)
return (y,x)
ts_format = '%Y-%m-%d %H:%M:%S'
t_delta = timedelta(days=0, minutes=0, seconds=1)
def es5p2(step, sL, s, _input):
y = 'timestamp'
x = ep_time_step(s, dt_str=s['timestamp'], fromat_str=ts_format, _timedelta=t_delta)
return (y, x)
#Environment States
# NONE
# Genesis States
state_dict = {
'Z': Decimal(21000000.0),
'Price': Decimal(100.0), # Initialize = Z for EMA
'Buy_Log': Decimal(0.0),
'Sell_Log': Decimal(0.0),
'Trans': Decimal(0.0),
'P_Ext_Markets': Decimal(25000.0),
'timestamp': '2018-10-01 15:16:24'
}
def env_proc_id(x):
return x
env_processes = {
# "P_Ext_Markets": env_proc_id
}
exogenous_states = exo_update_per_ts(
{
"P_Ext_Markets": es4p2,
"timestamp": es5p2
}
)
sim_config = {
"N": 1,
"T": range(1000)
}
# test return vs. non-return functions as lambdas
# test fully defined functions
mechanisms = {
"m1": {
"behaviors": {
"b1": b1m1
},
"states": {
"Z": s1m1,
"Buy_Log": s3m1
}
},
"m2": {
"behaviors": {
"b1": b1m2,
"b4": b4m2
},
"states": {
"Sell_Log": s4m2
}
},
"m3": {
"behaviors": {
},
"states": {
"Price": s2m3
}
}
}
configs.append(Configuration(sim_config, state_dict, seed, exogenous_states, env_processes, mechanisms))

View File

@ -1,247 +0,0 @@
from decimal import Decimal
import numpy as np
from datetime import timedelta
from SimCAD import configs
from SimCAD.configuration import Configuration
from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \
ep_time_step
seed = {
'z': np.random.RandomState(1)
}
# Signals
# Pr_signal
beta = Decimal('0.25') # agent response gain
beta_LT = Decimal('0.1') # LT agent response gain
# alpha = .67, 2 block moving average
alpha = Decimal('0.67') # 21 day EMA forgetfullness between 0 and 1, closer to 1 discounts older obs quicker, should be 2/(N+1)
max_withdraw_factor = Decimal('0.9')
external_draw = Decimal('0.01') # between 0 and 1 to draw Buy_Log to external
#alpha * s['Zeus_ST'] + (1 - alpha)*s['Zeus_LT']
# Stochastic process factors
correction_factor = Decimal('0.01')
volatility = Decimal('5.0')
# Buy_Log_signal =
# Z_signal =
# Price_signal =
# TDR_draw_signal =
# P_Ext_Markets_signal =
# Behaviors per Mechanism
# BEHAVIOR 1: EMH Trader
EMH_portion = Decimal('0.250')
EMH_Ext_Hold = Decimal('42000.0')
def b1m1(step, sL, s):
# print('b1m1')
theta = (s['Z']*EMH_portion*s['Price'])/(s['Z']*EMH_portion*s['Price'] + EMH_Ext_Hold * s['P_Ext_Markets'])
if s['Price'] < (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
buy = beta * theta*EMH_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EMH_portion*(1-theta))
return {'buy_order1': buy}
elif s['Price'] > (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
return {'buy_order1': 0}
else:
return {'buy_order1': 0}
def b1m2(step, sL, s):
# print('b1m2')
theta = (s['Z']*EMH_portion*s['Price'])/(s['Z']*EMH_portion*s['Price'] + EMH_Ext_Hold * s['P_Ext_Markets'])
if s['Price'] < (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
return {'sell_order1': 0}
elif s['Price'] > (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
sell = beta * theta*EMH_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EMH_portion*(1-theta))
return {'sell_order1': sell}
else:
return {'sell_order1': 0}
# BEHAVIOR 3: Herding
Herd_portion = Decimal('0.250')
Herd_Ext_Hold = Decimal('42000.0')
Herd_UB = Decimal('0.10') # UPPER BOUND
Herd_LB = Decimal('0.10') # LOWER BOUND
def b3m2(step, sL, s):
theta = (s['Z']*Herd_portion*s['Price'])/(s['Z']*Herd_portion*s['Price'] + Herd_Ext_Hold * s['P_Ext_Markets'])
# if s['Price'] - s['Price_Signal'] < (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)) - Herd_LB:
if (s['Price'] - s['Price_Signal']) < - Herd_LB:
sell = beta * theta*Herd_Ext_Hold * s['P_Ext_Markets']/(s['Price']*Herd_portion*(1-theta))
return {'herd_sell': sell, 'herd_buy': 0}
# elif s['Price'] > Herd_UB - (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)):
elif (s['Price'] - s['Price_Signal']) > Herd_UB:
buy = beta * theta*Herd_Ext_Hold * s['P_Ext_Markets']/(s['Price']*Herd_portion*(1-theta))
return {'herd_sell': 0, 'herd_buy': buy}
else:
return {'herd_sell': 0, 'herd_buy': 0}
# BEHAVIOR 4: HODLers
HODL_belief = Decimal('10.0')
HODL_portion = Decimal('0.250')
HODL_Ext_Hold = Decimal('4200.0')
def b4m2(step, sL, s):
# print('b4m2')
theta = (s['Z']*HODL_portion*s['Price'])/(s['Z']*HODL_portion*s['Price'] + HODL_Ext_Hold * s['P_Ext_Markets'])
if s['Price'] < 1/HODL_belief*(theta*HODL_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*HODL_portion*(1-theta)):
sell = beta * theta*HODL_Ext_Hold * s['P_Ext_Markets']/(s['Price']*HODL_portion*(1-theta))
return {'sell_order2': sell}
elif s['Price'] > (theta*HODL_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*HODL_portion*(1-theta)):
return {'sell_order2': 0}
else:
return {'sell_order2': 0}
# STATES
# ZEUS Fixed Supply
def s1m1(step, sL, s, _input):
y = 'Z'
x = s['Z'] #+ _input # / Psignal_int
return (y, x)
# def s2m1(step, sL, s, _input):
# y = 'Price'
# x = (s['P_Ext_Markets'] - _input['buy_order1']) / s['Z'] * 10000
# #x= alpha * s['Z'] + (1 - alpha)*s['Price']
# return (y, x)
def s3m1(step, sL, s, _input):
y = 'Buy_Log'
x = _input['buy_order1'] + _input['herd_buy'] # / Psignal_int
return (y, x)
def s4m2(step, sL, s, _input):
y = 'Sell_Log'
x = _input['sell_order1'] + _input['sell_order2'] + _input['herd_sell'] # / Psignal_int
return (y, x)
def s3m3(step, sL, s, _input):
y = 'Buy_Log'
x = s['Buy_Log'] + _input # / Psignal_int
return (y, x)
# Price Update
def s2m3(step, sL, s, _input):
y = 'Price'
#var1 = Decimal.from_float(s['Buy_Log'])
x = s['Price'] + s['Buy_Log'] /s['Z'] - s['Sell_Log']/s['Z']
#+ np.divide(s['Buy_Log'],s['Z']) - np.divide() # / Psignal_int
return (y, x)
def s5m3(step, sL, s, _input):
y = 'Price_Signal'
x = alpha * s['Price'] + (1 - alpha)*s['Price_Signal']
return (y, x)
def s6m1(step, sL, s, _input):
y = 'P_Ext_Markets'
x = s['P_Ext_Markets'] - _input
#x= alpha * s['Z'] + (1 - alpha)*s['Price']
return (y, x)
def s2m2(step, sL, s, _input):
y = 'Price'
x = (s['P_Ext_Markets'] - _input) /s['Z'] *10000
#x= alpha * s['Z'] + (1 - alpha)*s['Price']
return (y, x)
# Exogenous States
proc_one_coef_A = -125
proc_one_coef_B = 125
# A change in belief of actual price, passed onto behaviors to make action
def es4p2(step, sL, s, _input):
y = 'P_Ext_Markets'
x = s['P_Ext_Markets'] + bound_norm_random(seed['z'], proc_one_coef_A, proc_one_coef_B)
return (y,x)
ts_format = '%Y-%m-%d %H:%M:%S'
t_delta = timedelta(days=0, minutes=0, seconds=1)
def es5p2(step, sL, s, _input):
y = 'timestamp'
x = ep_time_step(s, dt_str=s['timestamp'], fromat_str=ts_format, _timedelta=t_delta)
return (y, x)
#Environment States
# NONE
# Genesis States
state_dict = {
'Z': Decimal(21000000.0),
'Price': Decimal(100.0), # Initialize = Z for EMA
'Buy_Log': Decimal(0.0),
'Sell_Log': Decimal(0.0),
'Price_Signal': Decimal(100.0),
'Trans': Decimal(0.0),
'P_Ext_Markets': Decimal(25000.0),
'timestamp': '2018-10-01 15:16:24'
}
def env_proc_id(x):
return x
env_processes = {}
exogenous_states = exo_update_per_ts(
{
"P_Ext_Markets": es4p2,
"timestamp": es5p2
}
)
sim_config = {
"N": 20,
"T": range(1000)
}
# test return vs. non-return functions as lambdas
# test fully defined functions
mechanisms = {
"m1": {
"behaviors": {
"b1": b1m1,
"b3": b3m2
},
"states": {
"Z": s1m1,
"Buy_Log": s3m1
}
},
"m2": {
"behaviors": {
"b1": b1m2,
"b3": b3m2,
"b4": b4m2
},
"states": {
"Sell_Log": s4m2
}
},
"m3": {
"behaviors": {
},
"states": {
"Price": s2m3,
"Price_Signal": s5m3
}
}
}
configs.append(Configuration(sim_config, state_dict, seed, exogenous_states, env_processes, mechanisms))

View File

@ -1,267 +0,0 @@
from decimal import Decimal
import numpy as np
from datetime import timedelta
from SimCAD import configs
from SimCAD.configuration import Configuration
from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \
ep_time_step
seed = {
'z': np.random.RandomState(1)
}
# Signals
# Pr_signal
beta = Decimal('0.25') # agent response gain
beta_LT = Decimal('0.1') # LT agent response gain
# alpha = .67, 2 block moving average
alpha = Decimal('0.67') # 21 day EMA forgetfullness between 0 and 1, closer to 1 discounts older obs quicker, should be 2/(N+1)
max_withdraw_factor = Decimal('0.9')
external_draw = Decimal('0.01') # between 0 and 1 to draw Buy_Log to external
#alpha * s['Zeus_ST'] + (1 - alpha)*s['Zeus_LT']
# Stochastic process factors
correction_factor = Decimal('0.01')
volatility = Decimal('5.0')
# Buy_Log_signal =
# Z_signal =
# Price_signal =
# TDR_draw_signal =
# P_Ext_Markets_signal =
# Behaviors per Mechanism
# BEHAVIOR 1: EMH Trader
EMH_portion = Decimal('0.250')
EMH_Ext_Hold = Decimal('42000.0')
def b1m1(step, sL, s):
# print('b1m1')
theta = (s['Z']*EMH_portion*s['Price'])/(s['Z']*EMH_portion*s['Price'] + EMH_Ext_Hold * s['P_Ext_Markets'])
if s['Price'] < (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
buy = beta * theta*EMH_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EMH_portion*(1-theta))
return {'buy_order1': buy}
elif s['Price'] > (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
return {'buy_order1': 0}
else:
return {'buy_order1': 0}
def b1m2(step, sL, s):
# print('b1m2')
theta = (s['Z']*EMH_portion*s['Price'])/(s['Z']*EMH_portion*s['Price'] + EMH_Ext_Hold * s['P_Ext_Markets'])
if s['Price'] < (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
return {'sell_order1': 0}
elif s['Price'] > (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
sell = beta * theta*EMH_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EMH_portion*(1-theta))
return {'sell_order1': sell}
else:
return {'sell_order1': 0}
# BEHAVIOR 3: Herding
Herd_portion = Decimal('0.250')
Herd_Ext_Hold = Decimal('42000.0')
Herd_UB = Decimal('0.10') # UPPER BOUND
Herd_LB = Decimal('0.10') # LOWER BOUND
def b3m2(step, sL, s):
theta = (s['Z']*Herd_portion*s['Price'])/(s['Z']*Herd_portion*s['Price'] + Herd_Ext_Hold * s['P_Ext_Markets'])
# if s['Price'] - s['Price_Signal'] < (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)) - Herd_LB:
if (s['Price'] - s['Price_Signal']) < - Herd_LB:
sell = beta * theta*Herd_Ext_Hold * s['P_Ext_Markets']/(s['Price']*Herd_portion*(1-theta))
return {'herd_sell': sell, 'herd_buy': 0}
# elif s['Price'] > Herd_UB - (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)):
elif (s['Price'] - s['Price_Signal']) > Herd_UB:
buy = beta * theta*Herd_Ext_Hold * s['P_Ext_Markets']/(s['Price']*Herd_portion*(1-theta))
return {'herd_sell': 0, 'herd_buy': buy}
else:
return {'herd_sell': 0, 'herd_buy': 0}
# BEHAVIOR 4: HODLers
HODL_belief = Decimal('10.0')
HODL_portion = Decimal('0.250')
HODL_Ext_Hold = Decimal('4200.0')
def b4m2(step, sL, s):
# print('b4m2')
theta = (s['Z']*HODL_portion*s['Price'])/(s['Z']*HODL_portion*s['Price'] + HODL_Ext_Hold * s['P_Ext_Markets'])
if s['Price'] < 1/HODL_belief*(theta*HODL_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*HODL_portion*(1-theta)):
sell = beta * theta*HODL_Ext_Hold * s['P_Ext_Markets']/(s['Price']*HODL_portion*(1-theta))
return {'sell_order2': sell}
elif s['Price'] > (theta*HODL_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*HODL_portion*(1-theta)):
return {'sell_order2': 0}
else:
return {'sell_order2': 0}
# BEHAVIOR 7: Endogenous Information Updating (EIU)
EIU_portion = Decimal('0.250')
EIU_Ext_Hold = Decimal('42000.0')
EIU_UB = Decimal('0.50') # UPPER BOUND
EIU_LB = Decimal('0.50') # LOWER BOUND
def b7m2(step, sL, s):
theta = (s['Z']*EIU_portion*s['Price'])/(s['Z']*EIU_portion*s['Price'] + EIU_Ext_Hold * s['P_Ext_Markets'])
# if s['Price'] - s['Price_Signal'] < (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)) - Herd_LB:
if (s['Price'] - s['Price_Signal']) < - EIU_LB:
sell = beta * theta*EIU_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EIU_portion*(1-theta))
return {'EIU_sell': sell, 'EIU_buy': 0}
# elif s['Price'] > Herd_UB - (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)):
elif (s['Price'] - s['Price_Signal']) > EIU_UB:
buy = beta * theta* EIU_Ext_Hold * s['P_Ext_Markets']/(s['Price']* EIU_portion*(1-theta))
return {'EIU_sell': 0, 'EIU_buy': buy}
else:
return {'EIU_sell': 0, 'EIU_buy': 0}
# STATES
# ZEUS Fixed Supply
def s1m1(step, sL, s, _input):
y = 'Z'
x = s['Z'] #+ _input # / Psignal_int
return (y, x)
# def s2m1(step, sL, s, _input):
# y = 'Price'
# x = (s['P_Ext_Markets'] - _input['buy_order1']) / s['Z'] * 10000
# #x= alpha * s['Z'] + (1 - alpha)*s['Price']
# return (y, x)
def s3m1(step, sL, s, _input):
y = 'Buy_Log'
x = _input['buy_order1'] + _input['herd_buy'] + _input['EIU_buy'] # / Psignal_int
return (y, x)
def s4m2(step, sL, s, _input):
y = 'Sell_Log'
x = _input['sell_order1'] + _input['sell_order2'] + _input['herd_sell'] + _input['EIU_sell'] # / Psignal_int
return (y, x)
# def s3m3(step, sL, s, _input):
# y = 'Buy_Log'
# x = s['Buy_Log'] + _input # / Psignal_int
# return (y, x)
# Price Update
def s2m3(step, sL, s, _input):
y = 'Price'
#var1 = Decimal.from_float(s['Buy_Log'])
x = s['Price'] + s['Buy_Log'] /s['Z'] /(Decimal('0.10') * s['Price']) - s['Sell_Log'] / s['Z'] / (Decimal('0.10')*s['Price'])
#+ np.divide(s['Buy_Log'],s['Z']) - np.divide() # / Psignal_int
return (y, x)
def s5m3(step, sL, s, _input):
y = 'Price_Signal'
x = alpha * s['Price'] + (1 - alpha)*s['Price_Signal']
return (y, x)
def s6m1(step, sL, s, _input):
y = 'P_Ext_Markets'
x = s['P_Ext_Markets'] - _input
#x= alpha * s['Z'] + (1 - alpha)*s['Price']
return (y, x)
def s2m2(step, sL, s, _input):
y = 'Price'
x = (s['P_Ext_Markets'] - _input) /s['Z'] *10000
#x= alpha * s['Z'] + (1 - alpha)*s['Price']
return (y, x)
# Exogenous States
proc_one_coef_A = -125
proc_one_coef_B = 125
# A change in belief of actual price, passed onto behaviors to make action
def es4p2(step, sL, s, _input):
y = 'P_Ext_Markets'
x = s['P_Ext_Markets'] + bound_norm_random(seed['z'], proc_one_coef_A, proc_one_coef_B)
return (y,x)
def es5p2(step, sL, s, _input): # accept timedelta instead of timedelta params
y = 'timestamp'
x = ep_time_step(s, s['timestamp'], seconds=1)
return (y, x)
#Environment States
# NONE
# Genesis States
state_dict = {
'Z': Decimal(21000000.0),
'Price': Decimal(100.0), # Initialize = Z for EMA
'Buy_Log': Decimal(0.0),
'Sell_Log': Decimal(0.0),
'Price_Signal': Decimal(100.0),
'Trans': Decimal(0.0),
'P_Ext_Markets': Decimal(25000.0),
'timestamp': '2018-10-01 15:16:24'
}
def env_proc_id(x):
return x
env_processes = {
# "P_Ext_Markets": env_proc_id
}
exogenous_states = exo_update_per_ts(
{
"P_Ext_Markets": es4p2,
"timestamp": es5p2
}
)
sim_config = {
"N": 100,
"T": range(1000)
}
# test return vs. non-return functions as lambdas
# test fully defined functions
mechanisms = {
"m1": {
"behaviors": {
"b1": b1m1,
"b3": b3m2,
"b7": b7m2
},
"states": {
"Z": s1m1,
"Buy_Log": s3m1
}
},
"m2": {
"behaviors": {
"b1": b1m2,
"b3": b3m2,
"b4": b4m2,
"b7": b7m2
},
"states": {
"Sell_Log": s4m2
}
},
"m3": {
"behaviors": {
},
"states": {
"Price": s2m3,
"Price_Signal": s5m3
}
}
}
configs.append(Configuration(sim_config, state_dict, seed, exogenous_states, env_processes, mechanisms))

View File

@ -1,300 +0,0 @@
from decimal import Decimal
import numpy as np
from datetime import timedelta
from SimCAD import configs
from SimCAD.configuration import Configuration
from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \
ep_time_step
seed = {
'z': np.random.RandomState(1)
}
# Signals
# Pr_signal
beta = Decimal('0.25') # agent response gain
beta_LT = Decimal('0.1') # LT agent response gain
# alpha = .67, 2 block moving average
alpha = Decimal('0.67')
# 21 day EMA forgetfullness between 0 and 1, closer to 1 discounts older obs quicker, should be 2/(N+1)
# 21 * 3 mech steps, 2/64 = 0.03125
alpha_2 = Decimal('0.03125')
max_withdraw_factor = Decimal('0.9')
external_draw = Decimal('0.01') # between 0 and 1 to draw Buy_Log to external
#alpha * s['Zeus_ST'] + (1 - alpha)*s['Zeus_LT']
# Stochastic process factors
correction_factor = Decimal('0.01')
volatility = Decimal('5.0')
# Buy_Log_signal =
# Z_signal =
# Price_signal =
# TDR_draw_signal =
# P_Ext_Markets_signal =
# Behaviors per Mechanism
# BEHAVIOR 1: EMH Trader
EMH_portion = Decimal('0.20')
EMH_Ext_Hold = Decimal('42000.0')
def b1m1(step, sL, s):
# print('b1m1')
theta = (s['Z']*EMH_portion*s['Price'])/(s['Z']*EMH_portion*s['Price'] + EMH_Ext_Hold * s['P_Ext_Markets'])
if s['Price'] < (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
buy = beta * theta*EMH_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EMH_portion*(1-theta))
return {'buy_order1': buy}
elif s['Price'] > (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
return {'buy_order1': 0}
else:
return {'buy_order1': 0}
def b1m2(step, sL, s):
# print('b1m2')
theta = (s['Z']*EMH_portion*s['Price'])/(s['Z']*EMH_portion*s['Price'] + EMH_Ext_Hold * s['P_Ext_Markets'])
if s['Price'] < (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
return {'sell_order1': 0}
elif s['Price'] > (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
sell = beta * theta*EMH_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EMH_portion*(1-theta))
return {'sell_order1': sell}
else:
return {'sell_order1': 0}
# BEHAVIOR 3: Herding
Herd_portion = Decimal('0.20')
Herd_Ext_Hold = Decimal('42000.0')
Herd_UB = Decimal('0.10') # UPPER BOUND
Herd_LB = Decimal('0.10') # LOWER BOUND
def b3m2(step, sL, s):
theta = (s['Z']*Herd_portion*s['Price'])/(s['Z']*Herd_portion*s['Price'] + Herd_Ext_Hold * s['P_Ext_Markets'])
# if s['Price'] - s['Price_Signal'] < (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)) - Herd_LB:
if (s['Price'] - s['Price_Signal']) < - Herd_LB:
sell = beta * theta*Herd_Ext_Hold * s['P_Ext_Markets']/(s['Price']*Herd_portion*(1-theta))
return {'herd_sell': sell, 'herd_buy': 0}
# elif s['Price'] > Herd_UB - (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)):
elif (s['Price'] - s['Price_Signal']) > Herd_UB:
buy = beta * theta*Herd_Ext_Hold * s['P_Ext_Markets']/(s['Price']*Herd_portion*(1-theta))
return {'herd_sell': 0, 'herd_buy': buy}
else:
return {'herd_sell': 0, 'herd_buy': 0}
# BEHAVIOR 4: HODLers
HODL_belief = Decimal('10.0')
HODL_portion = Decimal('0.20')
HODL_Ext_Hold = Decimal('4200.0')
def b4m2(step, sL, s):
# print('b4m2')
theta = (s['Z']*HODL_portion*s['Price'])/(s['Z']*HODL_portion*s['Price'] + HODL_Ext_Hold * s['P_Ext_Markets'])
if s['Price'] < 1/HODL_belief*(theta*HODL_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*HODL_portion*(1-theta)):
sell = beta * theta*HODL_Ext_Hold * s['P_Ext_Markets']/(s['Price']*HODL_portion*(1-theta))
return {'sell_order2': sell}
elif s['Price'] > (theta*HODL_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*HODL_portion*(1-theta)):
return {'sell_order2': 0}
else:
return {'sell_order2': 0}
# BEHAVIOR 7: Endogenous Information Updating (EIU)
# Short Term Price Signal, Lower Threshold = BOT-like
EIU_portion = Decimal('0.20')
EIU_Ext_Hold = Decimal('42000.0')
EIU_UB = Decimal('0.50') # UPPER BOUND
EIU_LB = Decimal('0.50') # LOWER BOUND
def b7m2(step, sL, s):
theta = (s['Z']*EIU_portion*s['Price'])/(s['Z']*EIU_portion*s['Price'] + EIU_Ext_Hold * s['P_Ext_Markets'])
# if s['Price'] - s['Price_Signal'] < (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)) - Herd_LB:
if (s['Price'] - s['Price_Signal']) < - EIU_LB:
sell = beta * theta*EIU_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EIU_portion*(1-theta))
return {'EIU_sell': sell, 'EIU_buy': 0}
# elif s['Price'] > Herd_UB - (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)):
elif (s['Price'] - s['Price_Signal']) > EIU_UB:
buy = beta * theta* EIU_Ext_Hold * s['P_Ext_Markets']/(s['Price']* EIU_portion*(1-theta))
return {'EIU_sell': 0, 'EIU_buy': buy}
else:
return {'EIU_sell': 0, 'EIU_buy': 0}
# BEHAVIOR 7b: Endogenous Information Updating (EIU)
# Longer Term Price Signal, Higher Threshold = Human-Like
HEIU_portion = Decimal('0.20')
HEIU_Ext_Hold = Decimal('42000.0')
HEIU_UB = Decimal('2.0') # UPPER BOUND
HEIU_LB = Decimal('2.0') # LOWER BOUND
def b7hm2(step, sL, s):
theta = (s['Z']*HEIU_portion*s['Price'])/(s['Z']*HEIU_portion*s['Price'] + HEIU_Ext_Hold * s['P_Ext_Markets'])
# if s['Price'] - s['Price_Signal'] < (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)) - Herd_LB:
if (s['Price'] - s['Price_Signal_2']) < - HEIU_LB:
sell = beta * theta* HEIU_Ext_Hold * s['P_Ext_Markets']/(s['Price']*HEIU_portion*(1-theta))
return {'HEIU_sell': sell, 'HEIU_buy': 0}
# elif s['Price'] > Herd_UB - (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)):
elif (s['Price'] - s['Price_Signal_2']) > HEIU_UB:
buy = beta * theta* HEIU_Ext_Hold * s['P_Ext_Markets']/(s['Price']* HEIU_portion*(1-theta))
return {'HEIU_sell': 0, 'HEIU_buy': buy}
else:
return {'HEIU_sell': 0, 'HEIU_buy': 0}
# STATES
# ZEUS Fixed Supply
def s1m1(step, sL, s, _input):
y = 'Z'
x = s['Z'] #+ _input # / Psignal_int
return (y, x)
# def s2m1(step, sL, s, _input):
# y = 'Price'
# x = (s['P_Ext_Markets'] - _input['buy_order1']) / s['Z'] * 10000
# #x= alpha * s['Z'] + (1 - alpha)*s['Price']
# return (y, x)
def s3m1(step, sL, s, _input):
y = 'Buy_Log'
x = _input['buy_order1'] + _input['herd_buy'] + _input['EIU_buy'] + _input['HEIU_buy'] # / Psignal_int
return (y, x)
def s4m2(step, sL, s, _input):
y = 'Sell_Log'
x = _input['sell_order1'] + _input['sell_order2'] + _input['herd_sell'] + _input['EIU_sell'] + _input['HEIU_sell'] # / Psignal_int
return (y, x)
# def s3m3(step, sL, s, _input):
# y = 'Buy_Log'
# x = s['Buy_Log'] + _input # / Psignal_int
# return (y, x)
# Price Update
def s2m3(step, sL, s, _input):
y = 'Price'
#var1 = Decimal.from_float(s['Buy_Log'])
x = s['Price'] + s['Buy_Log'] /s['Z']/(Decimal('1.25') ) - s['Sell_Log']/s['Z']/(Decimal('1.25') )
#+ np.divide(s['Buy_Log'],s['Z']) - np.divide() # / Psignal_int
return (y, x)
def s5m3(step, sL, s, _input):
y = 'Price_Signal'
x = alpha * s['Price'] + (1 - alpha)*s['Price_Signal']
return (y, x)
def s6m3(step, sL, s, _input):
y = 'Price_Signal_2'
x = alpha_2 * s['Price'] + (1 - alpha_2)*s['Price_Signal_2']
return (y, x)
def s6m1(step, sL, s, _input):
y = 'P_Ext_Markets'
x = s['P_Ext_Markets'] - _input
#x= alpha * s['Z'] + (1 - alpha)*s['Price']
return (y, x)
def s2m2(step, sL, s, _input):
y = 'Price'
x = (s['P_Ext_Markets'] - _input) /s['Z'] *10000
#x= alpha * s['Z'] + (1 - alpha)*s['Price']
return (y, x)
# Exogenous States
proc_one_coef_A = -125
proc_one_coef_B = 125
# A change in belief of actual price, passed onto behaviors to make action
def es4p2(step, sL, s, _input):
y = 'P_Ext_Markets'
x = s['P_Ext_Markets'] + bound_norm_random(seed['z'], proc_one_coef_A, proc_one_coef_B)
return (y,x)
def es5p2(step, sL, s, _input): # accept timedelta instead of timedelta params
y = 'timestamp'
x = ep_time_step(s, s['timestamp'], seconds=1)
return (y, x)
#Environment States
# NONE
# Genesis States
state_dict = {
'Z': Decimal(21000000.0),
'Price': Decimal(100.0), # Initialize = Z for EMA
'Buy_Log': Decimal(0.0),
'Sell_Log': Decimal(0.0),
'Price_Signal': Decimal(100.0),
'Price_Signal_2': Decimal(100.0),
'Trans': Decimal(0.0),
'P_Ext_Markets': Decimal(25000.0),
'timestamp': '2018-10-01 15:16:24'
}
def env_proc_id(x):
return x
env_processes = {
# "P_Ext_Markets": env_proc_id
}
exogenous_states = exo_update_per_ts(
{
"P_Ext_Markets": es4p2,
"timestamp": es5p2
}
)
sim_config = {
"N": 100,
"T": range(1000)
}
# test return vs. non-return functions as lambdas
# test fully defined functions
mechanisms = {
"m1": {
"behaviors": {
"b1": b1m1,
"b3": b3m2,
"b7": b7m2,
"b7h": b7hm2
},
"states": {
"Z": s1m1,
"Buy_Log": s3m1
}
},
"m2": {
"behaviors": {
"b1": b1m2,
"b3": b3m2,
"b4": b4m2,
"b7": b7m2,
"b7h": b7hm2
},
"states": {
"Sell_Log": s4m2
}
},
"m3": {
"behaviors": {
},
"states": {
"Price": s2m3,
"Price_Signal": s5m3,
"Price_Signal_2": s6m3,
}
}
}
configs.append(Configuration(sim_config, state_dict, seed, exogenous_states, env_processes, mechanisms))

View File

@ -1,309 +0,0 @@
from decimal import Decimal
import numpy as np
from datetime import timedelta
from SimCAD import configs
from SimCAD.configuration import Configuration
from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \
ep_time_step
seed = {
'z': np.random.RandomState(1)
}
# Signals
# Pr_signal
beta = Decimal('0.25') # agent response gain
beta_LT = Decimal('0.1') # LT agent response gain
# alpha = .67, 2 block moving average
alpha = Decimal('0.67')
# 21 day EMA forgetfullness between 0 and 1, closer to 1 discounts older obs quicker, should be 2/(N+1)
# 21 * 3 mech steps, 2/64 = 0.03125
alpha_2 = Decimal('0.03125')
max_withdraw_factor = Decimal('0.9')
external_draw = Decimal('0.01') # between 0 and 1 to draw Buy_Log to external
#alpha * s['Zeus_ST'] + (1 - alpha)*s['Zeus_LT']
# Stochastic process factors
correction_factor = Decimal('0.01')
volatility = Decimal('5.0')
# Buy_Log_signal =
# Z_signal =
# Price_signal =
# TDR_draw_signal =
# P_Ext_Markets_signal =
# Behaviors per Mechanism
# BEHAVIOR 1: EMH Trader
EMH_portion = Decimal('0.20')
EMH_Ext_Hold = Decimal('42000.0')
def b1m1(step, sL, s):
# print('b1m1')
theta = (s['Z']*EMH_portion*s['Price'])/(s['Z']*EMH_portion*s['Price'] + EMH_Ext_Hold * s['P_Ext_Markets'])
if s['Price'] < (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
buy = beta * theta*EMH_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EMH_portion*(1-theta))
price = s['Price']
return {'EMH_buy': buy, 'EMH_buy_P': price}
elif s['Price'] > (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
return {'EMH_buy': 0}
else:
return {'EMH_buy': 0}
def b1m2(step, sL, s):
# print('b1m2')
theta = (s['Z']*EMH_portion*s['Price'])/(s['Z']*EMH_portion*s['Price'] + EMH_Ext_Hold * s['P_Ext_Markets'])
if s['Price'] < (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
return {'EMH_sell': 0}
elif s['Price'] > (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
sell = beta * theta*EMH_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EMH_portion*(1-theta))
price = s['Price']
return {'EMH_sell': sell, 'EMH_sell_P': price}
else:
return {'EMH_sell': 0}
# BEHAVIOR 3: Herding
Herd_portion = Decimal('0.20')
Herd_Ext_Hold = Decimal('42000.0')
Herd_UB = Decimal('0.10') # UPPER BOUND
Herd_LB = Decimal('0.10') # LOWER BOUND
def b3m2(step, sL, s):
theta = (s['Z']*Herd_portion*s['Price'])/(s['Z']*Herd_portion*s['Price'] + Herd_Ext_Hold * s['P_Ext_Markets'])
# if s['Price'] - s['Price_Signal'] < (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)) - Herd_LB:
if (s['Price'] - s['Price_Signal']) < - Herd_LB:
sell = beta * theta*Herd_Ext_Hold * s['P_Ext_Markets']/(s['Price']*Herd_portion*(1-theta))
price = s['Price'] - (s['Price_Signal'] / s['Price'])
return {'herd_sell': sell, 'herd_buy': 0, 'herd_sell_P': price}
# elif s['Price'] > Herd_UB - (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)):
elif (s['Price'] - s['Price_Signal']) > Herd_UB:
buy = beta * theta*Herd_Ext_Hold * s['P_Ext_Markets']/(s['Price']*Herd_portion*(1-theta))
price = s['Price'] + (s['Price'] / s['Price_Signal'])
return {'herd_sell': 0, 'herd_buy': buy, 'herd_buy_P': price}
else:
return {'herd_sell': 0, 'herd_buy': 0}
# BEHAVIOR 4: HODLers
HODL_belief = Decimal('10.0')
HODL_portion = Decimal('0.20')
HODL_Ext_Hold = Decimal('4200.0')
def b4m2(step, sL, s):
# print('b4m2')
theta = (s['Z']*HODL_portion*s['Price'])/(s['Z']*HODL_portion*s['Price'] + HODL_Ext_Hold * s['P_Ext_Markets'])
if s['Price'] < 1/HODL_belief*(theta*HODL_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*HODL_portion*(1-theta)):
sell = beta * theta*HODL_Ext_Hold * s['P_Ext_Markets']/(s['Price']*HODL_portion*(1-theta))
price = s['Price']
return {'HODL_sell': sell, 'HODL_sell_P': price}
elif s['Price'] > (theta*HODL_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*HODL_portion*(1-theta)):
return {'HODL_sell': 0}
else:
return {'HODL_sell': 0}
# BEHAVIOR 7: Endogenous Information Updating (EIU)
# Short Term Price Signal, Lower Threshold = BOT-like
EIU_portion = Decimal('0.20')
EIU_Ext_Hold = Decimal('42000.0')
EIU_UB = Decimal('0.50') # UPPER BOUND
EIU_LB = Decimal('0.50') # LOWER BOUND
def b7m2(step, sL, s):
theta = (s['Z']*EIU_portion*s['Price'])/(s['Z']*EIU_portion*s['Price'] + EIU_Ext_Hold * s['P_Ext_Markets'])
# if s['Price'] - s['Price_Signal'] < (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)) - Herd_LB:
if (s['Price'] - s['Price_Signal']) < - EIU_LB:
sell = beta * theta*EIU_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EIU_portion*(1-theta))
price = s['Price'] + (s['Price_Signal'] / s['Price'])
return {'EIU_sell': sell, 'EIU_buy': 0, 'EIU_sell_P': price}
# elif s['Price'] > Herd_UB - (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)):
elif (s['Price'] - s['Price_Signal']) > EIU_UB:
buy = beta * theta* EIU_Ext_Hold * s['P_Ext_Markets']/(s['Price']* EIU_portion*(1-theta))
price = s['Price'] - (s['Price'] / s['Price_Signal'])
return {'EIU_sell': 0, 'EIU_buy': buy, 'EIU_buy_P': price}
else:
return {'EIU_sell': 0, 'EIU_buy': 0}
# BEHAVIOR 7b: Endogenous Information Updating (EIU)
# Longer Term Price Signal, Higher Threshold = Human-Like
HEIU_portion = Decimal('0.20')
HEIU_Ext_Hold = Decimal('42000.0')
HEIU_UB = Decimal('2.0') # UPPER BOUND
HEIU_LB = Decimal('2.0') # LOWER BOUND
def b7hm2(step, sL, s):
theta = (s['Z']*HEIU_portion*s['Price'])/(s['Z']*HEIU_portion*s['Price'] + HEIU_Ext_Hold * s['P_Ext_Markets'])
# if s['Price'] - s['Price_Signal'] < (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)) - Herd_LB:
if (s['Price'] - s['Price_Signal_2']) < - HEIU_LB:
sell = beta * theta* HEIU_Ext_Hold * s['P_Ext_Markets']/(s['Price']*HEIU_portion*(1-theta))
price = s['Price'] + (s['Price_Signal_2'] / s['Price'])
return {'HEIU_sell': sell, 'HEIU_buy': 0, 'HEIU_sell_P': price}
# elif s['Price'] > Herd_UB - (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)):
elif (s['Price'] - s['Price_Signal_2']) > HEIU_UB:
buy = beta * theta* HEIU_Ext_Hold * s['P_Ext_Markets']/(s['Price']* HEIU_portion*(1-theta))
price = s['Price'] - (s['Price'] / s['Price_Signal_2'])
return {'HEIU_sell': 0, 'HEIU_buy': buy, 'HEIU_buy_P': price}
else:
return {'HEIU_sell': 0, 'HEIU_buy': 0}
# STATES
# ZEUS Fixed Supply
def s1m1(step, sL, s, _input):
y = 'Z'
x = s['Z'] #+ _input # / Psignal_int
return (y, x)
# def s2m1(step, sL, s, _input):
# y = 'Price'
# x = (s['P_Ext_Markets'] - _input['EMH_buy']) / s['Z'] * 10000
# #x= alpha * s['Z'] + (1 - alpha)*s['Price']
# return (y, x)
def s3m1(step, sL, s, _input):
y = 'Buy_Log'
x = _input['EMH_buy'] + _input['herd_buy'] + _input['EIU_buy'] + _input['HEIU_buy'] # / Psignal_int
return (y, x)
def s4m2(step, sL, s, _input):
y = 'Sell_Log'
x = _input['EMH_sell'] + _input['HODL_sell'] + _input['herd_sell'] + _input['EIU_sell'] + _input['HEIU_sell'] # / Psignal_int
return (y, x)
# def s3m3(step, sL, s, _input):
# y = 'Buy_Log'
# x = s['Buy_Log'] + _input # / Psignal_int
# return (y, x)
# Price Update
def s2m3(step, sL, s, _input):
y = 'Price'
#var1 = Decimal.from_float(s['Buy_Log'])
x = s['Price'] + (s['Buy_Log'] /s['Z'] ) - (s['Sell_Log']/s['Z'] )
#+ np.divide(s['Buy_Log'],s['Z']) - np.divide() # / Psignal_int
return (y, x)
def s5m3(step, sL, s, _input):
y = 'Price_Signal'
x = alpha * s['Price'] + (1 - alpha)*s['Price_Signal']
return (y, x)
def s6m3(step, sL, s, _input):
y = 'Price_Signal_2'
x = alpha_2 * s['Price'] + (1 - alpha_2)*s['Price_Signal_2']
return (y, x)
def s6m1(step, sL, s, _input):
y = 'P_Ext_Markets'
x = s['P_Ext_Markets'] - _input
#x= alpha * s['Z'] + (1 - alpha)*s['Price']
return (y, x)
# def s2m2(step, sL, s, _input):
# y = 'Price'
# x = (s['P_Ext_Markets'] - _input) /s['Z'] *10000
# x= alpha * s['Z'] + (1 - alpha)*s['Price']
# return (y, x)
# Exogenous States
proc_one_coef_A = -125
proc_one_coef_B = 125
# A change in belief of actual price, passed onto behaviors to make action
def es4p2(step, sL, s, _input):
y = 'P_Ext_Markets'
x = s['P_Ext_Markets'] + bound_norm_random(seed['z'], proc_one_coef_A, proc_one_coef_B)
return (y,x)
def es5p2(step, sL, s, _input): # accept timedelta instead of timedelta params
y = 'timestamp'
x = ep_time_step(s, s['timestamp'], seconds=1)
return (y, x)
#Environment States
# NONE
# Genesis States
state_dict = {
'Z': Decimal(21000000.0),
'Price': Decimal(100.0), # Initialize = Z for EMA
'Buy_Log': Decimal(0.0),
'Sell_Log': Decimal(0.0),
'Price_Signal': Decimal(100.0),
'Price_Signal_2': Decimal(100.0),
'Trans': Decimal(0.0),
'P_Ext_Markets': Decimal(25000.0),
'timestamp': '2018-10-01 15:16:24'
}
def env_proc_id(x):
return x
env_processes = {
# "P_Ext_Markets": env_proc_id
}
exogenous_states = exo_update_per_ts(
{
"P_Ext_Markets": es4p2,
"timestamp": es5p2
}
)
sim_config = {
"N": 1,
"T": range(1000)
}
# test return vs. non-return functions as lambdas
# test fully defined functions
mechanisms = {
"m1": {
"behaviors": {
"b1": b1m1,
"b3": b3m2,
"b7": b7m2,
"b7h": b7hm2
},
"states": {
"Z": s1m1,
"Buy_Log": s3m1
}
},
"m2": {
"behaviors": {
"b1": b1m2,
"b3": b3m2,
"b4": b4m2,
"b7": b7m2,
"b7h": b7hm2
},
"states": {
"Sell_Log": s4m2
}
},
"m3": {
"behaviors": {
},
"states": {
"Price": s2m3,
"Price_Signal": s5m3,
"Price_Signal_2": s6m3,
}
}
}
configs.append(Configuration(sim_config, state_dict, seed, exogenous_states, env_processes, mechanisms))

View File

@ -1,319 +0,0 @@
from decimal import Decimal
import numpy as np
from datetime import timedelta
from SimCAD import configs
from SimCAD.configuration import Configuration
from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \
ep_time_step
seed = {
'z': np.random.RandomState(1)
}
# Signals
# Pr_signal
beta = Decimal('0.25') # agent response gain
beta_LT = Decimal('0.1') # LT agent response gain
# alpha = .67, 2 block moving average
alpha = Decimal('0.67')
# 21 day EMA forgetfullness between 0 and 1, closer to 1 discounts older obs quicker, should be 2/(N+1)
# 21 * 3 mech steps, 2/64 = 0.03125
alpha_2 = Decimal('0.03125')
max_withdraw_factor = Decimal('0.9')
external_draw = Decimal('0.01') # between 0 and 1 to draw Buy_Log to external
#alpha * s['Zeus_ST'] + (1 - alpha)*s['Zeus_LT']
# Stochastic process factors
correction_factor = Decimal('0.01')
volatility = Decimal('5.0')
# Buy_Log_signal =
# Z_signal =
# Price_signal =
# TDR_draw_signal =
# P_Ext_Markets_signal =
# Behaviors per Mechanism
# BEHAVIOR 1: EMH Trader
EMH_portion = Decimal('0.20')
EMH_Ext_Hold = Decimal('42000.0')
def b1m1(step, sL, s):
# print('b1m1')
theta = (s['Z']*EMH_portion*s['Price'])/(s['Z']*EMH_portion*s['Price'] + EMH_Ext_Hold * s['P_Ext_Markets'])
if s['Price'] < (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
buy = beta * theta*EMH_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EMH_portion*(1-theta))
price = s['Price']
return {'EMH_buy': buy, 'EMH_buy_P': price}
elif s['Price'] > (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
price = 0
return {'EMH_buy': 0, 'EMH_buy_P': price}
else:
price = 0
return {'EMH_buy': 0, 'EMH_buy_P': price}
def b1m2(step, sL, s):
# print('b1m2')
theta = (s['Z']*EMH_portion*s['Price'])/(s['Z']*EMH_portion*s['Price'] + EMH_Ext_Hold * s['P_Ext_Markets'])
if s['Price'] < (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
return {'EMH_sell': 0}
elif s['Price'] > (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
sell = beta * theta*EMH_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EMH_portion*(1-theta))
price = s['Price']
return {'EMH_sell': sell, 'EMH_sell_P': price}
else:
return {'EMH_sell': 0}
# BEHAVIOR 3: Herding
Herd_portion = Decimal('0.20')
Herd_Ext_Hold = Decimal('42000.0')
Herd_UB = Decimal('0.10') # UPPER BOUND
Herd_LB = Decimal('0.10') # LOWER BOUND
def b3m2(step, sL, s):
theta = (s['Z']*Herd_portion*s['Price'])/(s['Z']*Herd_portion*s['Price'] + Herd_Ext_Hold * s['P_Ext_Markets'])
# if s['Price'] - s['Price_Signal'] < (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)) - Herd_LB:
if (s['Price'] - s['Price_Signal']) < - Herd_LB:
sell = beta * theta*Herd_Ext_Hold * s['P_Ext_Markets']/(s['Price']*Herd_portion*(1-theta))
price = s['Price'] - (s['Price_Signal'] / s['Price'])
return {'herd_sell': sell, 'herd_buy': 0, 'herd_sell_P': price}
# elif s['Price'] > Herd_UB - (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)):
elif (s['Price'] - s['Price_Signal']) > Herd_UB:
buy = beta * theta*Herd_Ext_Hold * s['P_Ext_Markets']/(s['Price']*Herd_portion*(1-theta))
price = s['Price'] + (s['Price'] / s['Price_Signal'])
return {'herd_sell': 0, 'herd_buy': buy, 'herd_buy_P': price}
else:
return {'herd_sell': 0, 'herd_buy': 0, 'herd_buy_P':0}
# BEHAVIOR 4: HODLers
HODL_belief = Decimal('10.0')
HODL_portion = Decimal('0.20')
HODL_Ext_Hold = Decimal('4200.0')
def b4m2(step, sL, s):
# print('b4m2')
theta = (s['Z']*HODL_portion*s['Price'])/(s['Z']*HODL_portion*s['Price'] + HODL_Ext_Hold * s['P_Ext_Markets'])
if s['Price'] < 1/HODL_belief*(theta*HODL_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*HODL_portion*(1-theta)):
sell = beta * theta*HODL_Ext_Hold * s['P_Ext_Markets']/(s['Price']*HODL_portion*(1-theta))
price = s['Price']
return {'HODL_sell': sell, 'HODL_sell_P': price}
elif s['Price'] > (theta*HODL_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*HODL_portion*(1-theta)):
return {'HODL_sell': 0}
else:
return {'HODL_sell': 0}
# BEHAVIOR 7: Endogenous Information Updating (EIU)
# Short Term Price Signal, Lower Threshold = BOT-like
EIU_portion = Decimal('0.20')
EIU_Ext_Hold = Decimal('42000.0')
EIU_UB = Decimal('0.50') # UPPER BOUND
EIU_LB = Decimal('0.50') # LOWER BOUND
def b7m2(step, sL, s):
theta = (s['Z']*EIU_portion*s['Price'])/(s['Z']*EIU_portion*s['Price'] + EIU_Ext_Hold * s['P_Ext_Markets'])
# if s['Price'] - s['Price_Signal'] < (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)) - Herd_LB:
if (s['Price'] - s['Price_Signal']) < - EIU_LB:
sell = beta * theta*EIU_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EIU_portion*(1-theta))
price = s['Price'] + (s['Price_Signal'] / s['Price'])
return {'EIU_sell': sell, 'EIU_buy': 0, 'EIU_sell_P': price}
# elif s['Price'] > Herd_UB - (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)):
elif (s['Price'] - s['Price_Signal']) > EIU_UB:
buy = beta * theta* EIU_Ext_Hold * s['P_Ext_Markets']/(s['Price']* EIU_portion*(1-theta))
price = s['Price'] - (s['Price'] / s['Price_Signal'])
return {'EIU_sell': 0, 'EIU_buy': buy, 'EIU_buy_P': price}
else:
return {'EIU_sell': 0, 'EIU_buy': 0}
# BEHAVIOR 7b: Endogenous Information Updating (EIU)
# Longer Term Price Signal, Higher Threshold = Human-Like
HEIU_portion = Decimal('0.20')
HEIU_Ext_Hold = Decimal('42000.0')
HEIU_UB = Decimal('2.0') # UPPER BOUND
HEIU_LB = Decimal('2.0') # LOWER BOUND
def b7hm2(step, sL, s):
theta = (s['Z']*HEIU_portion*s['Price'])/(s['Z']*HEIU_portion*s['Price'] + HEIU_Ext_Hold * s['P_Ext_Markets'])
# if s['Price'] - s['Price_Signal'] < (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)) - Herd_LB:
if (s['Price'] - s['Price_Signal_2']) < - HEIU_LB:
sell = beta * theta* HEIU_Ext_Hold * s['P_Ext_Markets']/(s['Price']*HEIU_portion*(1-theta))
price = s['Price'] + (s['Price_Signal_2'] / s['Price'])
return {'HEIU_sell': sell, 'HEIU_buy': 0, 'HEIU_sell_P': price}
# elif s['Price'] > Herd_UB - (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)):
elif (s['Price'] - s['Price_Signal_2']) > HEIU_UB:
buy = beta * theta* HEIU_Ext_Hold * s['P_Ext_Markets']/(s['Price']* HEIU_portion*(1-theta))
price = s['Price'] - (s['Price'] / s['Price_Signal_2'])
return {'HEIU_sell': 0, 'HEIU_buy': buy, 'HEIU_buy_P': price}
else:
return {'HEIU_sell': 0, 'HEIU_buy': 0}
# STATES
# ZEUS Fixed Supply
def s1m1(step, sL, s, _input):
y = 'Z'
x = s['Z'] #+ _input # / Psignal_int
return (y, x)
# def s2m1(step, sL, s, _input):
# y = 'Price'
# x = (s['P_Ext_Markets'] - _input['EMH_buy']) / s['Z'] * 10000
# #x= alpha * s['Z'] + (1 - alpha)*s['Price']
# return (y, x)
def s3m1(step, sL, s, _input):
y = 'Buy_Log'
x = np.zeros(4)
x[0] = _input['EMH_buy']
x[1] = _input['EMH_buy_P']
x[2] = _input['herd_buy']
x[3] = _input['herd_buy_P']
# = _input['EMH_buy'] + _input['herd_buy'] + _input['EIU_buy'] + _input['HEIU_buy'] # / Psignal_int
return (y, x) #[0], x[1])
def s4m2(step, sL, s, _input):
y = 'Sell_Log'
x = _input['EMH_sell'] + _input['HODL_sell'] + _input['herd_sell'] + _input['EIU_sell'] + _input['HEIU_sell'] # / Psignal_int
return (y, x)
# def s3m3(step, sL, s, _input):
# y = 'Buy_Log'
# x = s['Buy_Log'] + _input # / Psignal_int
# return (y, x)
# Price Update
def s2m3(step, sL, s, _input):
y = 'Price'
#var1 = Decimal.from_float(s['Buy_Log'])
x = s['Price'] + (Decimal(s['Buy_Log'][0])) / s['Z'] # - (s['Sell_Log']/s['Z'] ) # for buy log term /s['Z'] )
#+ np.divide(s['Buy_Log'],s['Z']) - np.divide() # / Psignal_int
return (y, x)
def s5m3(step, sL, s, _input):
y = 'Price_Signal'
x = alpha * s['Price'] + (1 - alpha)*s['Price_Signal']
return (y, x)
def s6m3(step, sL, s, _input):
y = 'Price_Signal_2'
x = alpha_2 * s['Price'] + (1 - alpha_2)*s['Price_Signal_2']
return (y, x)
def s6m1(step, sL, s, _input):
y = 'P_Ext_Markets'
x = s['P_Ext_Markets'] - _input
#x= alpha * s['Z'] + (1 - alpha)*s['Price']
return (y, x)
# def s2m2(step, sL, s, _input):
# y = 'Price'
# x = (s['P_Ext_Markets'] - _input) /s['Z'] *10000
# x= alpha * s['Z'] + (1 - alpha)*s['Price']
# return (y, x)
# Exogenous States
proc_one_coef_A = -125
proc_one_coef_B = 125
# A change in belief of actual price, passed onto behaviors to make action
def es4p2(step, sL, s, _input):
y = 'P_Ext_Markets'
x = s['P_Ext_Markets'] + bound_norm_random(seed['z'], proc_one_coef_A, proc_one_coef_B)
return (y,x)
ts_format = '%Y-%m-%d %H:%M:%S'
t_delta = timedelta(days=0, minutes=0, seconds=1)
def es5p2(step, sL, s, _input):
y = 'timestamp'
x = ep_time_step(s, dt_str=s['timestamp'], fromat_str=ts_format, _timedelta=t_delta)
return (y, x)
#Environment States
# NONE
# Genesis States
state_dict = {
'Z': Decimal(21000000.0),
'Price': Decimal(100.0), # Initialize = Z for EMA
'Buy_Log': Decimal(0.0),
'Sell_Log': Decimal(0.0),
'Price_Signal': Decimal(100.0),
'Price_Signal_2': Decimal(100.0),
'Trans': Decimal(0.0),
'P_Ext_Markets': Decimal(25000.0),
'timestamp': '2018-10-01 15:16:24'
}
def env_proc_id(x):
return x
env_processes = {
# "P_Ext_Markets": env_proc_id
}
exogenous_states = exo_update_per_ts(
{
"P_Ext_Markets": es4p2,
"timestamp": es5p2
}
)
sim_config = {
"N": 1,
"T": range(1000)
}
# test return vs. non-return functions as lambdas
# test fully defined functions
mechanisms = {
"m1": {
"behaviors": {
"b1": b1m1,
"b3": b3m2,
"b7": b7m2,
"b7h": b7hm2
},
"states": {
"Z": s1m1,
"Buy_Log": s3m1
}
},
"m2": {
"behaviors": {
"b1": b1m2,
"b3": b3m2,
"b4": b4m2,
"b7": b7m2,
"b7h": b7hm2
},
"states": {
"Sell_Log": s4m2
}
},
"m3": {
"behaviors": {
},
"states": {
"Price": s2m3,
"Price_Signal": s5m3,
"Price_Signal_2": s6m3,
}
}
}
configs.append(Configuration(sim_config, state_dict, seed, exogenous_states, env_processes, mechanisms))

View File

@ -1,319 +0,0 @@
from decimal import Decimal
import numpy as np
from datetime import timedelta
from SimCAD import configs
from SimCAD.configuration import Configuration
from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \
ep_time_step
seed = {
'z': np.random.RandomState(1)
}
# Signals
# Pr_signal
beta = Decimal('0.25') # agent response gain
beta_LT = Decimal('0.1') # LT agent response gain
# alpha = .67, 2 block moving average
alpha = Decimal('0.67')
# 21 day EMA forgetfullness between 0 and 1, closer to 1 discounts older obs quicker, should be 2/(N+1)
# 21 * 3 mech steps, 2/64 = 0.03125
alpha_2 = Decimal('0.03125')
max_withdraw_factor = Decimal('0.9')
external_draw = Decimal('0.01') # between 0 and 1 to draw Buy_Log to external
#alpha * s['Zeus_ST'] + (1 - alpha)*s['Zeus_LT']
# Stochastic process factors
correction_factor = Decimal('0.01')
volatility = Decimal('5.0')
# Buy_Log_signal =
# Z_signal =
# Price_signal =
# TDR_draw_signal =
# P_Ext_Markets_signal =
# Behaviors per Mechanism
# BEHAVIOR 1: EMH Trader
EMH_portion = Decimal('0.20')
EMH_Ext_Hold = Decimal('42000.0')
def b1m1(step, sL, s):
# print('b1m1')
theta = (s['Z']*EMH_portion*s['Price'])/(s['Z']*EMH_portion*s['Price'] + EMH_Ext_Hold * s['P_Ext_Markets'])
if s['Price'] < (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
buy = beta * theta*EMH_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EMH_portion*(1-theta))
price = s['Price']
return {'EMH_buy': buy, 'EMH_buy_P': price}
elif s['Price'] > (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
price = 0
return {'EMH_buy': 0, 'EMH_buy_P': price}
else:
price = 0
return {'EMH_buy': 0, 'EMH_buy_P': price}
def b1m2(step, sL, s):
# print('b1m2')
theta = (s['Z']*EMH_portion*s['Price'])/(s['Z']*EMH_portion*s['Price'] + EMH_Ext_Hold * s['P_Ext_Markets'])
if s['Price'] < (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
return {'EMH_sell': 0}
elif s['Price'] > (theta*EMH_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*EMH_portion*(1-theta)):
sell = beta * theta*EMH_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EMH_portion*(1-theta))
price = s['Price']
return {'EMH_sell': sell, 'EMH_sell_P': price}
else:
return {'EMH_sell': 0}
# BEHAVIOR 3: Herding
Herd_portion = Decimal('0.20')
Herd_Ext_Hold = Decimal('42000.0')
Herd_UB = Decimal('0.10') # UPPER BOUND
Herd_LB = Decimal('0.10') # LOWER BOUND
def b3m2(step, sL, s):
theta = (s['Z']*Herd_portion*s['Price'])/(s['Z']*Herd_portion*s['Price'] + Herd_Ext_Hold * s['P_Ext_Markets'])
# if s['Price'] - s['Price_Signal'] < (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)) - Herd_LB:
if (s['Price'] - s['Price_Signal']) < - Herd_LB:
sell = beta * theta*Herd_Ext_Hold * s['P_Ext_Markets']/(s['Price']*Herd_portion*(1-theta))
price = s['Price'] - (s['Price_Signal'] / s['Price'])
return {'herd_sell': sell, 'herd_buy': 0, 'herd_sell_P': price}
# elif s['Price'] > Herd_UB - (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)):
elif (s['Price'] - s['Price_Signal']) > Herd_UB:
buy = beta * theta*Herd_Ext_Hold * s['P_Ext_Markets']/(s['Price']*Herd_portion*(1-theta))
price = s['Price'] + (s['Price'] / s['Price_Signal'])
return {'herd_sell': 0, 'herd_buy': buy, 'herd_buy_P': price}
else:
return {'herd_sell': 0, 'herd_buy': 0, 'herd_buy_P':0}
# BEHAVIOR 4: HODLers
HODL_belief = Decimal('10.0')
HODL_portion = Decimal('0.20')
HODL_Ext_Hold = Decimal('4200.0')
def b4m2(step, sL, s):
# print('b4m2')
theta = (s['Z']*HODL_portion*s['Price'])/(s['Z']*HODL_portion*s['Price'] + HODL_Ext_Hold * s['P_Ext_Markets'])
if s['Price'] < 1/HODL_belief*(theta*HODL_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*HODL_portion*(1-theta)):
sell = beta * theta*HODL_Ext_Hold * s['P_Ext_Markets']/(s['Price']*HODL_portion*(1-theta))
price = s['Price']
return {'HODL_sell': sell, 'HODL_sell_P': price}
elif s['Price'] > (theta*HODL_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*HODL_portion*(1-theta)):
return {'HODL_sell': 0}
else:
return {'HODL_sell': 0}
# BEHAVIOR 7: Endogenous Information Updating (EIU)
# Short Term Price Signal, Lower Threshold = BOT-like
EIU_portion = Decimal('0.20')
EIU_Ext_Hold = Decimal('42000.0')
EIU_UB = Decimal('0.50') # UPPER BOUND
EIU_LB = Decimal('0.50') # LOWER BOUND
def b7m2(step, sL, s):
theta = (s['Z']*EIU_portion*s['Price'])/(s['Z']*EIU_portion*s['Price'] + EIU_Ext_Hold * s['P_Ext_Markets'])
# if s['Price'] - s['Price_Signal'] < (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)) - Herd_LB:
if (s['Price'] - s['Price_Signal']) < - EIU_LB:
sell = beta * theta*EIU_Ext_Hold * s['P_Ext_Markets']/(s['Price']*EIU_portion*(1-theta))
price = s['Price'] + (s['Price_Signal'] / s['Price'])
return {'EIU_sell': sell, 'EIU_buy': 0, 'EIU_sell_P': price}
# elif s['Price'] > Herd_UB - (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)):
elif (s['Price'] - s['Price_Signal']) > EIU_UB:
buy = beta * theta* EIU_Ext_Hold * s['P_Ext_Markets']/(s['Price']* EIU_portion*(1-theta))
price = s['Price'] - (s['Price'] / s['Price_Signal'])
return {'EIU_sell': 0, 'EIU_buy': buy, 'EIU_buy_P': price}
else:
return {'EIU_sell': 0, 'EIU_buy': 0}
# BEHAVIOR 7b: Endogenous Information Updating (EIU)
# Longer Term Price Signal, Higher Threshold = Human-Like
HEIU_portion = Decimal('0.20')
HEIU_Ext_Hold = Decimal('42000.0')
HEIU_UB = Decimal('2.0') # UPPER BOUND
HEIU_LB = Decimal('2.0') # LOWER BOUND
def b7hm2(step, sL, s):
theta = (s['Z']*HEIU_portion*s['Price'])/(s['Z']*HEIU_portion*s['Price'] + HEIU_Ext_Hold * s['P_Ext_Markets'])
# if s['Price'] - s['Price_Signal'] < (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)) - Herd_LB:
if (s['Price'] - s['Price_Signal_2']) < - HEIU_LB:
sell = beta * theta* HEIU_Ext_Hold * s['P_Ext_Markets']/(s['Price']*HEIU_portion*(1-theta))
price = s['Price'] + (s['Price_Signal_2'] / s['Price'])
return {'HEIU_sell': sell, 'HEIU_buy': 0, 'HEIU_sell_P': price}
# elif s['Price'] > Herd_UB - (theta*Herd_Ext_Hold * s['P_Ext_Markets'])/(s['Z']*Herd_portion*(1-theta)):
elif (s['Price'] - s['Price_Signal_2']) > HEIU_UB:
buy = beta * theta* HEIU_Ext_Hold * s['P_Ext_Markets']/(s['Price']* HEIU_portion*(1-theta))
price = s['Price'] - (s['Price'] / s['Price_Signal_2'])
return {'HEIU_sell': 0, 'HEIU_buy': buy, 'HEIU_buy_P': price}
else:
return {'HEIU_sell': 0, 'HEIU_buy': 0}
# STATES
# ZEUS Fixed Supply
def s1m1(step, sL, s, _input):
y = 'Z'
x = s['Z'] #+ _input # / Psignal_int
return (y, x)
# def s2m1(step, sL, s, _input):
# y = 'Price'
# x = (s['P_Ext_Markets'] - _input['EMH_buy']) / s['Z'] * 10000
# #x= alpha * s['Z'] + (1 - alpha)*s['Price']
# return (y, x)
def s3m1(step, sL, s, _input):
y = 'Buy_Log'
x = np.zeros(4)
x[0] = _input['EMH_buy']
x[1] = _input['EMH_buy_P']
x[2] = _input['herd_buy']
x[3] = _input['herd_buy_P']
# = _input['EMH_buy'] + _input['herd_buy'] + _input['EIU_buy'] + _input['HEIU_buy'] # / Psignal_int
return (y, x) #[0], x[1])
def s4m2(step, sL, s, _input):
y = 'Sell_Log'
x = _input['EMH_sell'] + _input['HODL_sell'] + _input['herd_sell'] + _input['EIU_sell'] + _input['HEIU_sell'] # / Psignal_int
return (y, x)
# def s3m3(step, sL, s, _input):
# y = 'Buy_Log'
# x = s['Buy_Log'] + _input # / Psignal_int
# return (y, x)
# Price Update
def s2m3(step, sL, s, _input):
y = 'Price'
#var1 = Decimal.from_float(s['Buy_Log'])
x = s['Price'] + (Decimal(s['Buy_Log'][0] )) /s['Z'] # - (s['Sell_Log']/s['Z'] ) # for buy log term /s['Z'] )
#+ np.divide(s['Buy_Log'],s['Z']) - np.divide() # / Psignal_int
return (y, x)
def s5m3(step, sL, s, _input):
y = 'Price_Signal'
x = alpha * s['Price'] + (1 - alpha)*s['Price_Signal']
return (y, x)
def s6m3(step, sL, s, _input):
y = 'Price_Signal_2'
x = alpha_2 * s['Price'] + (1 - alpha_2)*s['Price_Signal_2']
return (y, x)
def s6m1(step, sL, s, _input):
y = 'P_Ext_Markets'
x = s['P_Ext_Markets'] - _input
#x= alpha * s['Z'] + (1 - alpha)*s['Price']
return (y, x)
# def s2m2(step, sL, s, _input):
# y = 'Price'
# x = (s['P_Ext_Markets'] - _input) /s['Z'] *10000
# x= alpha * s['Z'] + (1 - alpha)*s['Price']
# return (y, x)
# Exogenous States
proc_one_coef_A = -125
proc_one_coef_B = 125
# A change in belief of actual price, passed onto behaviors to make action
def es4p2(step, sL, s, _input):
y = 'P_Ext_Markets'
x = s['P_Ext_Markets'] + bound_norm_random(seed['z'], proc_one_coef_A, proc_one_coef_B)
return (y,x)
ts_format = '%Y-%m-%d %H:%M:%S'
t_delta = timedelta(days=0, minutes=0, seconds=1)
def es5p2(step, sL, s, _input):
y = 'timestamp'
x = ep_time_step(s, dt_str=s['timestamp'], fromat_str=ts_format, _timedelta=t_delta)
return (y, x)
#Environment States
# NONE
# Genesis States
state_dict = {
'Z': Decimal(21000000.0),
'Price': Decimal(100.0), # Initialize = Z for EMA
'Buy_Log': Decimal(0.0),
'Sell_Log': Decimal(0.0),
'Price_Signal': Decimal(100.0),
'Price_Signal_2': Decimal(100.0),
'Trans': Decimal(0.0),
'P_Ext_Markets': Decimal(25000.0),
'timestamp': '2018-10-01 15:16:24'
}
def env_proc_id(x):
return x
env_processes = {
# "P_Ext_Markets": env_proc_id
}
exogenous_states = exo_update_per_ts(
{
"P_Ext_Markets": es4p2,
"timestamp": es5p2
}
)
sim_config = {
"N": 1,
"T": range(1000)
}
# test return vs. non-return functions as lambdas
# test fully defined functions
mechanisms = {
"m1": {
"behaviors": {
"b1": b1m1,
"b3": b3m2,
"b7": b7m2,
"b7h": b7hm2
},
"states": {
"Z": s1m1,
"Buy_Log": s3m1
}
},
"m2": {
"behaviors": {
"b1": b1m2,
"b3": b3m2,
"b4": b4m2,
"b7": b7m2,
"b7h": b7hm2
},
"states": {
"Sell_Log": s4m2
}
},
"m3": {
"behaviors": {
},
"states": {
"Price": s2m3,
"Price_Signal": s5m3,
"Price_Signal_2": s6m3,
}
}
}
configs.append(Configuration(sim_config, state_dict, seed, exogenous_states, env_processes, mechanisms))

View File

@ -1,44 +0,0 @@
import pandas as pd
from tabulate import tabulate
# The following imports NEED to be in the exact same order
from SimCAD.engine import ExecutionMode, ExecutionContext, Executor
from simulations.validation import config1, config2
# from simulations.validation import base_config1, base_config2
# from simulations.barlin import config4
# from simulations.zx import config_zx
# from simulations.barlin import config6atemp #config6aworks,
from SimCAD import configs
# ToDo: pass ExecutionContext with execution method as ExecutionContext input
exec_mode = ExecutionMode()
print("Simulation Execution 1")
print()
first_config = [configs[0]] # from config1
single_proc_ctx = ExecutionContext(context=exec_mode.single_proc)
run1 = Executor(exec_context=single_proc_ctx, configs=first_config)
run1_raw_result, tensor_field = run1.main()
result = pd.DataFrame(run1_raw_result)
# result.to_csv('~/Projects/DiffyQ-SimCAD/results/config4.csv', sep=',')
print()
print("Tensor Field:")
print(tabulate(tensor_field, headers='keys', tablefmt='psql'))
print("Output:")
print(tabulate(result, headers='keys', tablefmt='psql'))
print()
print("Simulation Execution 2: Pairwise Execution")
print()
multi_proc_ctx = ExecutionContext(context=exec_mode.multi_proc)
run2 = Executor(exec_context=multi_proc_ctx, configs=configs)
for raw_result, tensor_field in run2.main():
result = pd.DataFrame(raw_result)
print()
print("Tensor Field:")
print(tabulate(tensor_field, headers='keys', tablefmt='psql'))
print("Output:")
print(tabulate(result, headers='keys', tablefmt='psql'))
print()

View File

@ -1,171 +0,0 @@
from decimal import Decimal
import numpy as np
from datetime import timedelta
from SimCAD import configs
from SimCAD.configuration import Configuration
from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \
ep_time_step
seed = {
'z': np.random.RandomState(1),
'a': np.random.RandomState(2),
'b': np.random.RandomState(3),
'c': np.random.RandomState(3)
}
# Behaviors per Mechanism
# Different return types per mechanism ?? *** No ***
def b1m1(step, sL, s):
return {'param1': 1}
def b2m1(step, sL, s):
return {'param1': 1}
def b1m2(step, sL, s):
return {'param1': 1, 'param2': 2}
def b2m2(step, sL, s):
return {'param1': 1, 'param2': 4}
def b1m3(step, sL, s):
return {'param1': 1, 'param2': np.array([10, 100])}
def b2m3(step, sL, s):
return {'param1': 1, 'param2': np.array([20, 200])}
# deff not more than 2
# Internal States per Mechanism
def s1m1(step, sL, s, _input):
y = 's1'
x = s['s1'] + _input['param1']
return (y, x)
def s2m1(step, sL, s, _input):
y = 's2'
x = s['s2'] + _input['param1']
return (y, x)
def s1m2(step, sL, s, _input):
y = 's1'
x = s['s1'] + _input['param1']
return (y, x)
def s2m2(step, sL, s, _input):
y = 's2'
x = s['s2'] + _input['param1']
return (y, x)
def s1m3(step, sL, s, _input):
y = 's1'
x = s['s1'] + _input['param1']
return (y, x)
def s2m3(step, sL, s, _input):
y = 's2'
x = s['s2'] + _input['param1']
return (y, x)
# Exogenous States
proc_one_coef_A = 0.7
proc_one_coef_B = 1.3
def es3p1(step, sL, s, _input):
y = 's3'
x = s['s3'] * bound_norm_random(seed['a'], proc_one_coef_A, proc_one_coef_B)
return (y, x)
def es4p2(step, sL, s, _input):
y = 's4'
x = s['s4'] * bound_norm_random(seed['b'], proc_one_coef_A, proc_one_coef_B)
return (y, x)
ts_format = '%Y-%m-%d %H:%M:%S'
t_delta = timedelta(days=0, minutes=0, seconds=1)
def es5p2(step, sL, s, _input):
y = 'timestamp'
x = ep_time_step(s, dt_str=s['timestamp'], fromat_str=ts_format, _timedelta=t_delta)
return (y, x)
# Environment States
def env_a(x):
return 10
def env_b(x):
return 10
# def what_ever(x):
# return x + 1
# Genesis States
genesis_states = {
's1': Decimal(0.0),
's2': Decimal(0.0),
's3': Decimal(1.0),
's4': Decimal(1.0),
'timestamp': '2018-10-01 15:16:24'
}
# remove `exo_update_per_ts` to update every ts
exogenous_states = exo_update_per_ts(
{
"s3": es3p1,
"s4": es4p2,
"timestamp": es5p2
}
)
# make env proc trigger field agnostic
# ToDo: Bug - Can't use environments without proc_trigger. TypeError: 'int' object is not callable
# "/Users/jjodesty/Projects/DiffyQ-SimCAD/SimCAD/engine/simulation.py"
env_processes = {
# "s3": env_a,
# "s4": env_b
"s3": proc_trigger('2018-10-01 15:16:25', env_a),
"s4": proc_trigger('2018-10-01 15:16:25', env_b)
}
# need at least 1 behaviour and 1 state function for the 1st mech with behaviors
# mechanisms = {}
mechanisms = {
"m1": {
"behaviors": {
"b1": b1m1, # lambda step, sL, s: s['s1'] + 1,
"b2": b2m1
},
"states": { # exclude only. TypeError: reduce() of empty sequence with no initial value
"s1": s1m1,
"s2": s2m1
}
},
"m2": {
"behaviors": {
"b1": b1m2,
"b2": b2m2
},
"states": {
"s1": s1m2,
"s2": s2m2
}
},
"m3": {
"behaviors": {
"b1": b1m3,
"b2": b2m3
},
"states": {
"s1": s1m3,
"s2": s2m3
}
}
}
sim_config = {
"N": 2,
"T": range(5)
}
configs.append(
Configuration(
sim_config=sim_config,
state_dict=genesis_states,
seed=seed,
exogenous_states=exogenous_states,
env_processes=env_processes,
mechanisms=mechanisms
)
)

View File

@ -1,180 +0,0 @@
from decimal import Decimal
import numpy as np
from datetime import timedelta
from SimCAD import configs
from SimCAD.configuration import Configuration
from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \
ep_time_step
seed = {
'z': np.random.RandomState(1),
'a': np.random.RandomState(2),
'b': np.random.RandomState(3),
'c': np.random.RandomState(3)
}
# Behaviors per Mechanism
# Different return types per mechanism ?? *** No ***
def b1m1(step, sL, s):
return {'param1': 1}
def b2m1(step, sL, s):
return {'param2': 4}
def b1m2(step, sL, s):
return {'param1': 'a', 'param2': 2}
def b2m2(step, sL, s):
return {'param1': 'b', 'param2': 4}
def b1m3(step, sL, s):
return {'param1': ['c'], 'param2': np.array([10, 100])}
def b2m3(step, sL, s):
return {'param1': ['d'], 'param2': np.array([20, 200])}
# Internal States per Mechanism
def s1m1(step, sL, s, _input):
y = 's1'
x = _input['param1']
return (y, x)
def s2m1(step, sL, s, _input):
y = 's2'
x = _input['param2']
return (y, x)
def s1m2(step, sL, s, _input):
y = 's1'
x = _input['param1']
return (y, x)
def s2m2(step, sL, s, _input):
y = 's2'
x = _input['param2']
return (y, x)
def s1m3(step, sL, s, _input):
y = 's1'
x = _input['param1']
return (y, x)
def s2m3(step, sL, s, _input):
y = 's2'
x = _input['param2']
return (y, x)
# Exogenous States
proc_one_coef_A = 0.7
proc_one_coef_B = 1.3
def es3p1(step, sL, s, _input):
y = 's3'
x = s['s3'] * bound_norm_random(seed['a'], proc_one_coef_A, proc_one_coef_B)
return (y, x)
def es4p2(step, sL, s, _input):
y = 's4'
x = s['s4'] * bound_norm_random(seed['b'], proc_one_coef_A, proc_one_coef_B)
return (y, x)
ts_format = '%Y-%m-%d %H:%M:%S'
t_delta = timedelta(days=0, minutes=0, seconds=1)
def es5p2(step, sL, s, _input):
y = 'timestamp'
x = ep_time_step(s, dt_str=s['timestamp'], fromat_str=ts_format, _timedelta=t_delta)
return (y, x)
# Environment States
def env_a(x):
return 10
def env_b(x):
return 10
# def what_ever(x):
# return x + 1
# Genesis States
genesis_states = {
's1': Decimal(0.0),
's2': Decimal(0.0),
's3': Decimal(1.0),
's4': Decimal(1.0),
'timestamp': '2018-10-01 15:16:24'
}
# remove `exo_update_per_ts` to update every ts
# why `exo_update_per_ts` here instead of `env_processes`
exogenous_states = exo_update_per_ts(
{
"s3": es3p1,
"s4": es4p2,
"timestamp": es5p2
}
)
# make env proc trigger field agnostic
env_processes = {
"s3": proc_trigger('2018-10-01 15:16:25', env_a),
"s4": proc_trigger('2018-10-01 15:16:25', env_b)
}
# lambdas
# genesis Sites should always be there
# [1, 2]
# behavior_ops = [ foldr(_ + _), lambda x: x + 0 ]
# [1, 2] = {'b1': ['a'], 'b2', [1]} =
# behavior_ops = [behavior_to_dict, print_fwd, sum_dict_values]
# behavior_ops = [foldr(dict_elemwise_sum())]
# behavior_ops = []
# need at least 1 behaviour and 1 state function for the 1st mech with behaviors
# mechanisms = {}
mechanisms = {
"m1": {
"behaviors": {
"b1": b1m1, # lambda step, sL, s: s['s1'] + 1,
# "b2": b2m1
},
"states": { # exclude only. TypeError: reduce() of empty sequence with no initial value
"s1": s1m1,
# "s2": s2m1
}
},
"m2": {
"behaviors": {
"b1": b1m2,
# "b2": b2m2
},
"states": {
"s1": s1m2,
# "s2": s2m2
}
},
"m3": {
"behaviors": {
"b1": b1m3,
"b2": b2m3
},
"states": {
"s1": s1m3,
"s2": s2m3
}
}
}
sim_config = {
"N": 2,
"T": range(5)
}
configs.append(
Configuration(
sim_config=sim_config,
state_dict=genesis_states,
seed=seed,
exogenous_states=exogenous_states,
env_processes=env_processes,
mechanisms=mechanisms
)
)

View File

@ -1,176 +0,0 @@
from decimal import Decimal
import numpy as np
from datetime import timedelta
from SimCAD import configs
from SimCAD.configuration import Configuration
from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \
ep_time_step
seed = {
'z': np.random.RandomState(1),
'a': np.random.RandomState(2),
'b': np.random.RandomState(3),
'c': np.random.RandomState(3)
}
# Behaviors per Mechanism
# Different return types per mechanism ?? *** No ***
def b1m1(step, sL, s):
return {'param1': 1}
def b2m1(step, sL, s):
return {'param2': 4}
def b1m2(step, sL, s):
return {'param1': 'a', 'param2': 2}
def b2m2(step, sL, s):
return {'param1': 'b', 'param2': 4}
def b1m3(step, sL, s):
return {'param1': ['c'], 'param2': np.array([10, 100])}
def b2m3(step, sL, s):
return {'param1': ['d'], 'param2': np.array([20, 200])}
# deff not more than 2
# Internal States per Mechanism
def s1m1(step, sL, s, _input):
y = 's1'
x = _input['param1'] #+ [Coef1 x 5]
return (y, x)
def s2m1(step, sL, s, _input):
y = 's2'
x = _input['param2'] #+ [Coef2 x 5]
return (y, x)
def s1m2(step, sL, s, _input):
y = 's1'
x = _input['param1']
return (y, x)
def s2m2(step, sL, s, _input):
y = 's2'
x = _input['param2']
return (y, x)
def s1m3(step, sL, s, _input):
y = 's1'
x = _input['param1']
return (y, x)
def s2m3(step, sL, s, _input):
y = 's2'
x = _input['param2']
return (y, x)
# Exogenous States
proc_one_coef_A = 0.7
proc_one_coef_B = 1.3
def es3p1(step, sL, s, _input):
y = 's3'
x = s['s3'] * bound_norm_random(seed['a'], proc_one_coef_A, proc_one_coef_B)
return (y, x)
def es4p2(step, sL, s, _input):
y = 's4'
x = s['s4'] * bound_norm_random(seed['b'], proc_one_coef_A, proc_one_coef_B)
return (y, x)
ts_format = '%Y-%m-%d %H:%M:%S'
t_delta = timedelta(days=0, minutes=0, seconds=1)
def es5p2(step, sL, s, _input):
y = 'timestamp'
x = ep_time_step(s, dt_str=s['timestamp'], fromat_str=ts_format, _timedelta=t_delta)
return (y, x)
# Environment States
def env_a(x):
return 10
def env_b(x):
return 10
# def what_ever(x):
# return x + 1
# Genesis States
genesis_states = {
's1': Decimal(0.0),
's2': Decimal(0.0),
's3': Decimal(1.0),
's4': Decimal(1.0),
'timestamp': '2018-10-01 15:16:24'
}
# remove `exo_update_per_ts` to update every ts
exogenous_states = exo_update_per_ts(
{
"s3": es3p1,
"s4": es4p2,
"timestamp": es5p2
}
)
# make env proc trigger field agnostic
env_processes = {
"s3": proc_trigger('2018-10-01 15:16:25', env_a),
"s4": proc_trigger('2018-10-01 15:16:25', env_b)
}
# lambdas
# genesis Sites should always be there
# [1, 2]
# behavior_ops = [ foldr(_ + _), lambda x: x + 0 ]
# [1, 2] = {'b1': ['a'], 'b2', [1]} =
# behavior_ops = [ behavior_to_dict, print_fwd, sum_dict_values ]
# behavior_ops = [foldr(dict_elemwise_sum())]
# behavior_ops = [foldr(lambda a, b: a + b)]
# need at least 1 behaviour and 1 state function for the 1st mech with behaviors
# mechanisms = {}
mechanisms = {
"m1": {
"behaviors": {
"b1": b1m1, # lambda step, sL, s: s['s1'] + 1,
"b2": b2m1
},
"states": { # exclude only. TypeError: reduce() of empty sequence with no initial value
"s1": s1m1,
"s2": s2m1
}
},
"m2": {
"behaviors": {
"b1": b1m2,
"b2": b2m2
},
"states": {
"s1": s1m2,
"s2": s2m2
}
},
"m3": {
"behaviors": {
"b1": b1m3,
"b2": b2m3
},
"states": {
"s1": s1m3,
"s2": s2m3
}
}
}
sim_config = {
"N": 2,
"T": range(5)
}
configs.append(
Configuration(
sim_config=sim_config,
state_dict=genesis_states,
seed=seed,
exogenous_states=exogenous_states,
env_processes=env_processes,
mechanisms=mechanisms
)
)

View File

@ -1,180 +0,0 @@
from decimal import Decimal
import numpy as np
from datetime import timedelta
from SimCAD import configs
from SimCAD.configuration import Configuration
from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \
ep_time_step
seed = {
'z': np.random.RandomState(1),
'a': np.random.RandomState(2),
'b': np.random.RandomState(3),
'c': np.random.RandomState(3)
}
# Behaviors per Mechanism
# Different return types per mechanism ?? *** No ***
def b1m1(step, sL, s):
return {'param1': 1}
def b2m1(step, sL, s):
return {'param2': 4}
def b1m2(step, sL, s):
return {'param1': 'a', 'param2': 2}
def b2m2(step, sL, s):
return {'param1': 'b', 'param2': 4}
def b1m3(step, sL, s):
return {'param1': ['c'], 'param2': np.array([10, 100])}
def b2m3(step, sL, s):
return {'param1': ['d'], 'param2': np.array([20, 200])}
# Internal States per Mechanism
def s1m1(step, sL, s, _input):
y = 's1'
x = _input['param1']
return (y, x)
def s2m1(step, sL, s, _input):
y = 's2'
x = _input['param2']
return (y, x)
def s1m2(step, sL, s, _input):
y = 's1'
x = _input['param1']
return (y, x)
def s2m2(step, sL, s, _input):
y = 's2'
x = _input['param2']
return (y, x)
def s1m3(step, sL, s, _input):
y = 's1'
x = _input['param1']
return (y, x)
def s2m3(step, sL, s, _input):
y = 's2'
x = _input['param2']
return (y, x)
# Exogenous States
proc_one_coef_A = 0.7
proc_one_coef_B = 1.3
def es3p1(step, sL, s, _input):
y = 's3'
x = s['s3'] * bound_norm_random(seed['a'], proc_one_coef_A, proc_one_coef_B)
return (y, x)
def es4p2(step, sL, s, _input):
y = 's4'
x = s['s4'] * bound_norm_random(seed['b'], proc_one_coef_A, proc_one_coef_B)
return (y, x)
ts_format = '%Y-%m-%d %H:%M:%S'
t_delta = timedelta(days=0, minutes=0, seconds=1)
def es5p2(step, sL, s, _input):
y = 'timestamp'
x = ep_time_step(s, dt_str=s['timestamp'], fromat_str=ts_format, _timedelta=t_delta)
return (y, x)
# Environment States
def env_a(x):
return 10
def env_b(x):
return 10
# def what_ever(x):
# return x + 1
# Genesis States
genesis_states = {
's1': Decimal(0.0),
's2': Decimal(0.0),
's3': Decimal(1.0),
's4': Decimal(1.0),
'timestamp': '2018-10-01 15:16:24'
}
# remove `exo_update_per_ts` to update every ts
# why `exo_update_per_ts` here instead of `env_processes`
exogenous_states = exo_update_per_ts(
{
"s3": es3p1,
"s4": es4p2,
"timestamp": es5p2
}
)
# make env proc trigger field agnostic
env_processes = {
"s3": proc_trigger('2018-10-01 15:16:25', env_a),
"s4": proc_trigger('2018-10-01 15:16:25', env_b)
}
# lambdas
# genesis Sites should always be there
# [1, 2]
# behavior_ops = [ foldr(_ + _), lambda x: x + 0 ]
# [1, 2] = {'b1': ['a'], 'b2', [1]} =
# behavior_ops = [behavior_to_dict, print_fwd, sum_dict_values]
# behavior_ops = [foldr(dict_elemwise_sum())]
# behavior_ops = []
# need at least 1 behaviour and 1 state function for the 1st mech with behaviors
# mechanisms = {}
mechanisms = {
"m1": {
"behaviors": {
"b1": b1m1, # lambda step, sL, s: s['s1'] + 1,
# "b2": b2m1
},
"states": { # exclude only. TypeError: reduce() of empty sequence with no initial value
"s1": s1m1,
# "s2": s2m1
}
},
"m2": {
"behaviors": {
"b1": b1m2,
# "b2": b2m2
},
"states": {
"s1": s1m2,
# "s2": s2m2
}
},
"m3": {
"behaviors": {
"b1": b1m3,
"b2": b2m3
},
"states": {
"s1": s1m3,
"s2": s2m3
}
}
}
sim_config = {
"N": 2,
"T": range(5)
}
configs.append(
Configuration(
sim_config=sim_config,
state_dict=genesis_states,
seed=seed,
exogenous_states=exogenous_states,
env_processes=env_processes,
mechanisms=mechanisms
)
)

View File

@ -1,156 +0,0 @@
from decimal import Decimal
import numpy as np
from datetime import timedelta
from SimCAD import configs
from SimCAD.configuration import Configuration
from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \
ep_time_step
seed = {
'z': np.random.RandomState(1),
'a': np.random.RandomState(2),
'b': np.random.RandomState(3),
'c': np.random.RandomState(3)
}
# Behaviors per Mechanism
def b1m1(step, sL, s):
return s['s1'] + 1
def b2m1(step, sL, s):
return s['s1'] + 1
def b1m2(step, sL, s):
return s['s1'] + 1
def b2m2(step, sL, s):
return s['s1'] + 1
def b1m3(step, sL, s):
return s['s1'] + 1
def b2m3(step, sL, s):
return s['s2'] + 1
# Internal States per Mechanism
def s1m1(step, sL, s, _input):
y = 's1'
x = s['s1'] + _input
return (y, x)
def s2m1(step, sL, s, _input):
y = 's2'
x = s['s2'] + _input
return (y, x)
def s1m2(step, sL, s, _input):
y = 's1'
x = s['s1'] + _input
return (y, x)
def s2m2(step, sL, s, _input):
y = 's2'
x = s['s2'] + _input
return (y, x)
def s1m3(step, sL, s, _input):
y = 's1'
x = s['s1'] + _input
return (y, x)
def s2m3(step, sL, s, _input):
y = 's2'
x = s['s2'] + s['s3'] + _input
return (y, x)
# Exogenous States
proc_one_coef_A = 0.7
proc_one_coef_B = 1.3
def es3p1(step, sL, s, _input):
y = 's3'
x = s['s3'] * bound_norm_random(seed['a'], proc_one_coef_A, proc_one_coef_B)
return (y, x)
def es4p2(step, sL, s, _input):
y = 's4'
x = s['s4'] * bound_norm_random(seed['b'], proc_one_coef_A, proc_one_coef_B)
return (y, x)
def es5p2(step, sL, s, _input): # accept timedelta instead of timedelta params
y = 'timestamp'
x = ep_time_step(s, s['timestamp'], seconds=1)
return (y, x)
# Environment States
def env_a(x):
return 10
def env_b(x):
return 10
# def what_ever(x):
# return x + 1
# Genesis States
state_dict = {
's1': Decimal(0.0),
's2': Decimal(0.0),
's3': Decimal(1.0),
's4': Decimal(1.0),
'timestamp': '2018-10-01 15:16:24'
}
exogenous_states = exo_update_per_ts(
{
"s3": es3p1,
"s4": es4p2,
"timestamp": es5p2
}
)
env_processes = {
"s3": proc_trigger('2018-10-01 15:16:25', env_a),
"s4": proc_trigger('2018-10-01 15:16:25', env_b)
}
# lambdas
# genesis Sites should always be there
# [1, 2]
# User Defined Aggregate Function
behavior_udaf = [ foldr(_ + _), lambda x: x + 0 ]
# need at least 1 behaviour and 1 state function for the 1st mech with behaviors
mechanisms = {
"m1": {
"behaviors": {
"b1": b1m1, # lambda step, sL, s: s['s1'] + 1,
"b2": b2m1
},
"states": { # exclude only. TypeError: reduce() of empty sequence with no initial value
"s1": s1m1,
"s2": s2m1
}
},
"m2": {
"behaviors": {
"b1": b1m2,
"b2": b2m2
},
"states": {
"s1": s1m2,
"s2": s2m2
}
},
"m3": {
"behaviors": {
"b1": b1m3,
"b2": b2m3
},
"states": {
"s1": s1m3,
"s2": s2m3
}
}
}
sim_config = {
"N": 2,
"T": range(5)
}
configs.append(Configuration(sim_config, state_dict, seed, exogenous_states, env_processes, mechanisms, behavior_udaf))