-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Fix weights calculation in VBaseSignalExport #9258
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
Open
vb-vlb
wants to merge
5
commits into
QuantConnect:master
Choose a base branch
from
validityBase:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+69
−11
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6b31166
Fix weights calculation in VBaseSignalExport
vb-vlb f38786e
fix empty portfolio handling
vb-vlb 6784603
Refactored signal export to compute and export weights for all portfo…
vb-vlb 10e58b0
Update BuildCsv XML doc to clarify CSV output details
vb-vlb 95382f9
Clarify comments on portfolio value and empty weights
vb-vlb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @vb-vlb!
The original implementation is expecting percentages/weights to be passed in, as documented at https://www.quantconnect.com/docs/v2/writing-algorithms/live-trading/signal-exports/vbase#01-Introduction see also example algorithm https://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/VBaseSignalExportDemonstrationAlgorithm.py .
If the API is expecting percentages/weights too this means this implementation shouldn't be doing any math at all but just passing through the values?
Please take a look at
SignalExport.SetTargetPortfolioFromPortfolio()too which will call Send onVBaseSignalExportpassing percent's too?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Martin-Molinero, thanks for the prompt reply.
In the VBaseSignalExportDemonstrationAlgorithm, the portfolio targets collection consists of a single record: SPY with a quantity of 0.25.
Since we only have one position with a quantity of 0.25, the weights output should consist of a single record with SPY having a weight of 1.
like this
sym,wt
SPY,1
In fact, because PortfolioTarget.Percent creates a new target for the specified percentage, we end up receiving a quantity of SPY that needs to be bought to make it 25% of the portfolio. This results in a stamped weights file like:
sym,wt
SPY,172
the documentation states:
“Under the hood, it uses PortfolioTarget.Percent to convert your absolute target quantities into portfolio weights.”
Which implies that the expected inputs are absolute target quantities, not derived quantities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm don't think this is right really, 0.25 mean 25% if the available portfolio, that shouldn't translate to 1 IMHO. The remaining 75% of the portfolio can be allocated to something else in the next minute for example
The documentation could be wrong, need an update 💯, but what matters I think is what it should/expected to be by the vbase api and consumer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Martin-Molinero ,
The business objective is to create a snapshot of portfolio weights that best reflects, economically, what the portfolio actually holds.
The vBase API does not analyze the contents of the file; it only stamps the hash. Maybe @greg-vbase from vBase can comment on this to confirm.
I still see two issues with the current implementation of VBaseSignalExport:
It takes quantity and passes it through PortfolioTarget.Percent, which returns a number of units. As a result, we end up stamping units instead of weights.
If I understand correctly, the targets in the signal export do not always contain all positions in the portfolio. Since we want to stamp the portfolio weights, we also need to include positions that already exist in the portfolio but are not listed in the targets.
The proposed PR addresses the issues above.