A RSI-based trading bot that allocates position sizes based on the Kelly Criterion to trade stocks (SPY, CRM, AAPL).
Note: Python Version 3.7+ is supported
- First install Blankly using
pip
. Blankly is hosted on PyPi.
$ pip install blankly
- Clone the repo --
git clone https://github.com/blankly-finance/KellyBot.git
- Ensure that you have your Alpaca API Keys connected and set sandbox to true. Check here for more details
- Run the python file
$ python kellybot.py
- Voila! You have a stock trading bot that works based off the Kelly Criterion!
Blankly Metrics:
Calmar Ratio: 3.42
Compound Annual Growth Rate (%): 22.0%
Conditional Value-at-Risk: 1.02
Cumulative Returns (%): 22.0%
Max Drawdown (%): 4.0%
Resampled Time: 86400.0
Risk-Free Return Rate: 0.0
Sharpe Ratio: 1.95
Sortino Ratio: 3.58
Volatility: 0.07
Value-at-Risk: 58.84
Variance (%): 0.52%
This uses the blankly package to build a trading strategy
We are able to utilize the Blankly.Strategy
object to easily add our Kelly initialization function that determines our RSI histogram logic and calculations and then easily create a price event that trades off of the calculated Kelly Criterion sizes.
The Kelly Criterion gives the optimal bet value, given the probabilities of wins and losses as well as the payoffs for each outcome. It works by optimizing the logarithmic growth rate, which leads to the greatest returns in the long term. In portfolio management scenarios, where it's important to both discover opportunities and allocate capital efficiently, the Kelly Criterion is an extremely useful tool.
What is Kelly? - Investopedia The Kelly Criterion
Fork this repository, and start adding in some more indicators to test different ways to build the base model. Alternatively, build the Kelly Criterion section onto one of your existing models.
Take this strategy live by changing it to strategy.start()
or use strategy.backtest()
to backtest.