Create a custom gym environment to simulate simple betting strategy.
Project description
fastbet
from IPython.display import HTML
import pandas as pd
from fastbet.config.mongo import mongo_init
from fastbet.datastructure.data_extractor import data_aggregator
from fastbet.environment import BettingEnv
Install
pip install fastbet
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.
Let’s start by registering the connection to the mongo database:
mongo_init(db_host="public_atlas")
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 3 main markets: 1X2
(home/draw/away), Asian handicap
and Total(Over/Under)
(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 7 possible selections
home team win
, away team win
, or draw
(1X2
case) or home
or
away
(Asian handicap
and Total
) 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(limit=10)
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
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
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
Built Distribution
File details
Details for the file fastbet-0.2.3.tar.gz
.
File metadata
- Download URL: fastbet-0.2.3.tar.gz
- Upload date:
- Size: 23.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3652cc7e24e106aaee8a0374ebe571daf44641c3cc2ac504935ed1cdd0bf9626 |
|
MD5 | e3f04523396439ec2b3c0d820430d244 |
|
BLAKE2b-256 | 9dfdedc1e31a51e123e1c4338fce258c53e230f20c010800b49a3008958ef3a3 |
File details
Details for the file fastbet-0.2.3-py3-none-any.whl
.
File metadata
- Download URL: fastbet-0.2.3-py3-none-any.whl
- Upload date:
- Size: 24.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a714b8130cfb1fa52380e0250927404131a08030e8e2704812dca0fe4fac9a50 |
|
MD5 | 4a47e759fb46b73f52cd048e0a0db670 |
|
BLAKE2b-256 | 9f52067539f2a9685414b79bd4675ef895f19de58016f21397f0bc64498830a4 |