Skip to content

Commit

Permalink
Merge pull request #67 from masanorihirano/release/0.0.13
Browse files Browse the repository at this point in the history
Release/0.0.13
  • Loading branch information
masanorihirano authored Apr 16, 2023
2 parents 5a7eb3e + 726e56d commit 2bc0b20
Show file tree
Hide file tree
Showing 13 changed files with 359 additions and 24 deletions.
12 changes: 9 additions & 3 deletions docs/source/user_guide/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ Json config
"noiseScale": 0.001,
"timeWindowSize": [100, 200],
"orderMargin": [0.0, 0.1],
"marginType": "fixed" or "normal"
}
"marginType": "fixed" or "normal" (Optional)
},
"ArbitrageAgent": {
"class": "ArbitrageAgent",
"extends": "Agents",
"orderVolume": int,
"orderThresholdPrice": float,
"orderTimeLength": int (Optional, default 1),
},
}
25 changes: 22 additions & 3 deletions pams/agents/arbitrage_agent.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import random
from typing import Any
from typing import Dict
from typing import List
from typing import Optional
from typing import Union

from ..index_market import IndexMarket
from ..logs import Logger
from ..market import Market
from ..order import LIMIT_ORDER
from ..order import Cancel
Expand All @@ -21,9 +24,21 @@ class ArbitrageAgent(HighFrequencyAgent):
Currently, index markets must have the same weight for each constitutional stock.
"""

order_volume: int = 1
order_threshold_price: float = 1.0
order_time_length: int = 1
def __init__(
self,
agent_id: int,
prng: random.Random,
simulator: "Simulator", # type: ignore # NOQA
name: str,
logger: Optional[Logger] = None,
) -> None:
super().__init__(
agent_id=agent_id, prng=prng, simulator=simulator, name=name, logger=logger
)

self.order_volume: int = 1
self.order_threshold_price: float = 1.0
self.order_time_length: int = 1

def setup( # type: ignore
self,
Expand All @@ -48,11 +63,15 @@ def setup( # type: ignore
)
if "orderVolume" not in settings:
raise ValueError("orderVolume is required for ArbitrageAgent")
if not isinstance(settings["orderVolume"], int):
raise ValueError("orderVolume have to be int")
self.order_volume = settings["orderVolume"]
if "orderThresholdPrice" not in settings:
raise ValueError("orderThresholdPrice is required for ArbitrageAgent")
self.order_threshold_price = settings["orderThresholdPrice"]
if "orderTimeLength" in settings:
if not isinstance(settings["orderTimeLength"], int):
raise ValueError("orderTimeLength have to be int")
self.order_time_length = settings["orderTimeLength"]

def _submit_orders(self, market: Market) -> List[Union[Order, Cancel]]:
Expand Down
2 changes: 1 addition & 1 deletion pams/agents/fcn_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class FCNAgent(Agent):

fundamental_weight: float
chart_weight: float
is_chart_following: bool = True
margin_type: int
mean_reversion_time: int
noise_scale: float
Expand All @@ -53,6 +52,7 @@ def __init__(
logger: Optional[Logger] = None,
):
super().__init__(agent_id, prng, simulator, name, logger)
self.is_chart_following = True

def is_finite(self, x: float) -> bool:
"""determine if it is a valid value.
Expand Down
6 changes: 4 additions & 2 deletions pams/agents/high_frequency_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
class HighFrequencyAgent(Agent, ABC):
"""High-frequency trading Agent class.
High-frequency traders are treated as a special agent. Please see xxxx for more details.
#ToDo
High-frequency traders are treated as a special agent.
This class inherits from the :class:`pams.agents.Agent` class and ABC class.
.. seealso:
- :class:`pams.agents.ArbitrageAgent` for example.
"""

pass
21 changes: 19 additions & 2 deletions pams/events/fundamental_price_shock.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import random
from typing import Any
from typing import Dict
from typing import List
Expand All @@ -16,8 +17,24 @@ class FundamentalPriceShock(EventABC):
target_market: "Market" # type: ignore # NOQA
trigger_time: int
price_change_rate: float
is_enabled: bool = True
shock_time_length: int = 1

def __init__(
self,
event_id: int,
prng: random.Random,
session: "Session", # type: ignore # NOQA
simulator: "Simulator", # type: ignore # NOQA
name: str,
) -> None:
super().__init__(
event_id=event_id,
prng=prng,
session=session,
simulator=simulator,
name=name,
)
self.is_enabled: bool = True
self.shock_time_length: int = 1

def setup(self, settings: Dict[str, Any], *args, **kwargs) -> None: # type: ignore # NOQA
"""event setup. Usually be called from simulator/runner automatically.
Expand Down
19 changes: 18 additions & 1 deletion pams/index_market.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import random
import warnings
from typing import Any
from typing import Dict
from typing import List
from typing import Optional
from typing import cast

from .logs import Logger
from .market import Market


Expand All @@ -14,7 +16,22 @@ class IndexMarket(Market):
This class inherits from the :class:`pams.market.Market` class.
"""

_components: List[Market] = []
def __init__(
self,
market_id: int,
prng: random.Random,
simulator: "Simulator", # type: ignore # NOQA
name: str,
logger: Optional[Logger] = None,
):
super().__init__(
market_id=market_id,
prng=prng,
simulator=simulator,
name=name,
logger=logger,
)
self._components: List[Market] = []

def setup(self, settings: Dict[str, Any], *args, **kwargs) -> None: # type: ignore
"""setup market configuration from setting format.
Expand Down
4 changes: 3 additions & 1 deletion pams/logs/market_step_loggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def process_market_step_end_log(self, log: MarketStepEndLog) -> None:
class MarketStepSaver(Logger):
"""Saver of the market step class."""

market_step_logs: List[Dict] = []
def __init__(self) -> None:
super().__init__()
self.market_step_logs: List[Dict] = []

def process_market_step_end_log(self, log: MarketStepEndLog) -> None:
"""stack the market log.
Expand Down
7 changes: 6 additions & 1 deletion pams/market.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ class Market:
"""

def __init__(
self, market_id: int, prng: random.Random, simulator: "Simulator", name: str, logger: Optional[Logger] = None # type: ignore # NOQA
self,
market_id: int,
prng: random.Random,
simulator: "Simulator", # type: ignore # NOQA
name: str,
logger: Optional[Logger] = None,
) -> None:
"""initialization.
Expand Down
2 changes: 1 addition & 1 deletion pams/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.12"
__version__ = "0.0.13"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pams"
version = "0.0.12"
version = "0.0.13"
description = "PAMS: Platform for Artificial Market Simulations"
authors = ["Masanori HIRANO <[email protected]>"]
license = "MIT"
Expand Down
Loading

0 comments on commit 2bc0b20

Please sign in to comment.