Marigold / universal-portfolios

Collection of algorithms for online portfolio selection
Other
776 stars 213 forks source link

Practical use #42

Closed DrPaprikaa closed 3 years ago

DrPaprikaa commented 3 years ago

Hi, I just discovered your very cool repo. I was able to play with the parameters on my own historical data using :

algo = algos.OLMAR(window=5, eps=10)
result = algo.run(self.df)

The Jupiter Notebook has a "How to write your own algorithm" section but it is not, in my sense, very comprehensive.

How can I translate this algo into something that works realtime ? How do I feed the data in ? How do I extract the best model parameters at time t and translate this into actual buy & sell signals ?

I willing to help writting a comprehensive guide on how to do this and make a PR, can you point me in the right direction ? Thanks, DrPaprikaa

Marigold commented 3 years ago

Hey, this is solely a research project, it's not meant to run in "production". For that, you'll need to connect to a broker (like IB or something, there are tons of packages that can help you with that). OLMAR is such a simple algorithm that once you understand it, you can integrate it into your production code in like ~50 lines.

DrPaprikaa commented 3 years ago

Thanks for the quick reply. I already have a production algo and I have been researching strategies for a while now. I recently came across online portfolio selection algorithms and your repo specifically. I would like to understand how your code works and how I can input it in my personnal backtester, and ultimatly run it live.

Marigold commented 3 years ago

Understanding it is pretty easy, for instance OLMAR has just 70 lines. The step method returns portfolio weights for every time step from available inputs (last portfolio weights and historical prices). That's pretty easy to copy into any backtester.

DrPaprikaa commented 3 years ago

Thank you for your answer.

Btw, I get the error, in OLMAR's update() :

RuntimeWarning: divide by zero encountered in double_scalars
  lam = max(0., (eps - np.dot(b, x)) / np.linalg.norm(x - x_mean)**2)

which is due to x = [1, 1, ..., 1] at the first step, therefore x-x_mean = 0 and np.linalg.norm(x - x_mean)**2 = 0, therefore the division by zero (at the first step only, the code works fine after that).

Would you know a workaround ?

Thanks !