Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
custom money flow index (MFI) w/ history API

Perhaps of interest. Comments and questions welcome. --Grant

8 responses

Thanks Anony,

One thing I've noticed is that it is relatively easy to cook up an algorithm like this one that generate good returns relative to the market over the 2008-2009 period, but then it loses steam. One thought I've had is that perhaps on shorter time scales and/or market niches, the same thing that happened in 2008-2009 is going on now. Or perhaps it was a kinda of black swan event that has no current precedent?

Grant

Point regarding investing versus trading is understood. As I've commented elsewhere, Quantopian has started to use the term "systematic investing" but I don't think that's really their primary market. --Grant

Here's a minute-level version w/ more optimal return. Could probably be tweaked a bit more, at the risk of over-fitting bias (probably already has some). In any case, there seems to be some useful information in the MFI difference between SPY & BND, although as Anony points out, it may only be useful for long-term investing/asset allocation not trading. --Grant

Same as above, except:

-- GDX instead of BND
-- Started backtest 1 year earlier

Grant

Here's another variant, w/ QQQ & GLD. I use the error function to compute the allocation ratio. --Grant

Hello Grant

I just joined Quantopian and also new to Python programming. I am trying to learn and build my 1st algorithm using the MFI signals. I saw this post and was trying to study and learn from your codes. While I understand the MFI calculation mathematically, I am struggling to follow the code. Appreciate if you can help me on the part of MFI and get_MFI(context) function. Thanks very much!

Hi Seb,

It's been awhile since I wrote that code. As I recall, I followed https://en.wikipedia.org/wiki/Money_flow_index.

Rather than using the custom MFI computation I wrote, you could consider using the built-in one using TA-LIB. There are some examples on https://www.quantopian.com/posts/mfi-with-apply. With a little googling, you might be able to find more. This is probably a shorter path for you, than trying to unravel my code (which would benefit from some re-factoring). And as a general rule, all things being equal, it is usually better to use built-in functions.

Grant

Hi Grant

Thanks for the quick response and good pointers.

I have also just learned about the Quantopian debugger feature which allow me to step through the codes and explore how each steps affect the variables.

Thanks again!
Seb