Giter Club home page Giter Club logo

Comments (10)

enzbus avatar enzbus commented on July 4, 2024

EDIT: I hadn't read your comment well. If you do nothing it simply carries over the value for the day (no look-ahead).

Hello, I also need to improve the docs on this. There are two ways to do it. One is to build a MPO policy by providing a list of objectives and a list of lists of constraints:

mpo_policy = cvx.MultiPeriodOptimization(
    objective = [cvx.ReturnsForecast(signal_today_dataframe) - gamma_risk * cvx.FullCovariance() - ...,
                cvx.ReturnsForecast(signal_tomorrow_dataframe) - gamma_risk * cvx.FullCovariance() - ...]
    constraints = [[cvx.LeverageLimit(3)],
                [cvx.LeverageLimit(3)]]
)

so the planning_horizon argument is unused. In this way you can change all the terms you want for each MPO step.

The other, in case you simply have slow and fast signals, is to use the decay argument of ReturnsForecast

mpo_policy = cvx.MultiPeriodOptimization(
    objective = cvx.ReturnsForecast(fast_signal_dataframe, decay = .2)
              + cvx.ReturnsForecast(slow_signal_dataframe, decay = .8)
              - gamma_risk * cvx.FullCovariance() , 
    constraints = [cvx.LeverageLimit(3)],
    planning_horizon = 5,
)

Let me know if this answers your question.

from cvxportfolio.

pcgm-team avatar pcgm-team commented on July 4, 2024

Thank you that clarifies perfectly. Very helpful.

from cvxportfolio.

enzbus avatar enzbus commented on July 4, 2024

I need to improve the docs for this; it might take a while so at least if someone comes here to ask something similar they find this.

from cvxportfolio.

pcgm-team avatar pcgm-team commented on July 4, 2024

One more question about the indexing of signal_today_dataframe and signal_tomorrow_dataframe in

mpo_policy = cvx.MultiPeriodOptimization(
    objective = [cvx.ReturnsForecast(signal_today_dataframe) - gamma_risk * cvx.FullCovariance() - ...,
                cvx.ReturnsForecast(signal_tomorrow_dataframe) - gamma_risk * cvx.FullCovariance() - ...]
    constraints = [[cvx.LeverageLimit(3)],
                [cvx.LeverageLimit(3)]]
)

Should the index be the dates of the prediction or the date it is predicting?
Ie lets say I have a dataframe with:
t symbol pred_{t+1} pred_{t+2} pred_{t+3}

Is signal_tomorrow_dataframe going to be
t pred_{t+2} (so the index is the date the prediction was made)
or should it be:
t+1 pred_{t+2}
Or even
t pred_t

from cvxportfolio.

enzbus avatar enzbus commented on July 4, 2024

The timestamp refers to the time of each period in the back-test, say 9:30am EST on a Monday. Then signal today, at timestamp 9:30am Monday, is the prediction of the return from 9:30am Monday to 9:30am Tuesday, signal tomorrow, at timestamp 9:30am Monday, is prediction of return from Tuesday to Wednesday, .... The time convention is the one defined in the paper, section 2. In practice you can assume that signal for today is built knowing all data up to the open price of today (and the open-to-open total return from yesterday open to today open). Does it make sense? I should definitely make these things clearer in the docs. The policy objects receive a view (past_returns) of the open-to-open total returns up to the open of the day, as a dataframe. ReturnsForecast without arguments simply computes a .mean() of that, so each day it does the full mean of all past returns for each name. In the user provided forecasters example you see how you can use the same model to do arbitrary forecasting.

from cvxportfolio.

pcgm-team avatar pcgm-team commented on July 4, 2024

so if I have a dataframe of signal_day_after_tomorrow (indices are the date the signals are created) I should shift it forward by two when I feed it into the objective?

from cvxportfolio.

enzbus avatar enzbus commented on July 4, 2024

I think in your formalism (comment before) it's t+1 pred t+1 for signal today, and so on. The timestamp in the signal dataframe is such that the prediction at that timestamp is done using all data up to the price at that timestamp. For signals for the future it's the same, but you predict a future quantity.

from cvxportfolio.

pcgm-team avatar pcgm-team commented on July 4, 2024

I'm still not 100% sure, but it sounds like basically if I got signal1 and and signal2 with index being the index outputted by a regression (so the date at which we predict target return of next day for signal1, and then that target shifted back by 1 for signal2); the correct way to use the optimizer would be something like:

mpo_policy = cvx.MultiPeriodOptimization(
    objective = [cvx.ReturnsForecast(signal1.shift(1)) - gamma_risk * cvx.FullCovariance() - ...,
                cvx.ReturnsForecast(signal2.shift(2)) - gamma_risk * cvx.FullCovariance() - ...]
    constraints = [[cvx.LeverageLimit(3)],
                [cvx.LeverageLimit(3)]]
)

I suppose what I'm confused about is whether it would instead be

mpo_policy = cvx.MultiPeriodOptimization(
    objective = [cvx.ReturnsForecast(signal1) - gamma_risk * cvx.FullCovariance() - ...,
                cvx.ReturnsForecast(signal2.shift(1)) - gamma_risk * cvx.FullCovariance() - ...]
    constraints = [[cvx.LeverageLimit(3)],
                [cvx.LeverageLimit(3)]]
)

from cvxportfolio.

enzbus avatar enzbus commented on July 4, 2024

You've got to think about the way data is consumed by your machine learning model that produces the signal. That's why you can take the user provided forecasters example as a starting point https://github.com/cvxgrp/cvxportfolio/blob/master/examples/user_provided_forecasters.py .

The line of your signal that has timestamp t, must be built with data that was available at time t. That's the case for all forecasted quantities: returns for the period, for the next period, volumes, risk model parameters, .... (If you don't have that property you're doing look-ahead and any analysis is invalid.)

from cvxportfolio.

enzbus avatar enzbus commented on July 4, 2024

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

from cvxportfolio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.