Skip to content

Commit

Permalink
Merge pull request #76 from masanorihirano/dev
Browse files Browse the repository at this point in the history
CI test
  • Loading branch information
masanorihirano authored Apr 26, 2023
2 parents 6095b44 + 7d5d5a0 commit 5c98d5c
Show file tree
Hide file tree
Showing 3 changed files with 237 additions and 4 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ jobs:
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.8, 3.9, "3.10", "3.11"]
exclude:
- platform: windows-latest
python-version: "3.11"

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand Down
236 changes: 236 additions & 0 deletions examples/shock_transfer.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "KCI4qIU_pa-1"
},
"source": []
},
{
"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/shock_transfer.ipynb)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "OwaI8_xbpa-5",
"colab": {
"base_uri": "https://localhost:8080/"
},
"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\": [\"SpotMarket-1\", \"SpotMarket-2\", \"IndexMarket-I\"],\n",
"\t\t\"agents\": [\"FCNAgents-1\", \"FCNAgents-2\", \"FCNAgents-I\", \"ArbitrageAgents\"],\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\t\"maxNormalOrders\": 3, \"MEMO\": \"The same number as #markets\",\n",
"\t\t\t\t\"maxHighFrequencyOrders\": 0\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\"maxNormalOrders\": 3, \"MEMO\": \"The same number as #markets\",\n",
"\t\t\t\t\"maxHighFrequencyOrders\": 5,\n",
"\t\t\t\t\"events\": [\"FundamentalPriceShock\"]\n",
"\t\t\t}\n",
"\t\t]\n",
"\t},\n",
"\n",
"\t\"FundamentalPriceShock\": {\n",
"\t\t\"class\": \"FundamentalPriceShock\",\n",
"\t\t\"target\": \"SpotMarket-1\",\n",
"\t\t\"triggerTime\": 0,\n",
"\t\t\"priceChangeRate\": -0.1\n",
"\t},\n",
"\t\"SpotMarket\": {\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",
"\t\"SpotMarket-1\": {\n",
"\t\t\"extends\": \"SpotMarket\"\n",
"\t},\n",
"\t\"SpotMarket-2\": {\n",
"\t\t\"extends\": \"SpotMarket\"\n",
"\t},\n",
"\t\"IndexMarket-I\": {\n",
"\t\t\"class\": \"IndexMarket\",\n",
"\t\t\"tickSize\": 0.00001,\n",
"\t\t\"marketPrice\": 300.0,\n",
"\t\t\"outstandingShares\": 25000,\n",
"\t\t\"markets\": [\"SpotMarket-1\", \"SpotMarket-2\"]\n",
"\t},\n",
"\t\"FCNAgent\": {\n",
"\t\t\"class\": \"FCNAgent\",\n",
"\t\t\"numAgents\": 100,\n",
"\t\t\"markets\": [\"Market\"],\n",
"\t\t\"assetVolume\": 50,\n",
"\t\t\"cashAmount\": 10000,\n",
"\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",
"\n",
"\t\"FCNAgents-1\": {\n",
"\t\t\"extends\": \"FCNAgent\",\n",
"\t\t\"markets\": [\"SpotMarket-1\"]\n",
"\t},\n",
"\t\"FCNAgents-2\": {\n",
"\t\t\"extends\": \"FCNAgent\",\n",
"\t\t\"markets\": [\"SpotMarket-2\"]\n",
"\t},\n",
"\t\"FCNAgents-I\": {\n",
"\t\t\"extends\": \"FCNAgent\",\n",
"\t\t\"markets\": [\"IndexMarket-I\"]\n",
"\t},\n",
"\t\"ArbitrageAgents\": {\n",
"\t\t\"class\": \"ArbitrageAgent\",\n",
"\t\t\"numAgents\": 100,\n",
"\t\t\"markets\": [\"IndexMarket-I\", \"SpotMarket-1\", \"SpotMarket-2\"],\n",
"\t\t\"assetVolume\": 50,\n",
"\t\t\"cashAmount\": 150000,\n",
"\t\t\"orderVolume\": 1,\n",
"\t\t\"orderThresholdPrice\": 1.0\n",
"\t}\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "xUUUfulSpa-6"
},
"outputs": [],
"source": [
"import random\n",
"import numpy as np\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_indexmarket_i = dict(sorted(map(lambda x: (x[\"market_time\"], x[\"market_price\"]), filter(lambda x: x[\"market_name\"] == \"IndexMarket-I\", saver.market_step_logs))))\n",
"market_prices_spotmarket_1 = dict(sorted(map(lambda x: (x[\"market_time\"], x[\"market_price\"]), filter(lambda x: x[\"market_name\"] == \"SpotMarket-1\", saver.market_step_logs))))\n",
"market_prices_spotmarket_2 = dict(sorted(map(lambda x: (x[\"market_time\"], x[\"market_price\"]), filter(lambda x: x[\"market_name\"] == \"SpotMarket-2\", saver.market_step_logs))))\n",
"\n",
"fundamental_prices_indexmarket_i = dict(sorted(map(lambda x: (x[\"market_time\"], x[\"fundamental_price\"]), filter(lambda x: x[\"market_name\"] == \"IndexMarket-I\", saver.market_step_logs))))\n",
"fundamental_prices_spotmarket_1 = dict(sorted(map(lambda x: (x[\"market_time\"], x[\"fundamental_price\"]), filter(lambda x: x[\"market_name\"] == \"SpotMarket-1\", saver.market_step_logs))))\n",
"fundamental_prices_spotmarket_2 = dict(sorted(map(lambda x: (x[\"market_time\"], x[\"fundamental_price\"]), filter(lambda x: x[\"market_name\"] == \"SpotMarket-2\", 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_indexmarket_i.keys()), list(market_prices_indexmarket_i.values()), label=\"IndexMarket-I\")\n",
"plt.plot(list(market_prices_spotmarket_1.keys()), list(market_prices_spotmarket_1.values()), label=\"SpotMarket-1\")\n",
"plt.plot(list(market_prices_spotmarket_2.keys()), list(market_prices_spotmarket_2.values()), label=\"SpotMarket-2\")\n",
"plt.plot(list(fundamental_prices_indexmarket_i.keys()), list(fundamental_prices_indexmarket_i.values()), color='black')\n",
"plt.plot(list(fundamental_prices_spotmarket_1.keys()), list(fundamental_prices_spotmarket_1.values()), color='black')\n",
"plt.plot(list(fundamental_prices_spotmarket_2.keys()), list(fundamental_prices_spotmarket_2.values()), color='black')\n",
"plt.xlabel(\"ticks\")\n",
"plt.ylabel(\"market price\")\n",
"plt.legend()\n",
"plt.show()"
]
}
],
"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.9.12"
},
"colab": {
"provenance": []
}
},
"nbformat": 4,
"nbformat_minor": 0
}
2 changes: 1 addition & 1 deletion samples/shock_transfer/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"class": "FundamentalPriceShock",
"target": "SpotMarket-1",
"triggerTime": 0,
"priceChangeRate": -0.3,
"priceChangeRate": -0.1,
"enabled": true
},
"SpotMarket": {
Expand Down

0 comments on commit 5c98d5c

Please sign in to comment.