Merge 'staging's' core architecture into 'param-sweep-multi-proc'

This commit is contained in:
Joshua E. Jodesty 2019-01-28 13:45:29 -05:00
commit e06cb00536
44 changed files with 2552 additions and 711663 deletions

11
.gitignore vendored
View File

@ -1,12 +1,17 @@
.idea
.ipynb_checkpoints
.DS_Store
.idea
notebooks/.ipynb_checkpoints
notebooks/multithreading.ipynb
notebooks
SimCAD.egg-info
__pycache__
Pipfile
Pipfile.lock
results
.mypy_cache
simulations/scrapbox
*.csv
*.txt
simulations/.ipynb_checkpoints
build
SimCAD.egg-info

View File

@ -1,52 +1,53 @@
# SimCad
**Warning**:
**Do not** publish this package / software to **any** software repository **except** one permitted by BlockScience.
**Dependencies:**
**Description:**
SimCAD is a differential games based simulation software package for research, validation, and Computer \
Aided Design of economic systems. An economic system is treated as a state based model and defined through a \
set of endogenous and exogenous state variables which are updated through mechanisms and environmental \
processes, respectively. Behavioral models, which may be deterministic or stochastic, provide the evolution of \
the system within the action space of the mechanisms. Mathematical formulations of these economic games \
treat agent utility as derived from state rather than direct from action, creating a rich dynamic modeling framework.
Simulations may be run with a range of initial conditions and parameters for states, behaviors, mechanisms, \
and environmental processes to understand and visualize network behavior under various conditions. Support for \
A/B testing policies, monte carlo analysis and other common numerical methods is provided.
SimCAD is written in Python 3.
**1. Install Dependencies:**
```bash
pip install -r requirements.txt
python3 setup.py sdist bdist_wheel
pip install dist/SimCAD-0.1-py3-none-any.whl
```
**Project:**
**2. Configure Simulation:**
Example Runs:
`/simulations/sim_test.py`
Intructions:
`/Simulation.md`
Example Configurations:
`/simulations/validation/`
Examples:
`/simulations/validation/*`
**User Interface: Simulation Configuration**
**3. Import SimCAD & Run Simulation:**
Configurations:
```bash
/DiffyQ-SimCAD/ui/config.py
```
Examples: `/simulations/example_run.py` or `/simulations/example_run.ipynb`
**Build Tool & Package Import:**
Step 1. Build & Install Package locally:
```bash
pip install .
pip install -e .
```
* [Package Creation Tutorial](https://python-packaging.readthedocs.io/en/latest/minimal.html)
Step 2. Import Package & Run:
`/simulations/example_run.py`:
```python
import pandas as pd
from tabulate import tabulate
# The following imports NEED to be in the exact same order
# The following imports NEED to be in the exact order
from SimCAD.engine import ExecutionMode, ExecutionContext, Executor
from simulations.validation import config1, config2
from validation import config1, config2
from SimCAD import configs
# ToDo: pass ExecutionContext with execution method as ExecutionContext input
exec_mode = ExecutionMode()
exec_mode = ExecutionMode()
print("Simulation Execution 1")
print()
first_config = [configs[0]] # from config1
@ -54,7 +55,6 @@ 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'))
@ -76,14 +76,7 @@ for raw_result, tensor_field in run2.main():
print()
```
Same can be run in Jupyter .
The above can be run in Jupyter.
```bash
jupyter notebook
```
Notebooks Directory:
`/DiffyQ-SimCAD/notebooks/`
**Warning**:
**Do Not** publish this package / software to **Any** software repository **except** [DiffyQ-SimCAD's staging branch](https://github.com/BlockScience/DiffyQ-SimCAD/tree/staging) or its **Fork**

View File

@ -1 +1,2 @@
configs = []
name = "SimCAD"
configs = []

View File

@ -51,7 +51,6 @@ class Processor:
self.state_identity = id.state_identity
self.apply_identity_funcs = id.apply_identity_funcs
# Make returntype chosen by user.
def create_matrix_field(self, mechanisms, key):
if key == 'states':
identity = self.state_identity
@ -64,11 +63,8 @@ class Processor:
else:
return pd.DataFrame({'empty': []})
# Maybe Refactor to only use dictionary BUT I used dfs to fill NAs. Perhaps fill
def generate_config(self, state_dict, mechanisms, exo_proc):
# ToDo: include False / False case
# ToDo: Use Range multiplier instead for loop iterator
def no_update_handler(bdf, sdf):
if (bdf.empty == False) and (sdf.empty == True):
bdf_values = bdf.values.tolist()
@ -100,4 +96,4 @@ class Processor:
sdf_values, bdf_values = only_ep_handler(state_dict)
zipped_list = list(zip(sdf_values, bdf_values))
return list(map(lambda x: (x[0] + exo_proc, x[1]), zipped_list))
return list(map(lambda x: (x[0] + exo_proc, x[1]), zipped_list))

View File

@ -12,7 +12,6 @@ class TensorFieldReport:
def __init__(self, config_proc):
self.config_proc = config_proc
# ??? dont for-loop to apply exo_procs, use exo_proc struct
def create_tensor_field(self, mechanisms, exo_proc, keys=['behaviors', 'states']):
dfs = [self.config_proc.create_matrix_field(mechanisms, k) for k in keys]
df = pd.concat(dfs, axis=1)
@ -31,7 +30,6 @@ def state_update(y, x):
def bound_norm_random(rng, low, high):
# Add RNG Seed
res = rng.normal((high+low)/2,(high-low)/6)
if (res<low or res>high):
res = bound_norm_random(rng, low, high)
@ -46,7 +44,6 @@ def proc_trigger(trigger_step, update_f, step):
return lambda x: x
# accept timedelta instead of timedelta params
t_delta = timedelta(days=0, minutes=0, seconds=30)
def time_step(dt_str, dt_format='%Y-%m-%d %H:%M:%S', _timedelta = t_delta):
dt = datetime.strptime(dt_str, dt_format)
@ -54,7 +51,6 @@ def time_step(dt_str, dt_format='%Y-%m-%d %H:%M:%S', _timedelta = t_delta):
return t.strftime(dt_format)
# accept timedelta instead of timedelta params
t_delta = timedelta(days=0, minutes=0, seconds=1)
def ep_time_step(s, dt_str, fromat_str='%Y-%m-%d %H:%M:%S', _timedelta = t_delta):
if s['mech_step'] == 0:
@ -63,22 +59,6 @@ def ep_time_step(s, dt_str, fromat_str='%Y-%m-%d %H:%M:%S', _timedelta = t_delta
return dt_str
def exo_update_per_ts(ep):
@curried
def ep_decorator(fs, y, step, sL, s, _input):
# print(s)
if s['mech_step'] + 1 == 1: # inside f body to reduce performance costs
if isinstance(fs, list):
pool = ThreadPool(nodes=len(fs))
fx = pool.map(lambda f: f(step, sL, s, _input), fs)
return groupByKey(fx)
else:
return fs(step, sL, s, _input)
else:
return (y, s[y])
return {es: ep_decorator(f, es) for es, f in ep.items()}
def mech_sweep_filter(mech_field, mechanisms):
mech_dict = dict([(k, v[mech_field]) for k, v in mechanisms.items()])
return dict([
@ -129,6 +109,7 @@ def sweep_states(state_type, states, in_config):
return configs
def param_sweep(config, raw_exogenous_states):
return flatMap(
sweep_states('environmental', config.env_processes),
@ -139,4 +120,22 @@ def param_sweep(config, raw_exogenous_states):
sweep_mechs('behaviors', config)
)
)
)
)
def exo_update_per_ts(ep):
@curried
def ep_decorator(f, y, step, sL, s, _input):
if s['mech_step'] + 1 == 1:
return f(step, sL, s, _input)
else:
return (y, s[y])
return {es: ep_decorator(f, es) for es, f in ep.items()}
# def ep_decorator(f, y, step, sL, s, _input):
# if s['mech_step'] + 1 == 1:
# return f(step, sL, s, _input)
# else:
# return (y, s[y])
# return {es: ep_decorator(f, es) for es, f in ep.items()}

View File

@ -28,8 +28,7 @@ def foldr_dict_vals(f, d):
def sum_dict_values():
return foldr_dict_vals(add)
# AttributeError: 'int' object has no attribute 'keys'
# config7c
@curried
def dict_op(f, d1, d2):
def set_base_value(target_dict, source_dict, key):
@ -45,6 +44,3 @@ def dict_op(f, d1, d2):
def dict_elemwise_sum():
return dict_op(add)
# class BehaviorAggregation:

View File

@ -11,7 +11,6 @@ class ExecutionMode:
multi_proc = 'multi_proc'
# ToDo: switch / rename self.name & context ??
class ExecutionContext:
def __init__(self, context=ExecutionMode.multi_proc):
self.name = context
@ -43,9 +42,7 @@ class Executor:
self.configs = configs
self.main = self.execute
def execute(self):
config_proc = Processor()
create_tensor_field = TensorFieldReport(config_proc).create_tensor_field
@ -65,8 +62,6 @@ class Executor:
config_idx += 1
# Dimensions: N x r x mechs
if self.exec_context == ExecutionMode.single_proc:
tensor_field = create_tensor_field(mechanisms.pop(), eps.pop())
result = self.exec_method(simulation_execs, states_lists, configs_structs, env_processes_list, Ts, Ns)
@ -77,4 +72,5 @@ class Executor:
results = []
for result, mechanism, ep in list(zip(simulations, mechanisms, eps)):
results.append((flatten(result), create_tensor_field(mechanism, ep)))
return results
return results

View File

@ -1,10 +1,7 @@
from copy import deepcopy
from fn.op import foldr, call
from SimCAD.utils import rename
from SimCAD.engine.utils import engine_exception
id_exception = engine_exception(KeyError, KeyError, None)
@ -14,7 +11,6 @@ class Executor:
self.state_update_exception = state_update_exception
self.behavior_update_exception = behavior_update_exception
# Data Type reduction
def get_behavior_input(self, step, sL, s, funcs):
ops = self.behavior_ops[::-1]
@ -27,12 +23,11 @@ class Executor:
for state in state_dict.keys():
if state in list(env_processes.keys()):
env_state = env_processes[state]
if (env_state.__name__ == '_curried') or (env_state.__name__ == 'proc_trigger'): # might want to change
if (env_state.__name__ == '_curried') or (env_state.__name__ == 'proc_trigger'):
state_dict[state] = env_state(step)(state_dict[state])
else:
state_dict[state] = env_state(state_dict[state])
def mech_step(self, m_step, sL, state_funcs, behavior_funcs, env_processes, t_step, run):
last_in_obj = sL[-1]
@ -40,10 +35,13 @@ class Executor:
# ToDo: add env_proc generator to `last_in_copy` iterator as wrapper function
# last_in_copy = dict([self.behavior_update_exception(f(m_step, sL, last_in_obj, _input)) for f in state_funcs])
for f in state_funcs:
print(f(1,2,3,4))
last_in_copy = [self.behavior_update_exception(f(m_step, sL, last_in_obj, _input)) for f in state_funcs]
print(last_in_copy)
exit()
#
# for f in state_funcs:
# print(f(1,2,3,4))
# exit()
for k in last_in_obj:
if k not in last_in_copy:
@ -51,8 +49,7 @@ class Executor:
del last_in_obj
# make env proc trigger field agnostic
self.apply_env_proc(env_processes, last_in_copy, last_in_copy['timestamp']) # mutating last_in_copy
self.apply_env_proc(env_processes, last_in_copy, last_in_copy['timestamp'])
last_in_copy["mech_step"], last_in_copy["time_step"], last_in_copy['run'] = m_step, t_step, run
sL.append(last_in_copy)
@ -63,8 +60,6 @@ class Executor:
def mech_pipeline(self, states_list, configs, env_processes, t_step, run):
m_step = 0
states_list_copy = deepcopy(states_list)
# print(states_list_copy)
# remove copy
genesis_states = states_list_copy[-1]
genesis_states['mech_step'], genesis_states['time_step'] = m_step, t_step
states_list = [genesis_states]
@ -91,12 +86,13 @@ class Executor:
return simulation_list
# ToDo: Muiltithreaded Runs
def simulation(self, states_list, configs, env_processes, time_seq, runs):
pipe_run = []
for run in range(runs):
run += 1
states_list_copy = deepcopy(states_list) # WHY ???
states_list_copy = deepcopy(states_list)
head, *tail = self.block_pipeline(states_list_copy, configs, env_processes, time_seq, run)
genesis = head.pop()
genesis['mech_step'], genesis['time_step'], genesis['run'] = 0, 0, run
@ -104,4 +100,4 @@ class Executor:
pipe_run += [first_timestep_per_run] + tail
del states_list_copy
return pipe_run
return pipe_run

View File

@ -54,6 +54,7 @@ def key_filter(l, keyname):
return [v[keyname] for k, v in l.items()]
def groupByKey(l):
d = defaultdict(list)
for key, value in l:
@ -70,4 +71,4 @@ def rename(new_name, f):
# def decorator(f):
# f.__name__ = newname
# return f
# return decorator
# return decorator

BIN
dist/SimCAD-0.1-py3-none-any.whl vendored Normal file

Binary file not shown.

150
licenses/AGREEMENT.txt Normal file
View File

@ -0,0 +1,150 @@
SOFTWARE LICENSE AGREEMENT
This Software License Agreement (the “Agreement”) is entered into as of December __ 2018, (the “Effective Date”) between
Dapper Labs, Inc., a Canadian corporation having its principal place of business at 980-350 Howe Street,
Vancouver, BC V6Z 1N9 (“DLI”) and BlockScience, Inc., a California corporation with an address at 471 McAuley Street,
Oakland, CA 94609 (“BlockScience”). This Agreement includes the attached Exhibit A.
WHEREAS, DLI and BlockScience are parties to that certain Professional Services Agreement dated March 23, 2018 (the
“PSA”), pursuant to which BlockScience performed and is currently performing professional services and other development
work for DLI;
WHEREAS, as part of BlockSciences performance under the PSA, BlockScience developed certain “behaviour archetypes” and
“configuration of the Null Model”, which the parties agree are “Work Product” under the PSA;
WHEREAS, the parties agree that BlockSciences proprietary SimCAD software tool is considered “Contractor Technology”
under the PSA; and
WHEREAS, the parties wish to enter into this Agreement to clarify DLIs rights to use the SimCAD software tool on a
going-forward basis.
NOW, THEREFORE, for good and valuable consideration, the receipt and sufficiency of which is hereby acknowledged, DLI
and BlockScience agree as follows:
1. DEFINITIONS
(a) “Affiliate” means any entity that, directly or indirectly through one or more intermediaries, controls, is
controlled by, or is under common control with, DLI.
(b) “Documentation” means any manuals, documentation and other supporting materials related to the Software.
Documentation is considered part of the related Software.
(c) “Intellectual Property Rights” means patent rights (including patent applications and disclosures), copyrights,
trade marks, trade secrets, know-how and any other intellectual property rights recognized in any country or
jurisdiction in the world.
(d) “Software” means the object and source code versions of BlockSciences proprietary SimCAD software product more
fully described in Exhibit A. Software includes the applicable Documentation, as well as any Updates.
(e) “Update” means any bug fix, error correction, patch, modification, enhancement, update, upgrade, replacement,
successor product, new version, new release, or derivative work of or to the Software.
(f) “Zeus” means the decentralized synchronous computational network developed by DLI, as such name or reference may be
changed from time to time at DLIs sole discretion.
2. SOFTWARE LICENSE
(a) License Grant. BlockScience hereby grants to DLI and its Affiliates a worldwide, non-exclusive, royalty-free,
irrevocable, perpetual license to (i) download, install, use, execute, access, copy, perform, and modify, the Software
in connection with the Zeus project; (ii) distribute and display the Software internally amongst DLI and its Affiliates,
its and their employees, contractors, and agents, subject to the use of reasonable efforts to maintain the confidential
status of the non-public aspects of the Software display; and (iii) create derivative works of the Software in
connection with the Zeus project, provided that any such derivative works may only be used in connection with the Zeus
project. For the sake of clarity, nothing in this Agreement (including, without limitation, this Section 2) will create
any liability to DLI for or restrict DLIs ability to externally distribute python scripts containing the “input”
configuration files specific to the Zeus project, as well as the notebooks with the resulting “output” data from the
Software, all of which may be distributed, displayed, and shared publicly at DLIs discretion.
(b) Ownership; Limited Rights. As between the parties, BlockScience owns and retains all right, title and interest in
and to the Software, and all Intellectual Property Rights therein. DLIs rights in the Software are limited to those
expressly granted in Section 2(a) and in the PSA. BlockScience reserves all rights and licenses in the Software not
expressly granted to DLI herein and in the PSA.
(c) Delivery. BlockScience will deliver a copy of the Software and Documentation to DLI on the Effective Date. The
delivery may be made in electronic form, or via hardcopy medium (e.g., a CD).
(d) Updates. BlockScience will deliver Updates to DLI as and when such Updates become available. The obligation to
deliver Updates will continue for as long as the PSA remains in force; upon termination or expiration of the PSA,
BlockSciences obligation to provide Updates will automatically terminate.
(e) Support. BlockScience will provide reasonable technical support for the Software, to help DLI manage any support
issues that arise. The obligation to provide support will continue for as long as the PSA remains in force; upon
termination or expiration of the PSA, BlockSciences obligation to provide support will automatically terminate.
3. NO FEES.
There are no fees owed by DLI for the license granted or the Updates or support provided by BlockScience
pursuant to this Agreement. Each party will bear its own costs and expenses arising out of or relating to its
obligations, efforts and performance under this Agreement.
4. LIMITED WARRANTY; DISCLAIMER
(a) Limited Warranty. BlockScience represents and warrants as follows: (i) that it has the right to enter into this
Agreement, and to perform its obligations hereunder, without violating the terms of any other agreement; (ii) that the
Software, and any Updates, do not and will not infringe, violate, or misappropriate the Intellectual Property Rights of
any third party; (iii) that the Software and any Updates do not and will not contain any virus, malware, spyware, trojan
horse, or other malicious code; and (iv) that the Software and each Update will substantially conform to its
Documentation.
(b) Disclaimer. EXCEPT AS OTHERWISE SET FORTH IN THIS AGREEMENT, BLOCKSCIENCE DISCLAIMS ALL OTHER WARRANTIES, EXPRESS OR
IMPLIED, RELATED TO THE SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE.
5. TERM & TERMINATION
(a) Term. This Agreement begins on the Effective Date, and will continue in effect until one of us terminates it in
accordance with Section 5(b).
(b) Termination for Breach. Either party may terminate this Agreement if the other party breaches any material term or
condition of this Agreement, and the breaching party fails to cure the breach within thirty (30) days of receiving
written notice of it.
(c) Survival. Sections 2 through 7 will survive termination or expiration of this Agreement.
6. INDEMNIFICATION.
BlockScience will defend, indemnify, and hold DLI harmless from and against any claim, damage, loss,
liability, expense and cost (including, without limitation, reasonable attorneys fees) incurred by or brought against
DLI arising out of or related to: (i) any claim that the Software infringes or misappropriates the Intellectual Property
Rights of that third party; or (ii) BlockSciences breach of its limited warranties in Section 4(a).
7. GENERAL TERMS
(a) Entire Agreement; Waiver. This Agreement is the entire understanding of the parties, and supersedes any and all
prior agreements or understandings between the parties as to its subject matter. It may be amended or modified, or
provisions waived, only in a writing signed by both parties. The waiver of a breach of any provision of this Agreement
will not operate or be interpreted as a waiver of any other or subsequent breach.
(b) Acknowledgement. BlockScience acknowledges and agrees that the “behaviour archetypes” and “configuration of the Null
Model” referenced in the PSA are considered “Work Product” under the PSA.
(c) Governing Law. This Agreement will be construed, interpreted and applies in accordance with the internal laws of
British Columbia, Canada (excluding its body of law controlling conflicts of law). Any legal action or proceeding
arising under or related to this Agreement will be brought exclusively in the federal or provincial courts located in
Vancouver, British Columbia, and the parties irrevocably consent to personal jurisdiction and venue there.
(d) Severability. If any provision of this Agreement is held to be invalid or unenforceable for any reason, that
provision will be enforced to the maximum extent permitted by law, and the remaining provisions will continue in full
force and effect.
(e) Miscellaneous. This Agreement may be executed in one or more counterparts, with the same effect as if the parties
had signed the same document. Each counterpart so executed will be deemed to be an original, and all such counterparts
will be construed together and will constitute one Agreement. The prevailing party in any action or legal proceeding
arising out of this Agreement will be entitled to recover from the other party all reasonable costs and expenses
incurred in connection with such action or proceeding, including reasonable attorneys fees and court costs. In the
event of a direct conflict between the terms of this Agreement and the PSA with respect to the DLIs rights in and to
the Software, the terms of this Agreement will control.
EXHIBIT A
SOFTWARE
Software Name: SimCAD tool
Software Description: SimCAD is a Monte-Carlo based simulation software package for research, validation, and
Computer Aided Design of economic systems. An economic system is treated as a state based model and defined
through a set of endogenous and exogenous state variables which are updated through mechanisms and
environmental processes, respectively. Behavioral models, which may be deterministic or stochastic, provide the
evolution of the system within the action space of the mechanisms. Simulations can be run with a range of initial
conditions and parameters for states, behaviors, mechanisms, and environmental processes to understand and
visualize network behavior under various conditions.

119
licenses/LICENSE Normal file
View File

@ -0,0 +1,119 @@
TRIAL LICENSE AGREEMENT
BACKGROUND
Company has developed and intends to market and license a certain software product and service called ”SimCAD” which,
among other things, is a scientific engineering simulation tool (“Software”). Company wishes to provide access, on a
trial basis, to users of a “beta” version of the Software to test and provide feedback to Company. Licensee wishes to
participate in Companys beta trial of the Software and to provide feedback to Company with respect to Licensees use
thereof.
Accordingly, the parties hereby agree as follows:
1. BETA PRODUCT.
This Agreement applies to any pre­release version of the Software and any updates and changes thereto during the Term
(collectively, “Beta Product”). As an essential condition of this Agreement, Licensee understands and acknowledges that:
(a) Licensee is participating in a beta test of the Beta Product; (b) the Beta Product has not been field tested or
trialed; and (c) the Beta Product may not operate properly or be error free and may not perform all functions for
which it is intended or represented.
2. FEEDBACK.
As a condition of this Agreement, during the Term of this Agreement, Licensee agrees to provide Company with comments,
feedback, criticisms, and suggestions for changes to the Beta Product (“Feedback”), and to help Company identify errors
or malfunctions, and performance issues, in the operation of the Beta Product, as Company may reasonably request. All
rights to any Feedback or other intellectual property derived from Licensees use of or relating to the Beta Product,
as well any data collected from the use of the Beta Product, belong solely to Company and Licensee hereby irrevocably
assigns all such rights to Company. Company reserves the right to use all Feedback and data collected as a result of the
use of the Beta Product to advertise and promote the Company and the Software.
3. LICENSE AND RESERVATION OF RIGHTS.
3.1 Subject to the terms and conditions set forth in this Agreement, Company hereby grants Licensee, and Licensee
accepts, during the Term, a non­exclusive, royalty­free, revocable, non­transferable, limited license to access and use
the Beta Product for its internal, non­commercial use for evaluation purposes only, and to give permission to employees
of Licensee and employees of Licensees subsidiaries (“Permitted Users”) to use the Beta Product in accordance with the
foregoing.
3.2 The Beta Product and the Software comprise the intellectual property of Company. All right, title and interest in
and to the Beta Product (and, more generally, in and to the Software), and to all Feedback and data arising from its
use, in whole or in part, and all patent, copyright, trade­marks, trade secret and all other intellectual and industrial
property rights therein and the structure, sequence and organization of same, and the media on which such material is
contained belong exclusively to Company. Licensee and its Permitted Users will not, directly or indirectly: reverse
engineer, decompile, disassemble or otherwise attempt to discover the source code, object code or underlying structure,
ideas, know­how or algorithms relevant to the Beta Product; modify, adapt, alter, edit, correct, translate, publish,
sell, transfer, assign, convey, rent, lease, loan, pledge, sublicense, distribute, export, enhance or create derivative
works based on the Beta Product; or remove, alter, cover or otherwise obscure any proprietary notices or labels
displayed on or within the Beta Product any documentation relating thereto.
4. DISCLAIMER.
4.1 COMPANY MAKES NO WARRANTIES, WHETHER EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, WITH RESPECT TO THE BETA PRODUCT,
INCLUDING, BUT NOT LIMITED TO, THE AVAILABILITY, QUALITY OR PERFORMANCE OF THE BETA PRODUCT. COMPANY SPECIFICALLY
DISCLAIMS ALL EXPRESS, STATUTORY AND IMPLIED WARRANTIES AND CONDITIONS, INCLUDING, WITHOUT LIMITATION (A) THE IMPLIED
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON­INFRINGEMENT, (B) ANY WARRANTIES AGAINST HIDDEN
OR LATENT DEFECTS, (C) AND ANY WARRANTIES AND CONDITIONS ARISING OUT OF COURSE OF DEALING OR USAGE OF TRADE AND (D) ANY
WARRANTY OR REPRESENTATION THAT THE BETA PRODUCT IS ERROR­FREE, VIRUS­FREE, SECURE, UNINTERRUPTED, OR FREE FROM
UNAUTHORIZED ACCESS (INCLUDING, BUT NOT LIMITED TO, THIRD PARTY HACKERS OR DENIAL OF SERVICE ATTACKS). THE BETA PRODUCT
IS SUPPLIED ON AN “AS IS”, “AS AVAILABLE” BASIS WITHOUT WARRANTY.
4.2 NEITHER PARTY SHALL BE LIABLE FOR SPECIAL, INCIDENTAL, PUNITIVE, CONSEQUENTIAL OR INDIRECT DAMAGES OR LOSS
(INCLUDING DEATH AND PERSONAL INJURY), IRRESPECTIVE OF THEIR CAUSE, NOTWITHSTANDING THAT A PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH LOSS OR DAMAGE, NOR FOR ANY CLAIMS FOR SUCH LOSS OR DAMAGE INSTITUTED AGAINST A PARTY OR ITS
CUSTOMERS BY ANY THIRD PARTY.
5. CONFIDENTIALITY
5.1 All Confidential Information disclosed by either party shall be kept by the receiving party in strict confidence and
shall not be disclosed to any third party without the disclosing partys express written consent. For purposes of this
Agreement, “Confidential Information” means all information regarding either partys business which has been marked or
is otherwise communicated as being “proprietary” or “confidential” or which reasonably should be known by the receiving
party to be proprietary or confidential information. Without limiting the generality of the foregoing, Confidential
Information of Company includes non­public information regarding features, functionality and performance of the Beta
Product, including all Feedback and related data. Notwithstanding the foregoing, each partys confidentiality
obligations hereunder shall not apply to information that: (a) is already known to the receiving party without a
pre­existing restriction as to disclosure; (b) is or becomes publicly available without fault of the receiving party;
(c) is rightfully obtained by the receiving party from a third party without restriction as to disclosure, or is
approved for release by written authorization of the disclosing party; (d) is developed independently by the receiving
party without use of the disclosing partys Confidential Information; or (e) is required to be disclosed by law or
regulation, including, but not limited to, supplying such information or making such statements or disclosures relating
to this Agreement before any competent court, governmental agency or authority in response to a lawful requirement or
request from a court of governmental agency or authority, provided that the disclosing party shall give the other party
prompt notice of such request, to the extent practicable, so that the other party may seek (at its sole cost and
expense) an appropriate protective order or similar relief.
5.2 In the event of a breach of Sections 2, 3 or this Section 5, the non­breaching party shall be entitled to seek
equitable relief to protect its interests, including, but not limited to, injunctive relief. In the event of expiration
or earlier termination of this Agreement, each party shall immediately return to the other party such other partys
Confidential Information, or at such other partys option, destroy any remaining Confidential Information and certify
that such destruction has taken place.
6. FEES; EXPENSES.
Neither party shall be entitled to any compensation in connection with this Agreement or its use or provision of the
Beta Product. Each party shall bear its own costs and expenses arising from this Agreement and its use or provision of
the Beta Product, as the case may be.
7. TERM OF AGREEMENT.
This Agreement shall begin on the Effective Date and shall continue until it has been terminated (such period, the
“Term”). Either party shall have the right to terminate this Agreement at any time on one (1) month written notice to
the other party, or in the case of a breach of this Agreement by Licensee or its Permitted Users, Company may terminate
this Agreement immediately on written notice to Licensee. Upon termination of this Agreement, all rights granted to
Licensee (and any Permitted User) under this Agreement will immediately terminate and Licensee (and all Permitted Users)
must immediately cease all use of the Beta Product at such time. Notwithstanding any termination of this Agreement,
Sections 2, 3.2, 4, 5, 6, this Section 7 and Section 8 shall survive and remain binding on the parties.
8. MISCELLANEOUS.
This Agreement shall be governed by and construed in accordance with the laws of the State of New York. All disputes
relating to this Agreement shall be resolved in the federal and state courts of New York County, New York and the
parties submit to the jurisdiction of such courts. This Agreement does not create any agency, partnership, or joint
venture relationship between Licensee and Company. This Agreement is the entire understanding of the parties with
respect to the subject matter hereof and supersedes any previous or contemporaneous communications, representations,
warranties, discussions, arrangements or commitments, whether oral or written with respect to such subject matter. This
Agreement cannot be amended except by a written amendment that expressly refers to this Agreement and is signed by an
authorized representative of each party. This Agreement may be executed in one or more counterparts, including via
facsimile or email (or any other electronic means such as “.pdf” or “.tiff” files), each of which shall be deemed an
original, and all of which shall constitute one and the same Agreement.

File diff suppressed because it is too large Load Diff

View File

@ -1,42 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"assert pd.__version__ == '0.23.4'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@ -1,55 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'ui'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-1-a6e895c51fc0>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mengine\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mrun\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[0mrun\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmain\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\engine\\run.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mui\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconfig\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mstate_dict\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmechanisms\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mexogenous_states\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0menv_processes\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msim_config\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mengine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconfigProcessor\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mgenerate_config\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mengine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmechanismExecutor\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0msimulation\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mengine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mutils\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mflatten\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'ui'"
]
}
],
"source": [
"from engine import run\n",
"run.main()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,482 +0,0 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## SimCAD Application Notebook\n",
"## Experiment Type 2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Name of Config File or System Description\n",
"#### 20 MonteCarlo Runs \n",
"#### Behaviors: EMHers, Herders, HODLers, EIUers, and Human EIUers"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Simulation Run 1\n",
"single_proc: [<SimCAD.Configuration object at 0x000001EA1AAA6630>]\n"
]
},
{
"ename": "TypeError",
"evalue": "unsupported operand type(s) for *: 'float' and 'decimal.Decimal'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-1-0d9ea96d7f5c>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 15\u001b[0m \u001b[0msingle_proc_ctx\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mExecutionContext\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mexec_mode\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msingle_proc\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 16\u001b[0m \u001b[0mrun1\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mExecutor\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msingle_proc_ctx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msingle_config\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 17\u001b[1;33m \u001b[0mrun1_raw_result\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mrun1\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmain\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 18\u001b[0m \u001b[0mdf\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mDataFrame\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrun1_raw_result\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 19\u001b[0m \u001b[1;31m# print(tabulate(result, headers='keys', tablefmt='psql'))\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m~\\staging\\21f1155\\SimCAD\\engine\\__init__.py\u001b[0m in \u001b[0;36mexecute\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 71\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 72\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexec_context\u001b[0m \u001b[1;33m==\u001b[0m \u001b[0mExecutionMode\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msingle_proc\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 73\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0msingle_proc_exec\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msimulation_execs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstates_lists\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mconfigs_structs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0menv_processes_list\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mTs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mNs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 74\u001b[0m \u001b[1;32melif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexec_context\u001b[0m \u001b[1;33m==\u001b[0m \u001b[0mExecutionMode\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmulti_proc\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 75\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconfigs\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m~\\staging\\21f1155\\SimCAD\\engine\\__init__.py\u001b[0m in \u001b[0;36msingle_proc_exec\u001b[1;34m(simulation_execs, states_lists, configs_structs, env_processes_list, Ts, Ns)\u001b[0m\n\u001b[0;32m 67\u001b[0m \u001b[0msimulation\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstates_list\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mconfig\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0menv_processes\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mT\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mN\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mlist\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmap\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;32mlambda\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ml\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 68\u001b[0m \u001b[1;31m# print(states_list)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 69\u001b[1;33m \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0msimulation\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstates_list\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mconfig\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0menv_processes\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mT\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mN\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 70\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mflatten\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 71\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m~\\staging\\21f1155\\SimCAD\\engine\\simulation.py\u001b[0m in \u001b[0;36msimulation\u001b[1;34m(self, states_list, configs, env_processes, time_seq, runs)\u001b[0m\n\u001b[0;32m 100\u001b[0m \u001b[1;31m# print(\"Run: \"+str(run))\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 101\u001b[0m \u001b[0mstates_list_copy\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdeepcopy\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstates_list\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m# WHY ???\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 102\u001b[1;33m \u001b[0mhead\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0mtail\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpipe\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstates_list_copy\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mconfigs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0menv_processes\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtime_seq\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrun\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 103\u001b[0m \u001b[0mgenesis\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mhead\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 104\u001b[0m \u001b[0mgenesis\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'mech_step'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mgenesis\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'time_step'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mgenesis\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'run'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrun\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m~\\staging\\21f1155\\SimCAD\\engine\\simulation.py\u001b[0m in \u001b[0;36mpipe\u001b[1;34m(self, states_list, configs, env_processes, time_seq, run)\u001b[0m\n\u001b[0;32m 86\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mtime_step\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mtime_seq\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 87\u001b[0m \u001b[1;31m# print(run)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 88\u001b[1;33m \u001b[0mpipe_run\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mblock_gen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msimulation_list\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mconfigs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0menv_processes\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtime_step\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrun\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 89\u001b[0m \u001b[0m_\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0mpipe_run\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpipe_run\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 90\u001b[0m \u001b[0msimulation_list\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpipe_run\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m~\\staging\\21f1155\\SimCAD\\engine\\simulation.py\u001b[0m in \u001b[0;36mblock_gen\u001b[1;34m(self, states_list, configs, env_processes, t_step, run)\u001b[0m\n\u001b[0;32m 72\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mconfig\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mconfigs\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 73\u001b[0m \u001b[0ms_conf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mb_conf\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mconfig\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mconfig\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 74\u001b[1;33m \u001b[0mstates_list\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmech_step\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mm_step\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstates_list\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ms_conf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mb_conf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0menv_processes\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mt_step\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrun\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 75\u001b[0m \u001b[0mm_step\u001b[0m \u001b[1;33m+=\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 76\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m~\\staging\\21f1155\\SimCAD\\engine\\simulation.py\u001b[0m in \u001b[0;36mmech_step\u001b[1;34m(self, m_step, sL, state_funcs, behavior_funcs, env_processes, t_step, run)\u001b[0m\n\u001b[0;32m 42\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 43\u001b[0m \u001b[1;31m# *** add env_proc value here as wrapper function ***\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 44\u001b[1;33m \u001b[0mlast_in_copy\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexception_handler\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mm_step\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msL\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlast_in_obj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0m_input\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mf\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mstate_funcs\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 45\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 46\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mk\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mlast_in_obj\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m~\\staging\\21f1155\\SimCAD\\engine\\simulation.py\u001b[0m in \u001b[0;36m<listcomp>\u001b[1;34m(.0)\u001b[0m\n\u001b[0;32m 42\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 43\u001b[0m \u001b[1;31m# *** add env_proc value here as wrapper function ***\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 44\u001b[1;33m \u001b[0mlast_in_copy\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexception_handler\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mm_step\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msL\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlast_in_obj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0m_input\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mf\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mstate_funcs\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 45\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 46\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mk\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mlast_in_obj\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m~\\staging\\21f1155\\SimCAD\\engine\\simulation.py\u001b[0m in \u001b[0;36mexception_handler\u001b[1;34m(self, f, m_step, sL, last_mut_obj, _input)\u001b[0m\n\u001b[0;32m 28\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mexception_handler\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mm_step\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msL\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlast_mut_obj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0m_input\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 29\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 30\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mm_step\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msL\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlast_mut_obj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0m_input\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 31\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 32\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Exception\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m~\\staging\\21f1155\\sandboxUX\\config6b.py\u001b[0m in \u001b[0;36ms2m3\u001b[1;34m(step, sL, s, _input)\u001b[0m\n\u001b[0;32m 179\u001b[0m \u001b[0my\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'Price'\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 180\u001b[0m \u001b[1;31m#var1 = Decimal.from_float(s['Buy_Log'])\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 181\u001b[1;33m \u001b[0mx\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0ms\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'Price'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0ms\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'Buy_Log'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m/\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'Z'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m-\u001b[0m \u001b[1;36m0.1\u001b[0m \u001b[1;33m*\u001b[0m \u001b[0ms\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'Sell_Log'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'Z'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m+\u001b[0m \u001b[0ms\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'Buy_Log'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0ms\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'Sell_Log'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 182\u001b[0m \u001b[1;31m#+ np.divide(s['Buy_Log'],s['Z']) - np.divide() # / Psignal_int\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 183\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for *: 'float' and 'decimal.Decimal'"
]
}
],
"source": [
"import pandas as pd\n",
"from tabulate import tabulate\n",
"\n",
"from SimCAD.engine import ExecutionMode, ExecutionContext, Executor\n",
"from sandboxUX import config6b #, config2\n",
"from SimCAD import configs\n",
"\n",
"# ToDo: pass ExecutionContext with execution method as ExecutionContext input\n",
"\n",
"exec_mode = ExecutionMode()\n",
"\n",
"print(\"Simulation Run 1\")\n",
"# print()\n",
"single_config = [configs[0]]\n",
"single_proc_ctx = ExecutionContext(exec_mode.single_proc)\n",
"run1 = Executor(single_proc_ctx, single_config)\n",
"run1_raw_result = run1.main()\n",
"df = pd.DataFrame(run1_raw_result)\n",
"# print(tabulate(result, headers='keys', tablefmt='psql'))\n",
"# print()\n",
"\n",
"# print(\"Simulation Run 2: Pairwise Execution\")\n",
"# print()\n",
"# multi_proc_ctx = ExecutionContext(exec_mode.multi_proc)\n",
"# run2 = Executor(multi_proc_ctx, configs)\n",
"# run2_raw_results = run2.main()\n",
"# for raw_result in run2_raw_results:\n",
"# result = pd.DataFrame(raw_result)\n",
"# print(tabulate(result, headers='keys', tablefmt='psql'))\n",
"# print()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#df = pd.DataFrame(run1_raw_result)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Standard Library Imports\n",
"#import pandas as pd\n",
"import numpy as np\n",
"import matplotlib as mpl\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"#from tabulate import tabulate\n",
"\n",
"sns.set_style('whitegrid')\n",
"\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# SimCAD Specific\n",
"# from SimCAD.engine import ExecutionMode, ExecutionContext, Executor\n",
"# from sandboxUX import config1 , config2\n",
"# from SimCAD import configs"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Convert data type of output to float. MPL works OK with strings, seaborn does not\n",
"names = df.keys()[:-3] # [:-3] only affects state variables\n",
"for n in names:\n",
" df[n]=df[n].apply(float)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Check\n",
"df.head(10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df.iloc[2995:3005]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df.tail(10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df.corr()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"aggregate_dimension = 'time_step'\n",
"\n",
"mean_df = df.groupby(aggregate_dimension).mean().reset_index()\n",
"median_df = df.groupby(aggregate_dimension).median().reset_index()\n",
"std_df = df.groupby(aggregate_dimension).std().reset_index()\n",
"min_df = df.groupby(aggregate_dimension).min().reset_index()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"mean_df.head(10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"mean_df.tail(10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def dist_plot(x, y,lx=False,ly=False, suppMin=False): \n",
" plt.figure(figsize=(12,8))\n",
" if not(suppMin):\n",
" plt.plot(mean_df[x].values, mean_df[y].values,\n",
" mean_df[x].values,median_df[y].values,\n",
" mean_df[x].values,mean_df[y].values+std_df[y].values,\n",
" mean_df[x].values,min_df[y].values)\n",
" plt.legend(['mean', 'median', 'mean+ 1*std', 'min'],bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)\n",
" \n",
" else:\n",
" plt.plot(mean_df[x].values, mean_df[y].values,\n",
" mean_df[x].values,median_df[y].values,\n",
" mean_df[x].values,mean_df[y].values+std_df[y].values,\n",
" mean_df[x].values,mean_df[y].values-std_df[y].values)\n",
" plt.legend(['mean', 'median', 'mean+ 1*std', 'mean - 1*std'],bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)\n",
"\n",
" plt.xlabel(x)\n",
" plt.ylabel(y)\n",
" if lx:\n",
" plt.xscale('log')\n",
" \n",
" if ly:\n",
" plt.yscale('log')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dist_plot('time_step', 'P_Ext_Markets',suppMin=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dist_plot('time_step', 'Price',suppMin=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(12,8))\n",
"plt.plot(mean_df['time_step'][1:],mean_df['Price'][1:]) #, df['Zeus_LT']], figsize=(15,10)) #, logy=True)\n",
"plt.plot(mean_df['time_step'][1:],(1/250)*mean_df['P_Ext_Markets'][1:])\n",
"#plt.plot(df['time_step'],df['Zeus_LT'])\n",
"plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(np.std(mean_df))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(12,8))\n",
"plt.plot(mean_df['time_step'][1:],mean_df['Buy_Log'][1:]) #, df['Zeus_LT']], figsize=(15,10)) #, logy=True)\n",
"plt.plot(mean_df['time_step'][1:],mean_df['Sell_Log'][1:])\n",
"#plt.plot(df['time_step'],df['Zeus_LT'])\n",
"plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"buy_delta = mean_df['Buy_Log'].diff()\n",
"sell_delta = mean_df['Sell_Log'].diff()\n",
"ext_delta = mean_df['P_Ext_Markets'].diff()\n",
"# df_delta['Buy_Log'] = buy_delta\n",
"# df_delta['Sell_Log'] = sell_delta\n",
"# df_delta = df_delta.append(ext_delta)\n",
"# df_delta.head()\n",
"sell_delta.head(20)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(12,8))\n",
"plt.plot(mean_df['time_step'][1:],buy_delta[1:]) #, df['Zeus_LT']], figsize=(15,10)) #, logy=True)\n",
"plt.plot(mean_df['time_step'][1:],sell_delta[1:])\n",
"plt.plot(mean_df['time_step'][1:],ext_delta[1:])\n",
"plt.ylim(-400,400)\n",
"#plt.plot(df['time_step'],df['Zeus_LT'])\n",
"plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sns.pairplot(mean_df)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(12,8))\n",
"plt.plot(mean_df['time_step'],mean_df['Z']/mean_df['P_Ext_Markets'])\n",
"plt.title('Z per External Stock Market Price')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# plt.figure(figsize=(12,8))\n",
"# plt.plot(df['time_step'],(df['TDR_Int']-df['TDR_Ext'])/df['TDR_Ext'])\n",
"# plt.title('Availability of TDR arbitrage opportunity')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# plt.figure(figsize=(12,8))\n",
"# plt.plot(df['time_step'],(df['Zeus_LT']/df['Zeus_ST']-1))\n",
"# plt.title('Availability of LT vs ST arbitrage opportunity')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# vol_df = df.rolling(window = 21).mean()\n",
"vol_df = pd.DataFrame()\n",
"rolling_days = 63 # days = number * mechanisms\n",
"for n in names:\n",
" vol_df[n] = mean_df[n].rolling(rolling_days).mean().shift()\n",
" \n",
"vol_df = vol_df.dropna() #(vol_df.iloc[0:rolling_days])\n",
"# vol_df[n].iloc[:rolling_days], axis=1)\n",
"vol_df.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(12,8))\n",
"plt.plot(vol_df['Z'])\n",
"plt.title('Rolling Average of Z')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(12,8))\n",
"plt.plot(vol_df['P_Ext_Markets'])\n",
"plt.title('Rolling Average of External Stock Market Price')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(12,8))\n",
"plt.plot(vol_df['Price'])\n",
"plt.plot(vol_df['P_Ext_Markets']/250)\n",
"plt.legend()\n",
"plt.title('Rolling Average of Zeus Price')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df[\"Price\"].min()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df[\"Price\"].max()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@ -1,202 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Simulation Run 1\n",
"\n",
"single_proc: [<SimCAD.Configuration object at 0x10fc1a8d0>]\n",
"+----+-------------+-------+------------+-----------+----------+----------+-------------+---------------------+\n",
"| | mech_step | run | s1 | s2 | s3 | s4 | time_step | timestamp |\n",
"|----+-------------+-------+------------+-----------+----------+----------+-------------+---------------------|\n",
"| 0 | 0 | 2 | 0 | 0 | 1 | 1 | 0 | 2018-10-01 15:16:24 |\n",
"| 1 | 1 | 1 | 1 | 4 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n",
"| 2 | 2 | 1 | ab | 6 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n",
"| 3 | 3 | 1 | ['c', 'd'] | [ 30 300] | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n",
"| 4 | 1 | 1 | 1 | 4 | 9.94373 | 10.4365 | 2 | 2018-10-01 15:16:26 |\n",
"| 5 | 2 | 1 | ab | 6 | 9.94373 | 10.4365 | 2 | 2018-10-01 15:16:26 |\n",
"| 6 | 3 | 1 | ['c', 'd'] | [ 30 300] | 9.94373 | 10.4365 | 2 | 2018-10-01 15:16:26 |\n",
"| 7 | 1 | 1 | 1 | 4 | 7.81956 | 10.5372 | 3 | 2018-10-01 15:16:27 |\n",
"| 8 | 2 | 1 | ab | 6 | 7.81956 | 10.5372 | 3 | 2018-10-01 15:16:27 |\n",
"| 9 | 3 | 1 | ['c', 'd'] | [ 30 300] | 7.81956 | 10.5372 | 3 | 2018-10-01 15:16:27 |\n",
"| 10 | 1 | 1 | 1 | 4 | 9.10218 | 8.57362 | 4 | 2018-10-01 15:16:28 |\n",
"| 11 | 2 | 1 | ab | 6 | 9.10218 | 8.57362 | 4 | 2018-10-01 15:16:28 |\n",
"| 12 | 3 | 1 | ['c', 'd'] | [ 30 300] | 9.10218 | 8.57362 | 4 | 2018-10-01 15:16:28 |\n",
"| 13 | 1 | 1 | 1 | 4 | 7.46976 | 8.33579 | 5 | 2018-10-01 15:16:29 |\n",
"| 14 | 2 | 1 | ab | 6 | 7.46976 | 8.33579 | 5 | 2018-10-01 15:16:29 |\n",
"| 15 | 3 | 1 | ['c', 'd'] | [ 30 300] | 7.46976 | 8.33579 | 5 | 2018-10-01 15:16:29 |\n",
"| 16 | 0 | 2 | 0 | 0 | 1 | 1 | 0 | 2018-10-01 15:16:24 |\n",
"| 17 | 1 | 2 | 1 | 4 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n",
"| 18 | 2 | 2 | ab | 6 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n",
"| 19 | 3 | 2 | ['c', 'd'] | [ 30 300] | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n",
"| 20 | 1 | 2 | 1 | 4 | 10.5029 | 9.91726 | 2 | 2018-10-01 15:16:26 |\n",
"| 21 | 2 | 2 | ab | 6 | 10.5029 | 9.91726 | 2 | 2018-10-01 15:16:26 |\n",
"| 22 | 3 | 2 | ['c', 'd'] | [ 30 300] | 10.5029 | 9.91726 | 2 | 2018-10-01 15:16:26 |\n",
"| 23 | 1 | 2 | 1 | 4 | 9.19497 | 9.29545 | 3 | 2018-10-01 15:16:27 |\n",
"| 24 | 2 | 2 | ab | 6 | 9.19497 | 9.29545 | 3 | 2018-10-01 15:16:27 |\n",
"| 25 | 3 | 2 | ['c', 'd'] | [ 30 300] | 9.19497 | 9.29545 | 3 | 2018-10-01 15:16:27 |\n",
"| 26 | 1 | 2 | 1 | 4 | 8.22219 | 9.25471 | 4 | 2018-10-01 15:16:28 |\n",
"| 27 | 2 | 2 | ab | 6 | 8.22219 | 9.25471 | 4 | 2018-10-01 15:16:28 |\n",
"| 28 | 3 | 2 | ['c', 'd'] | [ 30 300] | 8.22219 | 9.25471 | 4 | 2018-10-01 15:16:28 |\n",
"| 29 | 1 | 2 | 1 | 4 | 7.47478 | 8.81306 | 5 | 2018-10-01 15:16:29 |\n",
"| 30 | 2 | 2 | ab | 6 | 7.47478 | 8.81306 | 5 | 2018-10-01 15:16:29 |\n",
"| 31 | 3 | 2 | ['c', 'd'] | [ 30 300] | 7.47478 | 8.81306 | 5 | 2018-10-01 15:16:29 |\n",
"+----+-------------+-------+------------+-----------+----------+----------+-------------+---------------------+\n",
"\n",
"Simulation Run 2: Pairwise Execution\n",
"\n",
"multi_proc: [<SimCAD.Configuration object at 0x10fc1a8d0>, <SimCAD.Configuration object at 0x10fc1aeb8>]\n",
"+----+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----+\n",
"| | b1 | b2 | s1 | s2 | es1 | es2 | es3 | m |\n",
"|----+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----|\n",
"| 0 | <function b1m1 at 0x10faedd08> | <function b2m1 at 0x10fc230d0> | <function s1m1 at 0x10fc23378> | <function s2m1 at 0x10fc23400> | <function curried.<locals>._curried at 0x10fc23ae8> | <function curried.<locals>._curried at 0x10fc23b70> | <function curried.<locals>._curried at 0x10fc23bf8> | 1 |\n",
"| 1 | <function b1m2 at 0x10fc23158> | <function b2m2 at 0x10fc231e0> | <function s1m2 at 0x10fc23488> | <function s2m2 at 0x10fc23510> | <function curried.<locals>._curried at 0x10fc23ae8> | <function curried.<locals>._curried at 0x10fc23b70> | <function curried.<locals>._curried at 0x10fc23bf8> | 2 |\n",
"| 2 | <function b1m3 at 0x10fc23268> | <function b2m3 at 0x10fc232f0> | <function s1m3 at 0x10fc23598> | <function s2m3 at 0x10fc23620> | <function curried.<locals>._curried at 0x10fc23ae8> | <function curried.<locals>._curried at 0x10fc23b70> | <function curried.<locals>._curried at 0x10fc23bf8> | 3 |\n",
"+----+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----+\n",
"+----+--------------------------------+--------------------------------+--------------------------------+------------------------------------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----+\n",
"| | b1 | b2 | s1 | s2 | es1 | es2 | es3 | m |\n",
"|----+--------------------------------+--------------------------------+--------------------------------+------------------------------------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----|\n",
"| 0 | <function b1m1 at 0x10fc23d08> | <function b2m1 at 0x10fc23d90> | <function s1m1 at 0x10fc290d0> | <function state_identity.<locals>.<lambda> at 0x10d4f6598> | <function curried.<locals>._curried at 0x10fc29840> | <function curried.<locals>._curried at 0x10fc298c8> | <function curried.<locals>._curried at 0x10fc29950> | 1 |\n",
"| 1 | <function b1m2 at 0x10fc23e18> | <function b2m2 at 0x10fc23ea0> | <function s1m2 at 0x10fc291e0> | <function state_identity.<locals>.<lambda> at 0x10d4f6598> | <function curried.<locals>._curried at 0x10fc29840> | <function curried.<locals>._curried at 0x10fc298c8> | <function curried.<locals>._curried at 0x10fc29950> | 2 |\n",
"| 2 | <function b1m3 at 0x10fc23f28> | <function b2m3 at 0x10fc29048> | <function s1m3 at 0x10fc292f0> | <function s2m3 at 0x10fc29378> | <function curried.<locals>._curried at 0x10fc29840> | <function curried.<locals>._curried at 0x10fc298c8> | <function curried.<locals>._curried at 0x10fc29950> | 3 |\n",
"+----+--------------------------------+--------------------------------+--------------------------------+------------------------------------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----+\n",
"+----+-------------+-------+------------+-----------+----------+----------+-------------+---------------------+\n",
"| | mech_step | run | s1 | s2 | s3 | s4 | time_step | timestamp |\n",
"|----+-------------+-------+------------+-----------+----------+----------+-------------+---------------------|\n",
"| 0 | 0 | 2 | 0 | 0 | 1 | 1 | 0 | 2018-10-01 15:16:24 |\n",
"| 1 | 1 | 1 | 1 | 4 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n",
"| 2 | 2 | 1 | ab | 6 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n",
"| 3 | 3 | 1 | ['c', 'd'] | [ 30 300] | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n",
"| 4 | 1 | 1 | 1 | 4 | 12.2922 | 10.8846 | 2 | 2018-10-01 15:16:26 |\n",
"| 5 | 2 | 1 | ab | 6 | 12.2922 | 10.8846 | 2 | 2018-10-01 15:16:26 |\n",
"| 6 | 3 | 1 | ['c', 'd'] | [ 30 300] | 12.2922 | 10.8846 | 2 | 2018-10-01 15:16:26 |\n",
"| 7 | 1 | 1 | 1 | 4 | 12.3433 | 11.8439 | 3 | 2018-10-01 15:16:27 |\n",
"| 8 | 2 | 1 | ab | 6 | 12.3433 | 11.8439 | 3 | 2018-10-01 15:16:27 |\n",
"| 9 | 3 | 1 | ['c', 'd'] | [ 30 300] | 12.3433 | 11.8439 | 3 | 2018-10-01 15:16:27 |\n",
"| 10 | 1 | 1 | 1 | 4 | 10.9634 | 13.8687 | 4 | 2018-10-01 15:16:28 |\n",
"| 11 | 2 | 1 | ab | 6 | 10.9634 | 13.8687 | 4 | 2018-10-01 15:16:28 |\n",
"| 12 | 3 | 1 | ['c', 'd'] | [ 30 300] | 10.9634 | 13.8687 | 4 | 2018-10-01 15:16:28 |\n",
"| 13 | 1 | 1 | 1 | 4 | 11.5544 | 13.9381 | 5 | 2018-10-01 15:16:29 |\n",
"| 14 | 2 | 1 | ab | 6 | 11.5544 | 13.9381 | 5 | 2018-10-01 15:16:29 |\n",
"| 15 | 3 | 1 | ['c', 'd'] | [ 30 300] | 11.5544 | 13.9381 | 5 | 2018-10-01 15:16:29 |\n",
"| 16 | 0 | 2 | 0 | 0 | 1 | 1 | 0 | 2018-10-01 15:16:24 |\n",
"| 17 | 1 | 2 | 1 | 4 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n",
"| 18 | 2 | 2 | ab | 6 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n",
"| 19 | 3 | 2 | ['c', 'd'] | [ 30 300] | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n",
"| 20 | 1 | 2 | 1 | 4 | 9.98087 | 9.45464 | 2 | 2018-10-01 15:16:26 |\n",
"| 21 | 2 | 2 | ab | 6 | 9.98087 | 9.45464 | 2 | 2018-10-01 15:16:26 |\n",
"| 22 | 3 | 2 | ['c', 'd'] | [ 30 300] | 9.98087 | 9.45464 | 2 | 2018-10-01 15:16:26 |\n",
"| 23 | 1 | 2 | 1 | 4 | 11.1536 | 7.9925 | 3 | 2018-10-01 15:16:27 |\n",
"| 24 | 2 | 2 | ab | 6 | 11.1536 | 7.9925 | 3 | 2018-10-01 15:16:27 |\n",
"| 25 | 3 | 2 | ['c', 'd'] | [ 30 300] | 11.1536 | 7.9925 | 3 | 2018-10-01 15:16:27 |\n",
"| 26 | 1 | 2 | 1 | 4 | 10.3195 | 8.77766 | 4 | 2018-10-01 15:16:28 |\n",
"| 27 | 2 | 2 | ab | 6 | 10.3195 | 8.77766 | 4 | 2018-10-01 15:16:28 |\n",
"| 28 | 3 | 2 | ['c', 'd'] | [ 30 300] | 10.3195 | 8.77766 | 4 | 2018-10-01 15:16:28 |\n",
"| 29 | 1 | 2 | 1 | 4 | 10.3288 | 7.81118 | 5 | 2018-10-01 15:16:29 |\n",
"| 30 | 2 | 2 | ab | 6 | 10.3288 | 7.81118 | 5 | 2018-10-01 15:16:29 |\n",
"| 31 | 3 | 2 | ['c', 'd'] | [ 30 300] | 10.3288 | 7.81118 | 5 | 2018-10-01 15:16:29 |\n",
"+----+-------------+-------+------------+-----------+----------+----------+-------------+---------------------+\n",
"+----+-------------+-------+------------+-----------+----------+----------+-------------+---------------------+\n",
"| | mech_step | run | s1 | s2 | s3 | s4 | time_step | timestamp |\n",
"|----+-------------+-------+------------+-----------+----------+----------+-------------+---------------------|\n",
"| 0 | 0 | 2 | 0 | 0 | 1 | 1 | 0 | 2018-10-01 15:16:24 |\n",
"| 1 | 1 | 1 | 1 | 0 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n",
"| 2 | 2 | 1 | ab | 0 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n",
"| 3 | 3 | 1 | ['c', 'd'] | [ 30 300] | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n",
"| 4 | 1 | 1 | 1 | [ 30 300] | 9.94373 | 10.4365 | 2 | 2018-10-01 15:16:26 |\n",
"| 5 | 2 | 1 | ab | [ 30 300] | 9.94373 | 10.4365 | 2 | 2018-10-01 15:16:26 |\n",
"| 6 | 3 | 1 | ['c', 'd'] | [ 30 300] | 9.94373 | 10.4365 | 2 | 2018-10-01 15:16:26 |\n",
"| 7 | 1 | 1 | 1 | [ 30 300] | 7.81956 | 10.5372 | 3 | 2018-10-01 15:16:27 |\n",
"| 8 | 2 | 1 | ab | [ 30 300] | 7.81956 | 10.5372 | 3 | 2018-10-01 15:16:27 |\n",
"| 9 | 3 | 1 | ['c', 'd'] | [ 30 300] | 7.81956 | 10.5372 | 3 | 2018-10-01 15:16:27 |\n",
"| 10 | 1 | 1 | 1 | [ 30 300] | 9.10218 | 8.57362 | 4 | 2018-10-01 15:16:28 |\n",
"| 11 | 2 | 1 | ab | [ 30 300] | 9.10218 | 8.57362 | 4 | 2018-10-01 15:16:28 |\n",
"| 12 | 3 | 1 | ['c', 'd'] | [ 30 300] | 9.10218 | 8.57362 | 4 | 2018-10-01 15:16:28 |\n",
"| 13 | 1 | 1 | 1 | [ 30 300] | 7.46976 | 8.33579 | 5 | 2018-10-01 15:16:29 |\n",
"| 14 | 2 | 1 | ab | [ 30 300] | 7.46976 | 8.33579 | 5 | 2018-10-01 15:16:29 |\n",
"| 15 | 3 | 1 | ['c', 'd'] | [ 30 300] | 7.46976 | 8.33579 | 5 | 2018-10-01 15:16:29 |\n",
"| 16 | 0 | 2 | 0 | 0 | 1 | 1 | 0 | 2018-10-01 15:16:24 |\n",
"| 17 | 1 | 2 | 1 | 0 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n",
"| 18 | 2 | 2 | ab | 0 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n",
"| 19 | 3 | 2 | ['c', 'd'] | [ 30 300] | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n",
"| 20 | 1 | 2 | 1 | [ 30 300] | 10.5029 | 9.91726 | 2 | 2018-10-01 15:16:26 |\n",
"| 21 | 2 | 2 | ab | [ 30 300] | 10.5029 | 9.91726 | 2 | 2018-10-01 15:16:26 |\n",
"| 22 | 3 | 2 | ['c', 'd'] | [ 30 300] | 10.5029 | 9.91726 | 2 | 2018-10-01 15:16:26 |\n",
"| 23 | 1 | 2 | 1 | [ 30 300] | 9.19497 | 9.29545 | 3 | 2018-10-01 15:16:27 |\n",
"| 24 | 2 | 2 | ab | [ 30 300] | 9.19497 | 9.29545 | 3 | 2018-10-01 15:16:27 |\n",
"| 25 | 3 | 2 | ['c', 'd'] | [ 30 300] | 9.19497 | 9.29545 | 3 | 2018-10-01 15:16:27 |\n",
"| 26 | 1 | 2 | 1 | [ 30 300] | 8.22219 | 9.25471 | 4 | 2018-10-01 15:16:28 |\n",
"| 27 | 2 | 2 | ab | [ 30 300] | 8.22219 | 9.25471 | 4 | 2018-10-01 15:16:28 |\n",
"| 28 | 3 | 2 | ['c', 'd'] | [ 30 300] | 8.22219 | 9.25471 | 4 | 2018-10-01 15:16:28 |\n",
"| 29 | 1 | 2 | 1 | [ 30 300] | 7.47478 | 8.81306 | 5 | 2018-10-01 15:16:29 |\n",
"| 30 | 2 | 2 | ab | [ 30 300] | 7.47478 | 8.81306 | 5 | 2018-10-01 15:16:29 |\n",
"| 31 | 3 | 2 | ['c', 'd'] | [ 30 300] | 7.47478 | 8.81306 | 5 | 2018-10-01 15:16:29 |\n",
"+----+-------------+-------+------------+-----------+----------+----------+-------------+---------------------+\n",
"\n"
]
}
],
"source": [
"import pandas as pd\n",
"from tabulate import tabulate\n",
"\n",
"from SimCAD.engine import ExecutionMode, ExecutionContext, Executor\n",
"from sandboxUX import config1, config2\n",
"from SimCAD import configs\n",
"\n",
"# ToDo: pass ExecutionContext with execution method as ExecutionContext input\n",
"\n",
"exec_mode = ExecutionMode()\n",
"\n",
"print(\"Simulation Run 1\")\n",
"print()\n",
"single_config = [configs[0]]\n",
"single_proc_ctx = ExecutionContext(exec_mode.single_proc)\n",
"run1 = Executor(single_proc_ctx, single_config)\n",
"run1_raw_result = run1.main()\n",
"result = pd.DataFrame(run1_raw_result)\n",
"print(tabulate(result, headers='keys', tablefmt='psql'))\n",
"print()\n",
"\n",
"print(\"Simulation Run 2: Pairwise Execution\")\n",
"print()\n",
"multi_proc_ctx = ExecutionContext(exec_mode.multi_proc)\n",
"run2 = Executor(multi_proc_ctx, configs)\n",
"run2_raw_results = run2.main()\n",
"for raw_result in run2_raw_results:\n",
" result = pd.DataFrame(raw_result)\n",
" print(tabulate(result, headers='keys', tablefmt='psql'))\n",
"print()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@ -1,4 +1,4 @@
wheel
pathos
pipenv
fn
tabulate

View File

@ -1,11 +1,23 @@
from setuptools import setup
from setuptools import setup, find_packages
long_description = "SimCAD is a differential games based simulation software package for research, validation, and \
Computer Aided Design of economic systems. An economic system is treated as a state based model and defined through \
a set of endogenous and exogenous state variables which are updated through mechanisms and environmental processes, \
respectively. Behavioral models, which may be deterministic or stochastic, provide the evolution of the system \
within the action space of the mechanisms. Mathematical formulations of these economic games treat agent utility as \
derived from state rather than direct from action, creating a rich dynamic modeling framework. Simulations may be \
run with a range of initial conditions and parameters for states, behaviors, mechanisms, and environmental \
processes to understand and visualize network behavior under various conditions. Support for A/B testing policies, \
monte carlo analysis and other common numerical methods is provided."
setup(name='SimCAD',
version='0.1',
description='Sim-Cad Enigne',
description="SimCAD: a differential games based simulation software package for research, validation, and \
Computer Aided Design of economic systems",
long_description = long_description,
url='https://github.com/BlockScience/DiffyQ-SimCAD',
author='Joshua E. Jodesty',
author_email='joshua@block.science',
# license='?????',
packages=['SimCAD'],
zip_safe=False)
# license='LICENSE',
packages=find_packages() #['SimCAD']
)

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))

