Comments (10)
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.
Thank you that clarifies perfectly. Very helpful.
from cvxportfolio.
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.
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.
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.
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.
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.
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.
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.
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)
- pip install complains of scipy<1.11.0 HOT 4
- User provided returns forecast (`r_hat`) can be problematic HOT 1
- Interest rate on short sell cash proceeds
- Error from sp500_ndx100 example HOT 1
- Issue When Running examples/sp500_ndx100.py HOT 5
- I HOT 2
- NaN Handling HOT 3
- Single-step use question HOT 5
- do_asset_selection potential bug HOT 3
- Pandas 2.2.0 causes issues HOT 1
- Possible issue when using Cvxportfolio's internet access through a VPN HOT 4
- Make test suite fail on warnings
- Questions on accounting model (e.g., for short positions) HOT 3
- Robustify online execution of example strategies (when open prices are missing) HOT 1
- Failure on non-numeric (object dtpye) user-provided data difficult to understand HOT 6
- Example request - Margin in a different currency HOT 14
- BUG: packaging failed to include modules moved into submodules (constraints, data)
- Feature request: handle user-defined time-varying universes (and better error checks with temporary `nan`s in user-provided returns) HOT 13
- Data quality issues in `ftse100_daily` example strategy
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cvxportfolio.