pinkfish
pinkfish on youtubeA backtester and spreadsheet library for security analysis.
Why another python backtesting library? How is pinkfish different? Simple, I couldn't find a python backtesting library that I allowed me to backtest intraday strategies with daily data. Even simple strategies like 'buying on the close' on the SAME day a 'new 20 day high is set' were not allowed. Additionally, I was put off by the complexity of some of the libraries available, and wanted something simple, that doesn't get in the way, and just allows me to test my trading ideas. One user commented that pinkfish is "very lightweight and to the point". I didn't set out to write a new backtesting library, but I had to. Daily data is free; minute and tick data are typically not. Using minute and tick data can require hours to run vs seconds for daily data.
Some of the key features of pinkfish:
- leverages pandas for dataframe, spreadsheet like features
- comes batteries included with the most common technical indicators
- also integrates with ta-lib or pandas_ta for more advanced indicators
- leverages matplotlib for making financial graphs
- uses daily data (vs minute or tick data) for intraday trading
- uses free daily data from yahoo finance
- simple to use python API
- backtest single stock/ETF strategy or a portolio (basket of stocks/ETFs)
- backtest short selling strategies and simulate trading with margin
- write optimizers to select the best parameters
- create spreadsheets within Jupyter Notebook by utilizing pandas dataframes and itable formatting
Installation
I recommend using Pinkfish either directly with Linux or using a Linux VM. That said, you should be able to make it work under Windows or MacOS.
This is how I got pinkfish working on Xubuntu 22.04:
# Make sure your system is up to date
sudo apt update
sudo apt upgrade
# Install some preliminary requirements
sudo apt install build-essential
sudo apt install git
sudo apt install python3-pip
# Clone pinkfish repo from Github
git clone https://github.com/fja05680/pinkfish.git
cd pinkfish
# Create virtual Python environment
python -m venv venv
source venv/bin/activate
# Install pinkfish
python setup.py develop
# Install TA-LIB (Optional)
cd ~/Downloads
sudo wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
tar -xzvf ta-lib-0.4.0-src.tar.gz
cd ta-lib
./configure --prefix=/usr
make
sudo make install
pip install TA-Lib
# Create shared data cache directory (optional)
mkdir $HOME/data
echo [global] > $HOME/.pinkfish
echo base_dir = $HOME >> $HOME/.pinkfish
Examples
- Buy-And-Hold - basic buy and hold strategy
- Golden-Cross - classic long term trading algorithm
- Spreadsheet - read only spreadsheet within jupyter notebook