Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: postgres investigations #364

Draft
wants to merge 13 commits into
base: develop
Choose a base branch
from
200 changes: 200 additions & 0 deletions parameter_results/MarginScalingFactors/MarginScalingFactors.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "41b7ce68",
"metadata": {},
"source": [
"# Network Parameter Experiment: `market.margin.scalingFactor`\n",
"\n",
"Experiment varies the network parameter `market.margin.scalingFactor` to the following two sets of values:\n",
"\n",
"- `{\"search_level\": 1.050, \"initial_margin\": 1.100, \"collateral_release\": 1.150}`\n",
"- `{\"search_level\": 1.001, \"initial_margin\": 2.000, \"collateral_release\": 4.000}`\n",
"\n",
"As the various scaling factors increase, the market-maker should have a larger balance in their margin account.\n",
"\n",
"Notebook also shows the parameters affect on the size of the data-node postgres database."
]
},
{
"cell_type": "markdown",
"id": "cb1f77a6",
"metadata": {},
"source": [
"## Notebook Setup"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5e230b76",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from parameter_results.toolkit import SingleParameterExperimentTk\n",
"\n",
"from vega_sim.scenario.common.utils.price_process import Granularity"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "78ca09ea",
"metadata": {},
"outputs": [],
"source": [
"experiment = SingleParameterExperimentTk(\n",
" path=os.getcwd(),\n",
" dt=1,\n",
" granularity=Granularity.MINUTE,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "3feec1fb",
"metadata": {},
"source": [
"## Market Data"
]
},
{
"cell_type": "markdown",
"id": "03f76bec",
"metadata": {},
"source": [
"### Market State\n",
"\n",
"As the experiment uses a pre-configured ParameterExperiment scenario, the market should stay mostly in an \"Active State\"."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3516be4e",
"metadata": {},
"outputs": [],
"source": [
"experiment.plot_results(variables=[\"Market State\"])"
]
},
{
"cell_type": "markdown",
"id": "99fe7488",
"metadata": {},
"source": [
"### Open Interest\n",
"\n",
"The Market Open Interest should be consistent across tested parameter values. Slight variation can be accredited to randomness from use of threads. If results vary dramatically across runs, increase the `environment_step_delay`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "414938e1",
"metadata": {},
"outputs": [],
"source": [
"experiment.plot_results(variables=[\"Market Open Interest\"])"
]
},
{
"cell_type": "markdown",
"id": "5bc65e89",
"metadata": {},
"source": [
"## Market-Maker Results"
]
},
{
"cell_type": "markdown",
"id": "671138bb",
"metadata": {},
"source": [
"### Position\n",
"\n",
"The market-makers Position should be consistent across tested parameter values. Slight variation can be accredited to randomness from use of threads. If results vary dramatically across runs, increase the `environment_step_delay`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ab7b688e",
"metadata": {},
"outputs": [],
"source": [
"experiment.plot_results(variables=[\"LP: Position\"])"
]
},
{
"cell_type": "markdown",
"id": "aa710463",
"metadata": {},
"source": [
"### Margin\n",
"\n",
"As the network parameter `market.margin.scalingFactor` the LP should require more funds in their margin account."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ba41f9d2",
"metadata": {},
"outputs": [],
"source": [
"experiment.plot_results(variables=[\"LP: Margin Account\"], iterations=[\"avg\"])"
]
},
{
"cell_type": "markdown",
"id": "17ec88cd",
"metadata": {},
"source": [
"## Datanode Performance\n",
"\n",
"### Postgres Database Size\n",
"\n",
"As the network parameter `market.margin.scalingFactor` is increased the size of the postgres database does not change."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "73444af8-2ec9-46c8-9665-ef233bb0be99",
"metadata": {},
"outputs": [],
"source": [
"experiment.plot_results(variables=[\"postgres [GB]\"], iterations=[\"avg\"])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.10.10"
},
"vscode": {
"interpreter": {
"hash": "290045affa00dd5165d3fe24c481c5729c6dad53632503a698ecc0053ee56db0"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading