Today I released Prophet, a microframework for analyzing financial markets. Prophet strives to let the programmer focus on modeling financial strategies, portfolio management, and analyzing backtests. It achieves this by having few functions to learn to hit the ground running, yet being flexible enough to accomodate sophistication.
Currently it provides a backtester and a method for generating trade orders. I am more than happy to take feature requests or feedback! Please open an issue here. I hope it helps you prophet from the stock market (hehe).
I wanted something that is lightweight and easy to pickup. Ideally a library that focuses on just support infrastructure and being performant and places as few restrictions on me as possible. Think Flask vs Django. When using Prophet, you really should primarily just be working with with pandas library.
In comparison to Zipline
Prophet provides a slightly smaller API surface so there aren't as many functions you need to know about before you can get up and running. However it is flexible in that you can use the lower-level API to create functions that fit your use case. Also, the backtesting model doesn't have a bias as to the type of data you use to trade. It does provide price data out of the box for convenience but treats all data sources equally. Zipline is more full featured and mature than Prophet and would be a great choice for price-based algorithms. It's API is still very simple but I felt it was biased toward algorithms driven by price.
In comparison to QSTK
QSTK is a huge library with many useful functions. However, lot of them are not well documented and you have to hunt in the source code to find some of the gems. Many functions also tend to be slightly stringy and inflexible. I think Prophet will work well alongside QSTK as QSTK's scope is broader than Prophet. The functions that Prophet provides are for the most part implemented or possible to implement with QSTK. Prophet should be more composable and flexible though, allowing you to play with the data in each step of the process and analyze the performance with a custom set of metrics that you care about. The source code should also be easier to read because it follows more closely to standard Python conventions. Also, Prophet does not to generate artifacts in the form of csv, html, and image files as a byproduct of executing code.
Prophet requires Python. Install prophet with the following command:
pip install prophet
If you want to dive straight into Prophet, here's the "Hello World":
import datetime as dt from prophet import Prophet from prophet.data import YahooCloseData from prophet.analyze import default_analyzers from prophet.orders import Orders class OrderGenerator(object): def run(self, prices, timestamp, cash, **kwargs): # Lets buy lots of Apple! symbol = "AAPL" orders = Orders() if (prices.loc[timestamp, symbol] * 100) < cash: orders.add_order(symbol, 100) return orders prophet = Prophet() prophet.set_universe(["AAPL", "XOM"]) prophet.register_data_generators(YahooCloseData()) prophet.set_order_generator(OrderGenerator()) backtest = prophet.run_backtest(start=dt.datetime(2010, 1, 1)) prophet.register_portfolio_analyzers(default_analyzers) analysis = prophet.analyze_backtest(backtest) print analysis # +--------------------------------------+ # | sharpe | 1.09754359611 | # | average_return | 0.00105478425027 | # | cumulative_return | 2.168833 | # | volatility | 0.0152560508189 | # +--------------------------------------+ # Generate orders for your to execute today # Using Nov, 10 2014 as the date because there might be no data for today's # date (Market might not be open) and we don't want examples to fail. today = dt.datetime(2014, 11, 10) print prophet.generate_orders(today) # Orders[Order(symbol='AAPL', shares=100)]
For a more thorough tutorial, please see the documentation.
On Quant Investing
Quant investing isn't a silver bullet. My personal take on quant investing is that it is really just a magnified reflection of your own investment skill.
What formula do you program the computer with? The formula is subject to human tinkering, and at some point enough tinkering creates a human driven computer executed fund.
- Nate Tobik, Oddball Stocks
You could use financial signal processing and catch large market moves. You could implement a quantitative value strategy. Whatever your strategy does is something that - by the fact you wrote the code - you could do by hand, but slower.
Strategies to Explore
So what do I think people using Prophet should focus on? Some strategies need extreme speed (We could all manually implement an arbitrage strategy but the hardware investment some firms have made to be faster than us is significant). Some strategies require you to travel around the world to survey people and places to generate realtime economic statistics. Many strategies are not suitable for the individual investor.
Instead, make Prophet a testbed for you to leverage your own expertise, form hypotheses and test them. Remember to learn from mistakes and tests as if it was a scientific experiment. Always be learning.
Focus on small-caps that have few to no large institutions covering them. Your code can probably analyze them faster than Joe at the office, who moonlights as a chart trader. Use NLP to find SEC filings that could potentially be the catalyst for interesting event driven trades. If you don't have a finance background, maybe that chaos theory or signal processing expertise can gain you an edge in the market. Work with what you are good at (and learn what will make you better). If you're using Prophet, you already have one advantage over most retail investors (programming knowledge, not Prophet ☺).
I am hoping people find this project interesting and that it provides a simple framework for programmers to explore and try trading strategies. I will personally be implementing a few strategies that have been on my mind for the last couple years.
Even if Prophet doesn't meet your needs now, please open an issue here. I want to build Prophet as flexible as possible but your use case might just be different than mine.
Until next time!