Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Stock Periodicity: Best Fit Sine Wave

This was research I did to create an algorithm, based on the machine learning approach to regression, to find the best fit sine wave for any given span of data. This can work on any time frame. The cost function may not always converge to the global minimum using my approach. There are more advanced ways to accomplish that, but I am choosing a simple iterative approach.

I attempted to code an algorithm which would take the hypothesis over a given day and project it to the next day, and buy on the f(x) = 1 or -1, depending on how price was tracking the sine wave. I failed to get it to work well, but I also didn't test out more forms that would find the best "generalized" fit.

I know of the Hilbert sine wave, which is adaptive and probably more useful than this. However, I had a hypothesis and ran with it. It is possible that this approach can be useful for detecting the natural rhythm of an instrument, but it needs some refinement and could work better for some instruments than others.

Anyone is welcome to this code.