No project description provided
Project description
almgren-chriss
Deep reinforcement learning for optimal execution of portfolio transactions.
Installation
pip install acrl
Usage
from collections import deque
import numpy as np
import acrl as sca
from acrl.agent import Agent
env = sca.MarketEnvironment()
agent = Agent(
state_size=env.observation_space_dimension(),
action_size=env.action_space_dimension(),
random_seed=0,
)
liquidation_time = 60
n_trades = 60
risk_aversion = 1e-6
episodes = 10000
shortfall_hist = np.array([])
shortfall_deque = deque(maxlen=100)
for episode in range(episodes):
current_state = env.reset(
seed=episode,
liquid_time=liquidation_time,
num_trades=n_trades,
lamb=risk_aversion,
)
env.start_transactions()
for i in range(n_trades + 1):
action = agent.act(current_state, add_noise=True)
new_state, reward, done, info = env.step(action)
agent.step(current_state, action, reward, new_state, done)
current_state = new_state
if info.done:
shortfall_hist = np.append(shortfall_hist, info.implementation_shortfall)
shortfall_deque.append(info.implementation_shortfall)
break
if (episode + 1) % 100 == 0:
print(
"\rEpisode [{}/{}]\tAverage Shortfall: ${:,.2f}".format(
episode + 1, episodes, np.mean(shortfall_deque)
)
)
print("\nAverage Implementation Shortfall: ${:,.2f} \n".format(np.mean(shortfall_hist)))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
acrl-0.0.3.tar.gz
(14.3 kB
view details)
Built Distribution
acrl-0.0.3-py3-none-any.whl
(15.0 kB
view details)
File details
Details for the file acrl-0.0.3.tar.gz
.
File metadata
- Download URL: acrl-0.0.3.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbf823ed9e20f9505a2385a8008da88c386e7a6a4d44beb2b28eb164722ba40a |
|
MD5 | 5dbe68a82f36d61da8a0abd569617215 |
|
BLAKE2b-256 | 687fd9f0042fca51890e0fcecaef3f6126334091b640f73aca43908b6bd19c57 |
File details
Details for the file acrl-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: acrl-0.0.3-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab0aa82f2c2b5a0dc79e545eed4a27c0c759de3d1ae81c98fc6449dd57403561 |
|
MD5 | f7ac0f9ebf922f1b42d7990f2801cd9d |
|
BLAKE2b-256 | 4b74cfdef09cb2ab21baa1d008cd88787da246ad1c4f0ba3fc3ff60d81904b96 |