blankly-finance / KellyBot

Simple RSI Bot that uses Kelly Criterion to optimize allocation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Kelly Criterion Trading Bot - Alpaca

A RSI-based trading bot that allocates position sizes based on the Kelly Criterion to trade stocks (SPY, CRM, AAPL).

Getting Started

Note: Python Version 3.7+ is supported

  1. First install Blankly using pip. Blankly is hosted on PyPi.
$ pip install blankly 
  1. Clone the repo --
git clone https://github.com/blankly-finance/KellyBot.git
  1. Ensure that you have your Alpaca API Keys connected and set sandbox to true. Check here for more details
  2. Run the python file
$ python kellybot.py 
  1. Voila! You have a stock trading bot that works based off the Kelly Criterion!

Backtest Output:

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%

How does this work?

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.

What is Kelly Criterion?

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.

Resources on Kelly Criterion

What is Kelly? - Investopedia The Kelly Criterion

Next Steps

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.

Join our discord and check out our platform.

About

Simple RSI Bot that uses Kelly Criterion to optimize allocation


Languages

Language:Jupyter Notebook 75.9%Language:Python 24.1%