Compare commits
31 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
8823959552 | |
|
|
9d02c0562c | |
|
|
ea7dad9367 | |
|
|
4315447b66 | |
|
|
c8d8524842 | |
|
|
e7eaff2363 | |
|
|
744d85c5ca | |
|
|
b0de56776b | |
|
|
12f88db31b | |
|
|
fd4ecb3839 | |
|
|
a4f252f85f | |
|
|
73183cf666 | |
|
|
aee638e309 | |
|
|
ee8bc97ce0 | |
|
|
47b326351f | |
|
|
7f5bcdebd3 | |
|
|
5f2389d8b7 | |
|
|
1f524b230b | |
|
|
07917ef2c6 | |
|
|
c9768a5985 | |
|
|
7d206183b6 | |
|
|
dbd00c8581 | |
|
|
5afc9bffbe | |
|
|
0d8b97267e | |
|
|
374590876c | |
|
|
cf525b89d1 | |
|
|
d9c1b50de9 | |
|
|
437fd81f08 | |
|
|
bdbda2685d | |
|
|
96187bbdb6 | |
|
|
b098a754e4 |
Binary file not shown.
|
After Width: | Height: | Size: 502 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 528 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 578 KiB |
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
Binary file not shown.
|
After Width: | Height: | Size: 280 KiB |
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
@ -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
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
@ -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))
|
|
||||||
|
|
@ -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))
|
|
||||||
|
|
@ -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))
|
|
||||||
|
|
@ -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))
|
|
||||||
|
|
@ -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))
|
|
||||||
|
|
@ -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))
|
|
||||||
|
|
@ -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))
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
import pandas as pd
|
|
||||||
from tabulate import tabulate
|
|
||||||
|
|
||||||
# The following imports NEED to be in the exact same order
|
|
||||||
from SimCAD.engine import ExecutionMode, ExecutionContext, Executor
|
|
||||||
from simulations.validation import config1, config2
|
|
||||||
# from simulations.validation import base_config1, base_config2
|
|
||||||
# from simulations.barlin import config4
|
|
||||||
# from simulations.zx import config_zx
|
|
||||||
# from simulations.barlin import config6atemp #config6aworks,
|
|
||||||
from SimCAD import configs
|
|
||||||
|
|
||||||
# ToDo: pass ExecutionContext with execution method as ExecutionContext input
|
|
||||||
|
|
||||||
exec_mode = ExecutionMode()
|
|
||||||
|
|
||||||
|
|
||||||
print("Simulation Execution 1")
|
|
||||||
print()
|
|
||||||
first_config = [configs[0]] # from config1
|
|
||||||
single_proc_ctx = ExecutionContext(context=exec_mode.single_proc)
|
|
||||||
run1 = Executor(exec_context=single_proc_ctx, configs=first_config)
|
|
||||||
run1_raw_result, tensor_field = run1.main()
|
|
||||||
result = pd.DataFrame(run1_raw_result)
|
|
||||||
# result.to_csv('~/Projects/DiffyQ-SimCAD/results/config4.csv', sep=',')
|
|
||||||
print()
|
|
||||||
print("Tensor Field:")
|
|
||||||
print(tabulate(tensor_field, headers='keys', tablefmt='psql'))
|
|
||||||
print("Output:")
|
|
||||||
print(tabulate(result, headers='keys', tablefmt='psql'))
|
|
||||||
print()
|
|
||||||
|
|
||||||
print("Simulation Execution 2: Pairwise Execution")
|
|
||||||
print()
|
|
||||||
multi_proc_ctx = ExecutionContext(context=exec_mode.multi_proc)
|
|
||||||
run2 = Executor(exec_context=multi_proc_ctx, configs=configs)
|
|
||||||
for raw_result, tensor_field in run2.main():
|
|
||||||
result = pd.DataFrame(raw_result)
|
|
||||||
print()
|
|
||||||
print("Tensor Field:")
|
|
||||||
print(tabulate(tensor_field, headers='keys', tablefmt='psql'))
|
|
||||||
print("Output:")
|
|
||||||
print(tabulate(result, headers='keys', tablefmt='psql'))
|
|
||||||
print()
|
|
||||||
|
|
@ -1,171 +0,0 @@
|
||||||
from decimal import Decimal
|
|
||||||
import numpy as np
|
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
from SimCAD import configs
|
|
||||||
from SimCAD.configuration import Configuration
|
|
||||||
from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \
|
|
||||||
ep_time_step
|
|
||||||
|
|
||||||
seed = {
|
|
||||||
'z': np.random.RandomState(1),
|
|
||||||
'a': np.random.RandomState(2),
|
|
||||||
'b': np.random.RandomState(3),
|
|
||||||
'c': np.random.RandomState(3)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Behaviors per Mechanism
|
|
||||||
# Different return types per mechanism ?? *** No ***
|
|
||||||
def b1m1(step, sL, s):
|
|
||||||
return {'param1': 1}
|
|
||||||
def b2m1(step, sL, s):
|
|
||||||
return {'param1': 1}
|
|
||||||
|
|
||||||
def b1m2(step, sL, s):
|
|
||||||
return {'param1': 1, 'param2': 2}
|
|
||||||
def b2m2(step, sL, s):
|
|
||||||
return {'param1': 1, 'param2': 4}
|
|
||||||
|
|
||||||
def b1m3(step, sL, s):
|
|
||||||
return {'param1': 1, 'param2': np.array([10, 100])}
|
|
||||||
def b2m3(step, sL, s):
|
|
||||||
return {'param1': 1, 'param2': np.array([20, 200])}
|
|
||||||
|
|
||||||
# deff not more than 2
|
|
||||||
# Internal States per Mechanism
|
|
||||||
def s1m1(step, sL, s, _input):
|
|
||||||
y = 's1'
|
|
||||||
x = s['s1'] + _input['param1']
|
|
||||||
return (y, x)
|
|
||||||
def s2m1(step, sL, s, _input):
|
|
||||||
y = 's2'
|
|
||||||
x = s['s2'] + _input['param1']
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
def s1m2(step, sL, s, _input):
|
|
||||||
y = 's1'
|
|
||||||
x = s['s1'] + _input['param1']
|
|
||||||
return (y, x)
|
|
||||||
def s2m2(step, sL, s, _input):
|
|
||||||
y = 's2'
|
|
||||||
x = s['s2'] + _input['param1']
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
def s1m3(step, sL, s, _input):
|
|
||||||
y = 's1'
|
|
||||||
x = s['s1'] + _input['param1']
|
|
||||||
return (y, x)
|
|
||||||
def s2m3(step, sL, s, _input):
|
|
||||||
y = 's2'
|
|
||||||
x = s['s2'] + _input['param1']
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
# Exogenous States
|
|
||||||
proc_one_coef_A = 0.7
|
|
||||||
proc_one_coef_B = 1.3
|
|
||||||
|
|
||||||
def es3p1(step, sL, s, _input):
|
|
||||||
y = 's3'
|
|
||||||
x = s['s3'] * bound_norm_random(seed['a'], proc_one_coef_A, proc_one_coef_B)
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
def es4p2(step, sL, s, _input):
|
|
||||||
y = 's4'
|
|
||||||
x = s['s4'] * bound_norm_random(seed['b'], proc_one_coef_A, proc_one_coef_B)
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
ts_format = '%Y-%m-%d %H:%M:%S'
|
|
||||||
t_delta = timedelta(days=0, minutes=0, seconds=1)
|
|
||||||
def es5p2(step, sL, s, _input):
|
|
||||||
y = 'timestamp'
|
|
||||||
x = ep_time_step(s, dt_str=s['timestamp'], fromat_str=ts_format, _timedelta=t_delta)
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
|
|
||||||
# Environment States
|
|
||||||
def env_a(x):
|
|
||||||
return 10
|
|
||||||
def env_b(x):
|
|
||||||
return 10
|
|
||||||
# def what_ever(x):
|
|
||||||
# return x + 1
|
|
||||||
|
|
||||||
# Genesis States
|
|
||||||
genesis_states = {
|
|
||||||
's1': Decimal(0.0),
|
|
||||||
's2': Decimal(0.0),
|
|
||||||
's3': Decimal(1.0),
|
|
||||||
's4': Decimal(1.0),
|
|
||||||
'timestamp': '2018-10-01 15:16:24'
|
|
||||||
}
|
|
||||||
|
|
||||||
# remove `exo_update_per_ts` to update every ts
|
|
||||||
exogenous_states = exo_update_per_ts(
|
|
||||||
{
|
|
||||||
"s3": es3p1,
|
|
||||||
"s4": es4p2,
|
|
||||||
"timestamp": es5p2
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
# make env proc trigger field agnostic
|
|
||||||
|
|
||||||
# ToDo: Bug - Can't use environments without proc_trigger. TypeError: 'int' object is not callable
|
|
||||||
# "/Users/jjodesty/Projects/DiffyQ-SimCAD/SimCAD/engine/simulation.py"
|
|
||||||
env_processes = {
|
|
||||||
# "s3": env_a,
|
|
||||||
# "s4": env_b
|
|
||||||
"s3": proc_trigger('2018-10-01 15:16:25', env_a),
|
|
||||||
"s4": proc_trigger('2018-10-01 15:16:25', env_b)
|
|
||||||
}
|
|
||||||
|
|
||||||
# need at least 1 behaviour and 1 state function for the 1st mech with behaviors
|
|
||||||
# mechanisms = {}
|
|
||||||
mechanisms = {
|
|
||||||
"m1": {
|
|
||||||
"behaviors": {
|
|
||||||
"b1": b1m1, # lambda step, sL, s: s['s1'] + 1,
|
|
||||||
"b2": b2m1
|
|
||||||
},
|
|
||||||
"states": { # exclude only. TypeError: reduce() of empty sequence with no initial value
|
|
||||||
"s1": s1m1,
|
|
||||||
"s2": s2m1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"m2": {
|
|
||||||
"behaviors": {
|
|
||||||
"b1": b1m2,
|
|
||||||
"b2": b2m2
|
|
||||||
},
|
|
||||||
"states": {
|
|
||||||
"s1": s1m2,
|
|
||||||
"s2": s2m2
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"m3": {
|
|
||||||
"behaviors": {
|
|
||||||
"b1": b1m3,
|
|
||||||
"b2": b2m3
|
|
||||||
},
|
|
||||||
"states": {
|
|
||||||
"s1": s1m3,
|
|
||||||
"s2": s2m3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sim_config = {
|
|
||||||
"N": 2,
|
|
||||||
"T": range(5)
|
|
||||||
}
|
|
||||||
|
|
||||||
configs.append(
|
|
||||||
Configuration(
|
|
||||||
sim_config=sim_config,
|
|
||||||
state_dict=genesis_states,
|
|
||||||
seed=seed,
|
|
||||||
exogenous_states=exogenous_states,
|
|
||||||
env_processes=env_processes,
|
|
||||||
mechanisms=mechanisms
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
@ -1,180 +0,0 @@
|
||||||
from decimal import Decimal
|
|
||||||
import numpy as np
|
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
from SimCAD import configs
|
|
||||||
from SimCAD.configuration import Configuration
|
|
||||||
from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \
|
|
||||||
ep_time_step
|
|
||||||
|
|
||||||
|
|
||||||
seed = {
|
|
||||||
'z': np.random.RandomState(1),
|
|
||||||
'a': np.random.RandomState(2),
|
|
||||||
'b': np.random.RandomState(3),
|
|
||||||
'c': np.random.RandomState(3)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Behaviors per Mechanism
|
|
||||||
# Different return types per mechanism ?? *** No ***
|
|
||||||
def b1m1(step, sL, s):
|
|
||||||
return {'param1': 1}
|
|
||||||
def b2m1(step, sL, s):
|
|
||||||
return {'param2': 4}
|
|
||||||
|
|
||||||
def b1m2(step, sL, s):
|
|
||||||
return {'param1': 'a', 'param2': 2}
|
|
||||||
def b2m2(step, sL, s):
|
|
||||||
return {'param1': 'b', 'param2': 4}
|
|
||||||
|
|
||||||
|
|
||||||
def b1m3(step, sL, s):
|
|
||||||
return {'param1': ['c'], 'param2': np.array([10, 100])}
|
|
||||||
def b2m3(step, sL, s):
|
|
||||||
return {'param1': ['d'], 'param2': np.array([20, 200])}
|
|
||||||
|
|
||||||
|
|
||||||
# Internal States per Mechanism
|
|
||||||
def s1m1(step, sL, s, _input):
|
|
||||||
y = 's1'
|
|
||||||
x = _input['param1']
|
|
||||||
return (y, x)
|
|
||||||
def s2m1(step, sL, s, _input):
|
|
||||||
y = 's2'
|
|
||||||
x = _input['param2']
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
def s1m2(step, sL, s, _input):
|
|
||||||
y = 's1'
|
|
||||||
x = _input['param1']
|
|
||||||
return (y, x)
|
|
||||||
def s2m2(step, sL, s, _input):
|
|
||||||
y = 's2'
|
|
||||||
x = _input['param2']
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
def s1m3(step, sL, s, _input):
|
|
||||||
y = 's1'
|
|
||||||
x = _input['param1']
|
|
||||||
return (y, x)
|
|
||||||
def s2m3(step, sL, s, _input):
|
|
||||||
y = 's2'
|
|
||||||
x = _input['param2']
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
# Exogenous States
|
|
||||||
proc_one_coef_A = 0.7
|
|
||||||
proc_one_coef_B = 1.3
|
|
||||||
|
|
||||||
def es3p1(step, sL, s, _input):
|
|
||||||
y = 's3'
|
|
||||||
x = s['s3'] * bound_norm_random(seed['a'], proc_one_coef_A, proc_one_coef_B)
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
def es4p2(step, sL, s, _input):
|
|
||||||
y = 's4'
|
|
||||||
x = s['s4'] * bound_norm_random(seed['b'], proc_one_coef_A, proc_one_coef_B)
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
ts_format = '%Y-%m-%d %H:%M:%S'
|
|
||||||
t_delta = timedelta(days=0, minutes=0, seconds=1)
|
|
||||||
def es5p2(step, sL, s, _input):
|
|
||||||
y = 'timestamp'
|
|
||||||
x = ep_time_step(s, dt_str=s['timestamp'], fromat_str=ts_format, _timedelta=t_delta)
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
|
|
||||||
# Environment States
|
|
||||||
def env_a(x):
|
|
||||||
return 10
|
|
||||||
def env_b(x):
|
|
||||||
return 10
|
|
||||||
# def what_ever(x):
|
|
||||||
# return x + 1
|
|
||||||
|
|
||||||
# Genesis States
|
|
||||||
genesis_states = {
|
|
||||||
's1': Decimal(0.0),
|
|
||||||
's2': Decimal(0.0),
|
|
||||||
's3': Decimal(1.0),
|
|
||||||
's4': Decimal(1.0),
|
|
||||||
'timestamp': '2018-10-01 15:16:24'
|
|
||||||
}
|
|
||||||
|
|
||||||
# remove `exo_update_per_ts` to update every ts
|
|
||||||
# why `exo_update_per_ts` here instead of `env_processes`
|
|
||||||
exogenous_states = exo_update_per_ts(
|
|
||||||
{
|
|
||||||
"s3": es3p1,
|
|
||||||
"s4": es4p2,
|
|
||||||
"timestamp": es5p2
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
# make env proc trigger field agnostic
|
|
||||||
env_processes = {
|
|
||||||
"s3": proc_trigger('2018-10-01 15:16:25', env_a),
|
|
||||||
"s4": proc_trigger('2018-10-01 15:16:25', env_b)
|
|
||||||
}
|
|
||||||
|
|
||||||
# lambdas
|
|
||||||
# genesis Sites should always be there
|
|
||||||
# [1, 2]
|
|
||||||
# behavior_ops = [ foldr(_ + _), lambda x: x + 0 ]
|
|
||||||
|
|
||||||
|
|
||||||
# [1, 2] = {'b1': ['a'], 'b2', [1]} =
|
|
||||||
# behavior_ops = [behavior_to_dict, print_fwd, sum_dict_values]
|
|
||||||
# behavior_ops = [foldr(dict_elemwise_sum())]
|
|
||||||
# behavior_ops = []
|
|
||||||
|
|
||||||
# need at least 1 behaviour and 1 state function for the 1st mech with behaviors
|
|
||||||
# mechanisms = {}
|
|
||||||
mechanisms = {
|
|
||||||
"m1": {
|
|
||||||
"behaviors": {
|
|
||||||
"b1": b1m1, # lambda step, sL, s: s['s1'] + 1,
|
|
||||||
# "b2": b2m1
|
|
||||||
},
|
|
||||||
"states": { # exclude only. TypeError: reduce() of empty sequence with no initial value
|
|
||||||
"s1": s1m1,
|
|
||||||
# "s2": s2m1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"m2": {
|
|
||||||
"behaviors": {
|
|
||||||
"b1": b1m2,
|
|
||||||
# "b2": b2m2
|
|
||||||
},
|
|
||||||
"states": {
|
|
||||||
"s1": s1m2,
|
|
||||||
# "s2": s2m2
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"m3": {
|
|
||||||
"behaviors": {
|
|
||||||
"b1": b1m3,
|
|
||||||
"b2": b2m3
|
|
||||||
},
|
|
||||||
"states": {
|
|
||||||
"s1": s1m3,
|
|
||||||
"s2": s2m3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sim_config = {
|
|
||||||
"N": 2,
|
|
||||||
"T": range(5)
|
|
||||||
}
|
|
||||||
|
|
||||||
configs.append(
|
|
||||||
Configuration(
|
|
||||||
sim_config=sim_config,
|
|
||||||
state_dict=genesis_states,
|
|
||||||
seed=seed,
|
|
||||||
exogenous_states=exogenous_states,
|
|
||||||
env_processes=env_processes,
|
|
||||||
mechanisms=mechanisms
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
@ -1,176 +0,0 @@
|
||||||
from decimal import Decimal
|
|
||||||
import numpy as np
|
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
from SimCAD import configs
|
|
||||||
from SimCAD.configuration import Configuration
|
|
||||||
from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \
|
|
||||||
ep_time_step
|
|
||||||
|
|
||||||
seed = {
|
|
||||||
'z': np.random.RandomState(1),
|
|
||||||
'a': np.random.RandomState(2),
|
|
||||||
'b': np.random.RandomState(3),
|
|
||||||
'c': np.random.RandomState(3)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Behaviors per Mechanism
|
|
||||||
# Different return types per mechanism ?? *** No ***
|
|
||||||
def b1m1(step, sL, s):
|
|
||||||
return {'param1': 1}
|
|
||||||
def b2m1(step, sL, s):
|
|
||||||
return {'param2': 4}
|
|
||||||
|
|
||||||
def b1m2(step, sL, s):
|
|
||||||
return {'param1': 'a', 'param2': 2}
|
|
||||||
def b2m2(step, sL, s):
|
|
||||||
return {'param1': 'b', 'param2': 4}
|
|
||||||
|
|
||||||
def b1m3(step, sL, s):
|
|
||||||
return {'param1': ['c'], 'param2': np.array([10, 100])}
|
|
||||||
def b2m3(step, sL, s):
|
|
||||||
return {'param1': ['d'], 'param2': np.array([20, 200])}
|
|
||||||
|
|
||||||
# deff not more than 2
|
|
||||||
# Internal States per Mechanism
|
|
||||||
def s1m1(step, sL, s, _input):
|
|
||||||
y = 's1'
|
|
||||||
x = _input['param1'] #+ [Coef1 x 5]
|
|
||||||
return (y, x)
|
|
||||||
def s2m1(step, sL, s, _input):
|
|
||||||
y = 's2'
|
|
||||||
x = _input['param2'] #+ [Coef2 x 5]
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
def s1m2(step, sL, s, _input):
|
|
||||||
y = 's1'
|
|
||||||
x = _input['param1']
|
|
||||||
return (y, x)
|
|
||||||
def s2m2(step, sL, s, _input):
|
|
||||||
y = 's2'
|
|
||||||
x = _input['param2']
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
def s1m3(step, sL, s, _input):
|
|
||||||
y = 's1'
|
|
||||||
x = _input['param1']
|
|
||||||
return (y, x)
|
|
||||||
def s2m3(step, sL, s, _input):
|
|
||||||
y = 's2'
|
|
||||||
x = _input['param2']
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
# Exogenous States
|
|
||||||
proc_one_coef_A = 0.7
|
|
||||||
proc_one_coef_B = 1.3
|
|
||||||
|
|
||||||
def es3p1(step, sL, s, _input):
|
|
||||||
y = 's3'
|
|
||||||
x = s['s3'] * bound_norm_random(seed['a'], proc_one_coef_A, proc_one_coef_B)
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
def es4p2(step, sL, s, _input):
|
|
||||||
y = 's4'
|
|
||||||
x = s['s4'] * bound_norm_random(seed['b'], proc_one_coef_A, proc_one_coef_B)
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
ts_format = '%Y-%m-%d %H:%M:%S'
|
|
||||||
t_delta = timedelta(days=0, minutes=0, seconds=1)
|
|
||||||
def es5p2(step, sL, s, _input):
|
|
||||||
y = 'timestamp'
|
|
||||||
x = ep_time_step(s, dt_str=s['timestamp'], fromat_str=ts_format, _timedelta=t_delta)
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
|
|
||||||
# Environment States
|
|
||||||
def env_a(x):
|
|
||||||
return 10
|
|
||||||
def env_b(x):
|
|
||||||
return 10
|
|
||||||
# def what_ever(x):
|
|
||||||
# return x + 1
|
|
||||||
|
|
||||||
# Genesis States
|
|
||||||
genesis_states = {
|
|
||||||
's1': Decimal(0.0),
|
|
||||||
's2': Decimal(0.0),
|
|
||||||
's3': Decimal(1.0),
|
|
||||||
's4': Decimal(1.0),
|
|
||||||
'timestamp': '2018-10-01 15:16:24'
|
|
||||||
}
|
|
||||||
|
|
||||||
# remove `exo_update_per_ts` to update every ts
|
|
||||||
exogenous_states = exo_update_per_ts(
|
|
||||||
{
|
|
||||||
"s3": es3p1,
|
|
||||||
"s4": es4p2,
|
|
||||||
"timestamp": es5p2
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
# make env proc trigger field agnostic
|
|
||||||
env_processes = {
|
|
||||||
"s3": proc_trigger('2018-10-01 15:16:25', env_a),
|
|
||||||
"s4": proc_trigger('2018-10-01 15:16:25', env_b)
|
|
||||||
}
|
|
||||||
|
|
||||||
# lambdas
|
|
||||||
# genesis Sites should always be there
|
|
||||||
# [1, 2]
|
|
||||||
# behavior_ops = [ foldr(_ + _), lambda x: x + 0 ]
|
|
||||||
|
|
||||||
# [1, 2] = {'b1': ['a'], 'b2', [1]} =
|
|
||||||
# behavior_ops = [ behavior_to_dict, print_fwd, sum_dict_values ]
|
|
||||||
# behavior_ops = [foldr(dict_elemwise_sum())]
|
|
||||||
# behavior_ops = [foldr(lambda a, b: a + b)]
|
|
||||||
|
|
||||||
# need at least 1 behaviour and 1 state function for the 1st mech with behaviors
|
|
||||||
# mechanisms = {}
|
|
||||||
mechanisms = {
|
|
||||||
"m1": {
|
|
||||||
"behaviors": {
|
|
||||||
"b1": b1m1, # lambda step, sL, s: s['s1'] + 1,
|
|
||||||
"b2": b2m1
|
|
||||||
},
|
|
||||||
"states": { # exclude only. TypeError: reduce() of empty sequence with no initial value
|
|
||||||
"s1": s1m1,
|
|
||||||
"s2": s2m1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"m2": {
|
|
||||||
"behaviors": {
|
|
||||||
"b1": b1m2,
|
|
||||||
"b2": b2m2
|
|
||||||
},
|
|
||||||
"states": {
|
|
||||||
"s1": s1m2,
|
|
||||||
"s2": s2m2
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"m3": {
|
|
||||||
"behaviors": {
|
|
||||||
"b1": b1m3,
|
|
||||||
"b2": b2m3
|
|
||||||
},
|
|
||||||
"states": {
|
|
||||||
"s1": s1m3,
|
|
||||||
"s2": s2m3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sim_config = {
|
|
||||||
"N": 2,
|
|
||||||
"T": range(5)
|
|
||||||
}
|
|
||||||
|
|
||||||
configs.append(
|
|
||||||
Configuration(
|
|
||||||
sim_config=sim_config,
|
|
||||||
state_dict=genesis_states,
|
|
||||||
seed=seed,
|
|
||||||
exogenous_states=exogenous_states,
|
|
||||||
env_processes=env_processes,
|
|
||||||
mechanisms=mechanisms
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
@ -1,180 +0,0 @@
|
||||||
from decimal import Decimal
|
|
||||||
import numpy as np
|
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
from SimCAD import configs
|
|
||||||
from SimCAD.configuration import Configuration
|
|
||||||
from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \
|
|
||||||
ep_time_step
|
|
||||||
|
|
||||||
|
|
||||||
seed = {
|
|
||||||
'z': np.random.RandomState(1),
|
|
||||||
'a': np.random.RandomState(2),
|
|
||||||
'b': np.random.RandomState(3),
|
|
||||||
'c': np.random.RandomState(3)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Behaviors per Mechanism
|
|
||||||
# Different return types per mechanism ?? *** No ***
|
|
||||||
def b1m1(step, sL, s):
|
|
||||||
return {'param1': 1}
|
|
||||||
def b2m1(step, sL, s):
|
|
||||||
return {'param2': 4}
|
|
||||||
|
|
||||||
def b1m2(step, sL, s):
|
|
||||||
return {'param1': 'a', 'param2': 2}
|
|
||||||
def b2m2(step, sL, s):
|
|
||||||
return {'param1': 'b', 'param2': 4}
|
|
||||||
|
|
||||||
|
|
||||||
def b1m3(step, sL, s):
|
|
||||||
return {'param1': ['c'], 'param2': np.array([10, 100])}
|
|
||||||
def b2m3(step, sL, s):
|
|
||||||
return {'param1': ['d'], 'param2': np.array([20, 200])}
|
|
||||||
|
|
||||||
|
|
||||||
# Internal States per Mechanism
|
|
||||||
def s1m1(step, sL, s, _input):
|
|
||||||
y = 's1'
|
|
||||||
x = _input['param1']
|
|
||||||
return (y, x)
|
|
||||||
def s2m1(step, sL, s, _input):
|
|
||||||
y = 's2'
|
|
||||||
x = _input['param2']
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
def s1m2(step, sL, s, _input):
|
|
||||||
y = 's1'
|
|
||||||
x = _input['param1']
|
|
||||||
return (y, x)
|
|
||||||
def s2m2(step, sL, s, _input):
|
|
||||||
y = 's2'
|
|
||||||
x = _input['param2']
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
def s1m3(step, sL, s, _input):
|
|
||||||
y = 's1'
|
|
||||||
x = _input['param1']
|
|
||||||
return (y, x)
|
|
||||||
def s2m3(step, sL, s, _input):
|
|
||||||
y = 's2'
|
|
||||||
x = _input['param2']
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
# Exogenous States
|
|
||||||
proc_one_coef_A = 0.7
|
|
||||||
proc_one_coef_B = 1.3
|
|
||||||
|
|
||||||
def es3p1(step, sL, s, _input):
|
|
||||||
y = 's3'
|
|
||||||
x = s['s3'] * bound_norm_random(seed['a'], proc_one_coef_A, proc_one_coef_B)
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
def es4p2(step, sL, s, _input):
|
|
||||||
y = 's4'
|
|
||||||
x = s['s4'] * bound_norm_random(seed['b'], proc_one_coef_A, proc_one_coef_B)
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
ts_format = '%Y-%m-%d %H:%M:%S'
|
|
||||||
t_delta = timedelta(days=0, minutes=0, seconds=1)
|
|
||||||
def es5p2(step, sL, s, _input):
|
|
||||||
y = 'timestamp'
|
|
||||||
x = ep_time_step(s, dt_str=s['timestamp'], fromat_str=ts_format, _timedelta=t_delta)
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
|
|
||||||
# Environment States
|
|
||||||
def env_a(x):
|
|
||||||
return 10
|
|
||||||
def env_b(x):
|
|
||||||
return 10
|
|
||||||
# def what_ever(x):
|
|
||||||
# return x + 1
|
|
||||||
|
|
||||||
# Genesis States
|
|
||||||
genesis_states = {
|
|
||||||
's1': Decimal(0.0),
|
|
||||||
's2': Decimal(0.0),
|
|
||||||
's3': Decimal(1.0),
|
|
||||||
's4': Decimal(1.0),
|
|
||||||
'timestamp': '2018-10-01 15:16:24'
|
|
||||||
}
|
|
||||||
|
|
||||||
# remove `exo_update_per_ts` to update every ts
|
|
||||||
# why `exo_update_per_ts` here instead of `env_processes`
|
|
||||||
exogenous_states = exo_update_per_ts(
|
|
||||||
{
|
|
||||||
"s3": es3p1,
|
|
||||||
"s4": es4p2,
|
|
||||||
"timestamp": es5p2
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
# make env proc trigger field agnostic
|
|
||||||
env_processes = {
|
|
||||||
"s3": proc_trigger('2018-10-01 15:16:25', env_a),
|
|
||||||
"s4": proc_trigger('2018-10-01 15:16:25', env_b)
|
|
||||||
}
|
|
||||||
|
|
||||||
# lambdas
|
|
||||||
# genesis Sites should always be there
|
|
||||||
# [1, 2]
|
|
||||||
# behavior_ops = [ foldr(_ + _), lambda x: x + 0 ]
|
|
||||||
|
|
||||||
|
|
||||||
# [1, 2] = {'b1': ['a'], 'b2', [1]} =
|
|
||||||
# behavior_ops = [behavior_to_dict, print_fwd, sum_dict_values]
|
|
||||||
# behavior_ops = [foldr(dict_elemwise_sum())]
|
|
||||||
# behavior_ops = []
|
|
||||||
|
|
||||||
# need at least 1 behaviour and 1 state function for the 1st mech with behaviors
|
|
||||||
# mechanisms = {}
|
|
||||||
mechanisms = {
|
|
||||||
"m1": {
|
|
||||||
"behaviors": {
|
|
||||||
"b1": b1m1, # lambda step, sL, s: s['s1'] + 1,
|
|
||||||
# "b2": b2m1
|
|
||||||
},
|
|
||||||
"states": { # exclude only. TypeError: reduce() of empty sequence with no initial value
|
|
||||||
"s1": s1m1,
|
|
||||||
# "s2": s2m1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"m2": {
|
|
||||||
"behaviors": {
|
|
||||||
"b1": b1m2,
|
|
||||||
# "b2": b2m2
|
|
||||||
},
|
|
||||||
"states": {
|
|
||||||
"s1": s1m2,
|
|
||||||
# "s2": s2m2
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"m3": {
|
|
||||||
"behaviors": {
|
|
||||||
"b1": b1m3,
|
|
||||||
"b2": b2m3
|
|
||||||
},
|
|
||||||
"states": {
|
|
||||||
"s1": s1m3,
|
|
||||||
"s2": s2m3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sim_config = {
|
|
||||||
"N": 2,
|
|
||||||
"T": range(5)
|
|
||||||
}
|
|
||||||
|
|
||||||
configs.append(
|
|
||||||
Configuration(
|
|
||||||
sim_config=sim_config,
|
|
||||||
state_dict=genesis_states,
|
|
||||||
seed=seed,
|
|
||||||
exogenous_states=exogenous_states,
|
|
||||||
env_processes=env_processes,
|
|
||||||
mechanisms=mechanisms
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
@ -1,156 +0,0 @@
|
||||||
from decimal import Decimal
|
|
||||||
import numpy as np
|
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
from SimCAD import configs
|
|
||||||
from SimCAD.configuration import Configuration
|
|
||||||
from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \
|
|
||||||
ep_time_step
|
|
||||||
|
|
||||||
seed = {
|
|
||||||
'z': np.random.RandomState(1),
|
|
||||||
'a': np.random.RandomState(2),
|
|
||||||
'b': np.random.RandomState(3),
|
|
||||||
'c': np.random.RandomState(3)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Behaviors per Mechanism
|
|
||||||
def b1m1(step, sL, s):
|
|
||||||
return s['s1'] + 1
|
|
||||||
def b2m1(step, sL, s):
|
|
||||||
return s['s1'] + 1
|
|
||||||
|
|
||||||
def b1m2(step, sL, s):
|
|
||||||
return s['s1'] + 1
|
|
||||||
def b2m2(step, sL, s):
|
|
||||||
return s['s1'] + 1
|
|
||||||
|
|
||||||
def b1m3(step, sL, s):
|
|
||||||
return s['s1'] + 1
|
|
||||||
def b2m3(step, sL, s):
|
|
||||||
return s['s2'] + 1
|
|
||||||
|
|
||||||
|
|
||||||
# Internal States per Mechanism
|
|
||||||
def s1m1(step, sL, s, _input):
|
|
||||||
y = 's1'
|
|
||||||
x = s['s1'] + _input
|
|
||||||
return (y, x)
|
|
||||||
def s2m1(step, sL, s, _input):
|
|
||||||
y = 's2'
|
|
||||||
x = s['s2'] + _input
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
def s1m2(step, sL, s, _input):
|
|
||||||
y = 's1'
|
|
||||||
x = s['s1'] + _input
|
|
||||||
return (y, x)
|
|
||||||
def s2m2(step, sL, s, _input):
|
|
||||||
y = 's2'
|
|
||||||
x = s['s2'] + _input
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
def s1m3(step, sL, s, _input):
|
|
||||||
y = 's1'
|
|
||||||
x = s['s1'] + _input
|
|
||||||
return (y, x)
|
|
||||||
def s2m3(step, sL, s, _input):
|
|
||||||
y = 's2'
|
|
||||||
x = s['s2'] + s['s3'] + _input
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
# Exogenous States
|
|
||||||
proc_one_coef_A = 0.7
|
|
||||||
proc_one_coef_B = 1.3
|
|
||||||
|
|
||||||
def es3p1(step, sL, s, _input):
|
|
||||||
y = 's3'
|
|
||||||
x = s['s3'] * bound_norm_random(seed['a'], proc_one_coef_A, proc_one_coef_B)
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
def es4p2(step, sL, s, _input):
|
|
||||||
y = 's4'
|
|
||||||
x = s['s4'] * bound_norm_random(seed['b'], proc_one_coef_A, proc_one_coef_B)
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
def es5p2(step, sL, s, _input): # accept timedelta instead of timedelta params
|
|
||||||
y = 'timestamp'
|
|
||||||
x = ep_time_step(s, s['timestamp'], seconds=1)
|
|
||||||
return (y, x)
|
|
||||||
|
|
||||||
|
|
||||||
# Environment States
|
|
||||||
def env_a(x):
|
|
||||||
return 10
|
|
||||||
def env_b(x):
|
|
||||||
return 10
|
|
||||||
# def what_ever(x):
|
|
||||||
# return x + 1
|
|
||||||
|
|
||||||
# Genesis States
|
|
||||||
state_dict = {
|
|
||||||
's1': Decimal(0.0),
|
|
||||||
's2': Decimal(0.0),
|
|
||||||
's3': Decimal(1.0),
|
|
||||||
's4': Decimal(1.0),
|
|
||||||
'timestamp': '2018-10-01 15:16:24'
|
|
||||||
}
|
|
||||||
|
|
||||||
exogenous_states = exo_update_per_ts(
|
|
||||||
{
|
|
||||||
"s3": es3p1,
|
|
||||||
"s4": es4p2,
|
|
||||||
"timestamp": es5p2
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
env_processes = {
|
|
||||||
"s3": proc_trigger('2018-10-01 15:16:25', env_a),
|
|
||||||
"s4": proc_trigger('2018-10-01 15:16:25', env_b)
|
|
||||||
}
|
|
||||||
|
|
||||||
# lambdas
|
|
||||||
# genesis Sites should always be there
|
|
||||||
# [1, 2]
|
|
||||||
# User Defined Aggregate Function
|
|
||||||
behavior_udaf = [ foldr(_ + _), lambda x: x + 0 ]
|
|
||||||
# need at least 1 behaviour and 1 state function for the 1st mech with behaviors
|
|
||||||
mechanisms = {
|
|
||||||
"m1": {
|
|
||||||
"behaviors": {
|
|
||||||
"b1": b1m1, # lambda step, sL, s: s['s1'] + 1,
|
|
||||||
"b2": b2m1
|
|
||||||
},
|
|
||||||
"states": { # exclude only. TypeError: reduce() of empty sequence with no initial value
|
|
||||||
"s1": s1m1,
|
|
||||||
"s2": s2m1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"m2": {
|
|
||||||
"behaviors": {
|
|
||||||
"b1": b1m2,
|
|
||||||
"b2": b2m2
|
|
||||||
},
|
|
||||||
"states": {
|
|
||||||
"s1": s1m2,
|
|
||||||
"s2": s2m2
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"m3": {
|
|
||||||
"behaviors": {
|
|
||||||
"b1": b1m3,
|
|
||||||
"b2": b2m3
|
|
||||||
},
|
|
||||||
"states": {
|
|
||||||
"s1": s1m3,
|
|
||||||
"s2": s2m3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sim_config = {
|
|
||||||
"N": 2,
|
|
||||||
"T": range(5)
|
|
||||||
}
|
|
||||||
|
|
||||||
configs.append(Configuration(sim_config, state_dict, seed, exogenous_states, env_processes, mechanisms, behavior_udaf))
|
|
||||||
Loading…
Reference in New Issue