Python

PyFolio Performance Reporting in Python

Pyfolio is a Python library that takes a return series of an asset, hedge fund, trading strategy, anything with daily returns and automatically generates some really cool statistics and charts. There is a LOT of cool stuff to explore in the library, have fun! Performance statistics Backtest annual_return 0.98 annual_volatility 0.62 sharpe_ratio 1.41 calmar_ratio 1.71 stability_of_timeseries 0.91 max_drawdown -0.57 omega_ratio 1.27 sortino_ratio 2.01 skew -0.51 kurtosis 2.12 tail_ratio 1.00 common_sense_ratio 1.99 information_ratio 0.09 alpha 0.28…

Read More

Dashboard for Historical SPX Butterfly Prices

I built a dashboard to plot historical butterfly prices from an options database that I have locally. I’m using Python and Ipywidgets in a Jupyter Notebook to create a user interface to select the expiration and strikes of the fly and it will plot the closing fly prices versus the SPX. I’m sharing the code as it can serve as a good template for others looking to visualize data or create GUI Dashboards with Python.  The…


Automatic Support/Resistance using ML

I think an interesting application of ML could be generating the ‘features’ for inclusion in a trading algorithm, converting non-numerical data into numerical. For example, converting market sentiment or satellite imagery to count cars in a retailer’s parking lot. More examples here. I had written previously about Machine Learning for trading strategy design here. Thanks to code from @johnromero via @quantocracy I wrote a quick script to draw support and resistance lines automatically using machine learning on…


Equity Supply/Demand Indicator

I read a very interesting post from AlephBlog  which led me to another blog called Philosophical Economics. It’s a long and in depth article I had to read a few times to understand but the basic gist of it is that when investors are under allocated to equities, future returns are better than when they are over allocated. It utilizes the Fed Flow of Funds report to develop a ratio of the value of equities…


Machine Learning & SciKit Learn

I made the point to someone the other day that technology and coding is getting easier and easier to accomplish. I don’t think I would have been able to perform ‘machine learning’ five years ago but with the resources available today (Python, SciKit Learn, and pages upon pages of StackOverflow) even someone like me can fit a model and build ML algorithms. Machine Learning is also ridiculously “easy”. It’s literally 4 lines of code. It…


Random Notes on Python II

In continuation of an old post on Python, I’ve been playing around with an awesome new library built by P. Morissette simply titled BT. It includes numerous functions for back testing and displaying results & charts for daily strategies and lower frequencies. Here’s an example of a simple momentum based tactical asset rotation strategy: It has a function to weight stocks based on mean-variance optimization: Spits out results for multiple strategies at once: Even has…


Fun with Leverage

An old post regarding a simple asset allocation model that beat the average performance of the top ten hedge funds of the past 15 years got me thinking. As an aside, the average performance will be highly biased upwards as we only know in hindsight what the top 10 hedge funds were. Thinking can be dangerous. So can leverage. In the previous Python post, I tested a simple RV timing tool in VXX and combined…


No Picture

Random Notes with Python

I admit I had a lot of trouble just getting up and running in Python. It probably should have been easier but programming languages seem to have gotten a bit more complex since Fortran and C++ where all you need was an editor and a compiler. So I’m sharing these notes to hopefully help anyone else out there who has an interest in using Python specifically for back testing trading strategies. Python can be used…