Skip to main content

almgren-chriss

PyPI - Python Version GitHub

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)))

Metadata

Release files for acrl 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for acrl 0.0.3
File Size Uploaded Provenance
acrl-0.0.3.tar.gz 14.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for acrl 0.0.3
File Interpreter ABI Platform
acrl-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 29.3 kB

Release files / acrl-0.0.3.tar.gz

Download URL acrl-0.0.3.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
cbf823ed9e20f9505a2385a8008da88c386e7a6a4d44beb2b28eb164722ba40a
BLAKE2b-256 checksum
How to use checksums
687fd9f0042fca51890e0fcecaef3f6126334091b640f73aca43908b6bd19c57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / acrl-0.0.3-py3-none-any.whl

Download URL acrl-0.0.3-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab0aa82f2c2b5a0dc79e545eed4a27c0c759de3d1ae81c98fc6449dd57403561
BLAKE2b-256 checksum
How to use checksums
4b74cfdef09cb2ab21baa1d008cd88787da246ad1c4f0ba3fc3ff60d81904b96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Security for acrl 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page