Skip to main content

Create a custom GYM environment to simulate trading strategy.

Project description

betting_env

from IPython.display import HTML
import pandas as pd

from betting_env.config.localconfig import CONFIG,DB_HOSTS
from betting_env.utils.data_extractor import data_aggregator
from betting_env.betting_env import BettingEnv

Install

pip install betting_env

Config

In order to connect to the mongo database we require some connection parameters defined in toml format and should be read when the library is loaded. The package will look first under /secrets/config.toml or in the environment variable BETTING_ENV_CONFIG. An example of config file is provided with the package and will be used by default. It is the user’s responsibility to make sure this file is saved at the right location if you want to use your own.

Simplified betting environment

The punter starts with $N (N>0) in his Bank account and can use them to place bets on several football games.

He is offered the option to bet on the 2 main markets: 1X2 (home/draw/away) and Asian handicap (we focus on the even line) and is only allowed to place a small, medium, or big stake on one and only one of the 5 possible selections home team win, away team win, or draw (1X2 case) or home or away (Asian handicap) or skip the betting opportunity. At each step, the punter is presented with some information about a game and the associated betting opportunities. If he decides to bet, he receives a reward that could be positive (profit) or negative (loss of his stake). His balance is then updated accordingly and he moves to the next step i.e next game. An episode ends when the punter goes bankrupt (Balance <= 0) or if no more betting opportunities are available.

Load games

fixtures = data_aggregator(
    db_hosts=DB_HOSTS, config=CONFIG, db_host="public_atlas", limit=None
)

Init environment

env = BettingEnv(fixtures)
max_steps_limit = fixtures.shape[0]

Playing random choices

# Init RL env.
env.reset()

# Init done Flag to False.
done = False
# Init loop counter.
i = 0
# Stops when it is done or when we have bet on all provided games.
while not done and i < max_steps_limit:
    # Make a step.
    obs, reward, done, info = env.step(env.action_space.sample())
    # Increment counter.
    i = i + 1

HTML('<img src="./images/img_1.gif">')

Playing Medium Stake on Home Team Win (1X2)

# Init RL env.
env.reset()
# Init done Flag to False.
done = False
# Init loop counter.
i = 0
# Stops when it is done or when we have bet on all provided games.
while not done and i < max_steps_limit:
    # Make a step.
    obs, reward, done, info = env.step(2)
    # Increment counter.
    i = i + 1

HTML('<img src="./images/img_2.gif">')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

betting_env-0.1.0.tar.gz (22.5 kB view details)

Uploaded Source

Built Distribution

betting_env-0.1.0-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file betting_env-0.1.0.tar.gz.

File metadata

  • Download URL: betting_env-0.1.0.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for betting_env-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f64da7f91a579fece1a17130cdb5c3eedb367c2851716e61531383bfcecda8fa
MD5 f3d02133f8b2f8de48e5faaa31a2eec6
BLAKE2b-256 773b8ca43248db7f477578d245ff76556746f3ee48ac86925db3af4c7f6b8a3b

See more details on using hashes here.

File details

Details for the file betting_env-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: betting_env-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for betting_env-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 55341020a602865ad8a0898c0e97ca6e4d04366a697da44e8abda14d305e5d92
MD5 6cecae79d657832fcc005c9042881d8b
BLAKE2b-256 7842cc7fc6a6bd30c5720f86a8603093e8efe00352cfa13f5f54e2343d9829f3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page