-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from masanorihirano/takata/examples_price_limi…
…t_rule [examples] PriceLimit
- Loading branch information
Showing
1 changed file
with
183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
{ | ||
"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/price_limit.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\": [\"PriceLimitRule\"]\n", | ||
"\t\t\t}\n", | ||
"\t\t]\n", | ||
"\t},\n", | ||
"\n", | ||
"\t\"PriceLimitRule\": {\n", | ||
"\t\t\"class\": \"PriceLimitRule\",\n", | ||
"\t\t\"targetMarkets\": [\"Market\"],\n", | ||
"\t\t\"triggerChangeRate\": 0.05,\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\"markets\": [\"Market\"],\n", | ||
"\t\t\"assetVolume\": 50,\n", | ||
"\t\t\"cashAmount\": 10000,\n", | ||
"\n", | ||
"\t\t\"fundamentalWeight\": {\"expon\": [0.2]},\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" | ||
}, | ||
"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.8.13" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 1 | ||
} |