Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single-step use question #121

Open
cadedoescode opened this issue Dec 13, 2023 · 5 comments
Open

Single-step use question #121

cadedoescode opened this issue Dec 13, 2023 · 5 comments

Comments

@cadedoescode
Copy link

Is there any information on how this package could be used to simply run a single optimizer step and return the weights (no backtest, save compute time, etc.)

Is this supported, or is there any recommendation?

I suppose simply calling backtest() with start_date equal to the last date could work. However, the last bar has nans for w_plus, which makes sense. Maybe this could be workarounded by just adding another dummy row or something but I'm just curious if theres been any thought around this.

@enzbus
Copy link
Collaborator

enzbus commented Dec 13, 2023

You're looking for the execute method of a policy object, I think. Let me know if it works for you, you need to instantiate a market data object for it, in a similar way of a market simulator.

You're right on the way the back-test result is formatted. In the future it will be possible to continue a back-test from the end, at the last timestamp you have the weights but not w_plus.

@enzbus
Copy link
Collaborator

enzbus commented Dec 27, 2023

PS I added a new option to cvx.DownloadedMarketData and cvx.UserProvidedMarketData, do_asset_selection, which is better set to False for online usage. This is only in the repository version at this point, and I'm testing it with examples/strategies/dow30_daily.py, running it every day at market open New York time. It will take some days to make it to a pip release.

@pcgm-team
Copy link

pcgm-team commented Jan 19, 2024

Another question about execute and online usage (and looking at your example dow30_daily).

cvx.UserProvidedMarketData (or in your case cvx.DownloadedMarketData) tends to be using open prices. But if you are online isn't the most recent price going to be close? Because you don't have the bar full bar yet to use open. do the 'price' df have one extra row than the volume and returns dfs passed into cvx.UserProvidedMarketData?

@enzbus
Copy link
Collaborator

enzbus commented Jan 21, 2024

You only need past returns (open prices are used by execute to give number of shares to trade, optionally). Past returns are passed down to all elements of a policy (covariance estimators, ...) to make their forecasts. If you don't know the most recent past return it's not necessarily a big deal. For online execution, though, you should know the most recent one to get the dollar holdings you have at time t. As you correctly say, Yahoo Finance doesn't provide accurate open prices a few minutes after market open. If I find another free source to use for that I'd switch, but for now I'm using the Yahoo Finance ones and then, next day, recompute the holdings for the past day. You can see it done in the commits, some names get a little adjustment. This is not part of the main library, it's logic specific for the examples strategies that are run online. I'll maybe work on making it smarter, but if you have paid data sources that give you more accurate prices you should probably use them. The example strategies do the best I can with free data.

@pcgm-team
Copy link

That clarifies, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants