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

[examples] MarketShare #87

Merged
merged 48 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
f5d24d7
add main and config
bonochof Jun 23, 2023
20015ab
add base functions
bonochof Jun 23, 2023
2219228
fix docstring
bonochof Jun 23, 2023
b1e2099
format
bonochof Jun 23, 2023
e4f3185
for test
bonochof Jun 23, 2023
3b9c174
fix to solve error
bonochof Jun 23, 2023
399cf03
add market_maker_agent
bonochof Jun 23, 2023
d4e251f
add MMAgent dynamics
bonochof Jun 23, 2023
cca9808
format
bonochof Jun 23, 2023
08df84e
fix warning
bonochof Jun 23, 2023
06b1ef5
fix error
bonochof Jun 23, 2023
bf86f91
fix docstring
bonochof Jun 23, 2023
56c89f9
add MarketShare and MarketMaker agents to test
bonochof Jun 23, 2023
c000ea0
add roulette
bonochof Jun 24, 2023
2f89a18
add docs
bonochof Jun 24, 2023
24c62b0
add fat_finger example
bonochof Jun 27, 2023
8565ddf
add setting tradeVolume parameter
bonochof Jun 30, 2023
fe7cf45
fix to use random.choices
bonochof Jun 30, 2023
3df4156
fix cond for None
bonochof Jun 30, 2023
0b22c8a
fix error
bonochof Jun 30, 2023
3899155
add examples market_share
bonochof Jun 30, 2023
5aee3ae
add documentation
bonochof Jun 30, 2023
e18b63e
Merge branch 'takata/samples_fat_finger' into takata/examples_fat_finger
bonochof Jun 30, 2023
755a87c
Merge branch 'takata/samples_fat_finger' into takata/examples_fat_finger
bonochof Jul 1, 2023
f12f56b
Merge branch 'takata/samples_fat_finger' into takata/examples_fat_finger
masanorihirano Aug 10, 2023
4025bb1
Merge branch 'takata/samples_fat_finger' into takata/examples_fat_finger
masanorihirano Aug 10, 2023
d61185d
update notebook
masanorihirano Aug 10, 2023
e5a6b8e
Merge commit '01fa1cba1db759b0b8f1ad7b79cba93e2c2f607c' into takata/e…
masanorihirano Aug 14, 2023
04c1086
Merge branch 'takata/examples_fat_finger' into takata/samples_market_…
masanorihirano Aug 17, 2023
ef32760
Merge branch 'takata/samples_market_share' into takata/examples_marke…
masanorihirano Aug 17, 2023
7aa2fae
refactor market share FCN
masanorihirano Aug 17, 2023
cd0b181
added test
masanorihirano Aug 17, 2023
caa478e
tradeVolume was moved
masanorihirano Aug 17, 2023
12f6c1d
fix docment
masanorihirano Aug 17, 2023
8900a94
refactoring
masanorihirano Aug 17, 2023
259c168
added input check
masanorihirano Aug 17, 2023
9c01b39
WIP
masanorihirano Aug 17, 2023
1ea08b1
update type
masanorihirano Aug 17, 2023
414f7ce
added docs
masanorihirano Aug 17, 2023
df6ba52
added test adn doc
masanorihirano Aug 17, 2023
99f9376
Merge branch 'takata/samples_market_share' into takata/examples_marke…
masanorihirano Aug 17, 2023
68a40c6
WIP checking
masanorihirano Aug 17, 2023
06d4834
added test
masanorihirano Aug 17, 2023
57ccdb7
added share plot
masanorihirano Aug 29, 2023
3e47f30
bug fix in calc sum executed volumes
masanorihirano Aug 29, 2023
998fd14
Merge branch 'takata/samples_market_share' into takata/examples_marke…
masanorihirano Aug 29, 2023
15f7be8
WIP
masanorihirano Aug 30, 2023
758abb3
working barely
masanorihirano Aug 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/source/reference/agents.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ Agents
agents.Agent
agents.HighFrequencyAgent
agents.FCNAgent
agents.ArbitrageAgent
agents.ArbitrageAgent
agents.MarketShareFCNAgent
11 changes: 11 additions & 0 deletions docs/source/user_guide/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ Json config
"timeWindowSize": JsonRandomFormat,
"orderMargin": JsonRandomFormat,
"marginType": "fixed" or "normal" (Optional; default fixed)
},
"MarketShareFCNAgents": {
"class": "MarketShareFCNAgent",
"extends": "FCNAgent"
},
"ArbitrageAgent": {
"class": "ArbitrageAgent",
Expand All @@ -102,4 +106,11 @@ Json config
"orderThresholdPrice": float,
"orderTimeLength": int (Optional, default 1),
},
"MarketMakerAgent": {
"class": "MarketMakerAgent",
"extends": "Agents",
"targetMarket": string required,
"netInterestSpread": float required,
"orderTimeLength": int optional; default 2,
}
}
191 changes: 191 additions & 0 deletions examples/fat_finger.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "58xSRq9jpa-2"
},
"source": [
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](http://colab.research.google.com/github/masanorihirano/pams/blob/main/examples/fat_finger.ipynb)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "OwaI8_xbpa-5",
"outputId": "1df64bd6-6e6b-4365-8f03-c6f3fc583f5e"
},
"outputs": [],
"source": [
"# Please remove comment-out if necessary\n",
"#! pip install pams matplotlib"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ixLeaU7Epa-5"
},
"outputs": [],
"source": [
"config = {\n",
"\t\"simulation\": {\n",
"\t\t\"markets\": [\"Market\"],\n",
"\t\t\"agents\": [\"FCNAgents\"],\n",
"\t\t\"sessions\": [\n",
"\t\t\t{\t\"sessionName\": 0,\n",
"\t\t\t\t\"iterationSteps\": 100,\n",
"\t\t\t\t\"withOrderPlacement\": True,\n",
"\t\t\t\t\"withOrderExecution\": False,\n",
"\t\t\t\t\"withPrint\": True\n",
"\t\t\t},\n",
"\t\t\t{\t\"sessionName\": 1,\n",
"\t\t\t\t\"iterationSteps\": 500,\n",
"\t\t\t\t\"withOrderPlacement\": True,\n",
"\t\t\t\t\"withOrderExecution\": True,\n",
"\t\t\t\t\"withPrint\": True,\n",
"\t\t\t\t\"events\": [\"OrderMistakeShock\"]\n",
"\t\t\t}\n",
"\t\t]\n",
"\t},\n",
"\n",
"\t\"OrderMistakeShock\": {\n",
"\t\t\"class\": \"OrderMistakeShock\",\n",
"\t\t\"target\": \"Market\",\n",
"\t\t\"triggerTime\": 100, \"MEMO\": \"At the 100th step of the session 2\",\n",
"\t\t\"priceChangeRate\": -0.05, \"MEMO\": \"Sign: negative for down; positive for up; zero for no change\",\n",
"\t\t\"orderVolume\": 10000, \"MEMO\": \"Very much\",\n",
"\t\t\"orderTimeLength\": 10000, \"MEMO\": \"Very long\",\n",
"\t\t\"enabled\": True\n",
"\t},\n",
"\n",
"\t\"Market\": {\n",
"\t\t\"class\": \"Market\",\n",
"\t\t\"tickSize\": 0.00001,\n",
"\t\t\"marketPrice\": 300.0,\n",
"\t\t\"outstandingShares\": 25000\n",
"\t},\n",
"\n",
"\t\"FCNAgents\": {\n",
"\t\t\"class\": \"FCNAgent\",\n",
"\t\t\"numAgents\": 100,\n",
"\n",
"\t\t\"MEMO\": \"Agent class\",\n",
"\t\t\"markets\": [\"Market\"],\n",
"\t\t\"assetVolume\": 50,\n",
"\t\t\"cashAmount\": 10000,\n",
"\n",
"\t\t\"MEMO\": \"FCNAgent class\",\n",
"\t\t\"fundamentalWeight\": {\"expon\": [1.0]},\n",
"\t\t\"chartWeight\": {\"expon\": [0.0]},\n",
"\t\t\"noiseWeight\": {\"expon\": [1.0]},\n",
"\t\t\"noiseScale\": 0.001,\n",
"\t\t\"timeWindowSize\": [100, 200],\n",
"\t\t\"orderMargin\": [0.0, 0.1]\n",
"\t}\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "xUUUfulSpa-6"
},
"outputs": [],
"source": [
"import random\n",
"import matplotlib.pyplot as plt\n",
"from pams.runners import SequentialRunner\n",
"from pams.logs.market_step_loggers import MarketStepSaver"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "3QXSkEw2pa-6",
"outputId": "fb454d0c-57b3-4cb6-d6ad-4512dbe429c1"
},
"outputs": [],
"source": [
"saver = MarketStepSaver()\n",
"\n",
"runner = SequentialRunner(\n",
" settings=config,\n",
" prng=random.Random(42),\n",
" logger=saver,\n",
")\n",
"runner.main()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "P5_pyTa9pa-6"
},
"outputs": [],
"source": [
"market_prices = dict(sorted(map(lambda x: (x[\"market_time\"], x[\"market_price\"]), saver.market_step_logs)))\n",
"fundamental_prices = dict(sorted(map(lambda x: (x[\"market_time\"], x[\"fundamental_price\"]), saver.market_step_logs)))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 449
},
"id": "c__AgWzapa-7",
"outputId": "456ed7cb-0b14-4774-845c-da50b68a7031",
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"plt.plot(list(market_prices.keys()), list(market_prices.values()))\n",
"plt.plot(list(fundamental_prices.keys()), list(fundamental_prices.values()), color='black')\n",
"plt.xlabel(\"ticks\")\n",
"plt.ylabel(\"market price\")\n",
"plt.ylim([270, 330])\n",
"plt.show()"
]
}
],
"metadata": {
"colab": {
"provenance": []
},
"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.11"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Loading