How to run portfolio optimization backtest with model forecasts? #139
-
I have daily prices of an asset going back 10 years, and I have a model which every day predicts the prices for the next 30 days. This means that the predictions for the same future days can change day-to-day as the model will get newer information. I want to run Multi-Period optimization with horizon = 30, however the optimizer should take into account new forecasts daily and adjust positions accordingly. This is the code I started with where
This sketch does not take into account that I have multiple sets of returns (each day for 30 days ahead) rather than a single set. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 14 replies
-
Discussion in #117 is relevant, let me know if that answers (my first post there). You need to specify the MPO policy with a list of 30 objective terms and list of 30 lists of constraints... |
Beta Was this translation helpful? Give feedback.
-
An improved explanation of the multi-period optimization model was just merged in master, can be seen on the development version of the docs https://www.cvxportfolio.com/en/master/manual.html#multi-period-optimization |
Beta Was this translation helpful? Give feedback.
-
Thanks, that was very useful. I got it to work by having one single-row dataframe for each forecast. However my case is slightly different to the issue #117 as I have multiple forecasts for each timestamp as each day my model outputs 'fresher' predictions, from day ahead to 30 days ahead. Perhaps this is due to my lack of knowledge in portfolio optimization, what I assumed that we could do was feed 30 day ahead forecasts each day to the portfolio optimizer and have it run optimization with forecast_horizon = 30, then the next day feed it fresh predictions for the next 30 days and the optimizer will readjust. |
Beta Was this translation helpful? Give feedback.
I think if you were starting from
SinglePeriodOptimization
(which you should anyways) it would be clearer to you how it's done.The datetime indexes are used to provide data for many times of execution, so you can back-test the policy. If you simply want one execution (e.g., for using Cvxportfolio online) you may as well pass a bunch of Series indexed by the assets names. This is all explained in the passing data manual section.
For multi-period optimization policies, if you want to pass data, the datetimes for which the predictions are made are not used, only the concept of "how many steps ahead" is used. So you have dataframes that are all indexed by the time of execution, and each pred…