BullETS is a Python library designed to help with the development of algorithmic trading strategies.
- Retrieve stock data
- Trading portfolio management
- Backtesting framework
This section will assume you have Python installed, if not, you can download & install it from here.
We strongly recommend using a virtual environment to keep BullETS and its dependencies from interfering with your system installs.
Windows:
# Initializing a virtual environment in the ./venv directory
py -3 -m venv venv
# Activating the virtual environment
venv\Scripts\activate.bat
Mac OS & Linux:
# Initializing a virtual environment in the ./venv directory
python3 -m venv bot-env
# Activating the virtual environment (Mac OS & Linux)
source bot-env/bin/activate
-
Register an account on the FinancialModelingPrep website and retrieve your API key
-
Create a new folder, initialize and activate a virtual environment inside (see above)
-
Install BullETS from PyPI
pip install BullETS
- Code your own strategy
from bullets.strategy import Strategy, Resolution
from bullets.runner import Runner
from bullets.data_source.data_source_fmp import FmpDataSource
from datetime import datetime
# Extend the default strategy from BullETS
class MyStrategy(Strategy):
# You can access the `portfolio` and the `data_source` variables to retrieve information for your strategy
# You are also free to add your own data sources here and use them
# Redefine this function to perform a task when the strategy starts
def on_start(self):
pass
# Redefine this function to perform a task on each resolution
def on_resolution(self):
self.portfolio.market_order("AAPL", 5)
# Redefine this function to perform a task at the end of the strategy
def on_finish(self):
pass
# Initialize your new strategy
if __name__ == '__main__':
resolution = Resolution.DAILY # Define your resolution (DAILY, HOURLY or MINUTE)
start_time = datetime(2019, 3, 5) # Define your strategy start time
end_time = datetime(2019, 4, 22) # Define your strategy end time
data_source = FmpDataSource("Insert your key here", resolution) # Initialize the FMP data source with your API key and resolution
strategy = MyStrategy(resolution=resolution,
start_time=start_time,
end_time=end_time,
starting_balance=5000,
data_source=data_source)
runner = Runner(strategy) # Initialize the runner, which handles the execution of your strategy
runner.start() # Start the runner and your strategy
This section only covers the basic features to develop a strategy. BullETS has other features, such as slippage, transaction fees, and many others. Stay updated for our upcoming detailed documentation that demonstrates how to use these features.
This section covers the installation process if you wish to contribute to the library.
- Clone the repo and go to the library's root directory
# Clone this repository
git clone https://github.com/AlgoETS/BullETS
# Move to the BullETS directory
cd BullETS
-
Initialize and run a virtual environment (see above)
-
Install BullETS in editable mode (while the virtual environment is activated)
pip install -e .
- Setup environment variables
- Make a copy of the
.env.sample
file and name it.env
- Replace the required values inside the
.env
file
- Make a copy of the