File diff suppressed because it is too large Load Diff

View File

@ -1,28 +1,20 @@
import pandas as pd
from tabulate import tabulate
# The following imports NEED to be in the exact same order
# The following imports NEED to be in the exact 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 simulations.validation import config1, config2
from SimCAD import configs
# ToDo: pass ExecutionContext with execution method as ExecutionContext input
exec_mode = ExecutionMode()
print("Simulation Execution 1: Config 1")
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'))
@ -30,7 +22,6 @@ print("Output:")
print(tabulate(result, headers='keys', tablefmt='psql'))
print()
# print("Simulation Execution 2: Pairwise Execution")
# multi_proc_ctx = ExecutionContext(context=exec_mode.multi_proc)
# run2 = Executor(exec_context=multi_proc_ctx, configs=configs)
@ -41,4 +32,4 @@ print()
# print(tabulate(tensor_field, headers='keys', tablefmt='psql'))
# print("Output:")
# print(tabulate(result, headers='keys', tablefmt='psql'))
# print()
# print()

View File

@ -16,6 +16,7 @@ pp = pprint.PrettyPrinter(indent=4)
# ToDo: handle single param sweep
beta =[Decimal(1), Decimal(2)]
seed = {
'z': np.random.RandomState(1),
'a': np.random.RandomState(2),
@ -23,8 +24,8 @@ seed = {
'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):
@ -46,11 +47,11 @@ def b1m3(step, sL, s):
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]
x = _input['param1']
return (y, x)
@ -84,6 +85,7 @@ def s2m3(step, sL, s, _input):
x = _input['param2']
return (y, x)
# Exogenous States
proc_one_coef_A = 0.7
proc_one_coef_B = 1.3
@ -123,6 +125,7 @@ def env_b(x):
# def what_ever(x):
# return x + 1
# Genesis States
genesis_states = {
's1': Decimal(0.0),
@ -132,6 +135,7 @@ genesis_states = {
'timestamp': '2018-10-01 15:16:24'
}
# remove `exo_update_per_ts` to update every ts
raw_exogenous_states = {
"s3": es3p1, #sweep(beta, es3p1),
@ -144,6 +148,7 @@ exogenous_states['s3'] = rename('parameterized', es3p1)
# ToDo: make env proc trigger field agnostic
# ToDo: input json into function renaming __name__
triggered_env_b = proc_trigger('2018-10-01 15:16:25', env_b)
env_processes = {
"s3": env_a, #sweep(beta, env_a, 'env_a'),
"s4": rename('parameterized', triggered_env_b) #sweep(beta, triggered_env_b)
@ -161,17 +166,17 @@ env_processes = {
mechanisms = {
"m1": {
"behaviors": {
"b1": b1m1, # lambda step, sL, s: s['s1'] + 1,
"b1": b1m1,
"b2": b2m1
},
"states": { # exclude only. TypeError: reduce() of empty sequence with no initial value
"states": {
"s1": s1m1,
"s2": rename('parameterized', s2m1) #s2m1(1) #sweep(beta, s2m1)
"s2": sweep(beta, s2m1) #rename('parameterized', s2m1) #s2m1(1) #sweep(beta, s2m1)
}
},
"m2": {
"behaviors": {
"b1": rename('parameterized', b1m2), #b1m2(1) #sweep(beta, b1m2),
"b1": sweep(beta, b1m2), #rename('parameterized', b1m2), #b1m2(1) #sweep(beta, b1m2),
"b2": b2m2
},
"states": {
@ -191,6 +196,28 @@ mechanisms = {
}
}
def mech_sweep(mechanisms):
sweep_lists = []
new_mechanisms = deepcopy(mechanisms)
for mech, update_types in new_mechanisms.items():
for update_type, fkv in update_types.items():
for sk, vfs in fkv.items():
if isinstance(vfs, list):
for vf in vfs:
sweep_lists.append((sk,vf))
zipped_sweep_lists = []
it = iter(sweep_lists)
the_len = len(next(it))
if all(len(l) == the_len for l in it):
zipped_sweep_lists = list(zip(*sweep_lists))
else:
raise ValueError('not all lists have same length!')
return sweep_lists
pp.pprint(mech_sweep(mechanisms))
sim_config = {
"N": 2,
"T": range(5)
@ -204,7 +231,7 @@ def parameterize_mechanism(mechanisms, param):
for update_type, fkv in update_types.items():
for sk, vf in fkv.items():
if vf.__name__ == 'parameterized':
print(vf.__name__)
# print(vf.__name__)
new_mechanisms[mech][update_type][sk] = vf(param)
del mechanisms
@ -228,21 +255,24 @@ def s2m1(param, a, b, c, d):
return (y, x)
# print(s2m1(1)(1))
pp.pprint(parameterize_mechanism(mechanisms, 1))
# pp.pprint(mechanisms)
# pp.pprint(parameterize_mechanism(mechanisms, 1))
# print(sweep(beta, s2m1))
# pp.pprint(parameterize_states(raw_exogenous_states, 1))
# pp.pprint(parameterize_states(env_processes, 1))
configs.append(
Configuration(
sim_config=sim_config,
state_dict=genesis_states,
seed=seed,
exogenous_states=exogenous_states,
env_processes=env_processes,
mechanisms=parameterize_mechanism(mechanisms, 1)
)
)
# configs.append(
# Configuration(
# sim_config=sim_config,
# state_dict=genesis_states,
# seed=seed,
# exogenous_states=exogenous_states,
# env_processes=env_processes,
# mechanisms=parameterize_mechanism(mechanisms, 1)
# )
# )
# def sweep_config(config, params):
# new_config = deepcopy(config)
@ -283,4 +313,4 @@ configs.append(
# pp.pprint(g.exogenous_states)
# print()
# pp.pprint(g.mechanisms)
# print()
# print()

View File

@ -15,8 +15,8 @@ seed = {
'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):
@ -27,7 +27,6 @@ def b1m2(step, sL, s):
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):
@ -62,6 +61,7 @@ def s2m3(step, sL, s, _input):
x = _input['param2']
return (y, x)
# Exogenous States
proc_one_coef_A = 0.7
proc_one_coef_B = 1.3
@ -92,6 +92,7 @@ def env_b(x):
# def what_ever(x):
# return x + 1
# Genesis States
genesis_states = {
's1': Decimal(0.0),
@ -101,8 +102,8 @@ genesis_states = {
'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,
@ -111,32 +112,20 @@ exogenous_states = exo_update_per_ts(
}
)
# 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,
"b1": b1m1,
# "b2": b2m1
},
"states": { # exclude only. TypeError: reduce() of empty sequence with no initial value
"states": {
"s1": s1m1,
# "s2": s2m1
}
@ -163,11 +152,13 @@ mechanisms = {
}
}
sim_config = {
"N": 2,
"T": range(5)
}
configs.append(
Configuration(
sim_config=sim_config,
@ -177,4 +168,4 @@ configs.append(
env_processes=env_processes,
mechanisms=mechanisms
)
)
)

View File

@ -15,48 +15,49 @@ seed = {
}
# Behaviors per Mechanism
# Different return types per mechanism ?? *** No ***
def b1m1(step, sL, s):
return s['s1'] + 1
return {'param1': 1}
def b2m1(step, sL, s):
return s['s1'] + 1
return {'param2': 4}
def b1m2(step, sL, s):
return s['s1'] + 1
return {'param1': 'a', 'param2': 2}
def b2m2(step, sL, s):
return s['s1'] + 1
return {'param1': 'b', 'param2': 4}
def b1m3(step, sL, s):
return s['s1'] + 1
return {'param1': ['c'], 'param2': np.array([10, 100])}
def b2m3(step, sL, s):
return s['s2'] + 1
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 = s['s1'] + _input
x = _input['param1'] #+ [Coef1 x 5]
return (y, x)
def s2m1(step, sL, s, _input):
y = 's2'
x = s['s2'] + _input
x = _input['param2'] #+ [Coef2 x 5]
return (y, x)
def s1m2(step, sL, s, _input):
y = 's1'
x = s['s1'] + _input
x = _input['param1']
return (y, x)
def s2m2(step, sL, s, _input):
y = 's2'
x = s['s2'] + _input
x = _input['param2']
return (y, x)
def s1m3(step, sL, s, _input):
y = 's1'
x = s['s1'] + _input
x = _input['param1']
return (y, x)
def s2m3(step, sL, s, _input):
y = 's2'
x = s['s2'] + s['s3'] + _input
x = _input['param2']
return (y, x)
# Exogenous States
@ -73,22 +74,24 @@ def es4p2(step, sL, s, _input):
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
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, s['timestamp'], seconds=1)
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
return 5
def env_b(x):
return 10
# def what_ever(x):
# return x + 1
# Genesis States
state_dict = {
genesis_states = {
's1': Decimal(0.0),
's2': Decimal(0.0),
's3': Decimal(1.0),
@ -96,6 +99,7 @@ state_dict = {
'timestamp': '2018-10-01 15:16:24'
}
# remove `exo_update_per_ts` to update every ts
exogenous_states = exo_update_per_ts(
{
"s3": es3p1,
@ -104,17 +108,26 @@ exogenous_states = exo_update_per_ts(
}
)
# ToDo: make env proc trigger field agnostic
# ToDo: input json into function renaming __name__
env_processes = {
"s3": proc_trigger('2018-10-01 15:16:25', env_a),
"s3": 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 ]
# 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": {
@ -153,4 +166,13 @@ sim_config = {
"T": range(5)
}
configs.append(Configuration(sim_config, state_dict, seed, exogenous_states, env_processes, mechanisms, behavior_udaf))
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

@ -0,0 +1,180 @@
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
)
)