Fix FutureSettlementModel cash adjustment for non-USD account currency - #9852
Open
abhi-byte62 wants to merge 1 commit into
Open
abhi-byte62 wants to merge 1 commit into
abhi-byte62 wants to merge 1 commit into
Conversation
In FutureSettlementModel.Scan and ApplyFunds, daily settled profit is computed in the account currency (via TotalCloseProfit and SettledProfit). When applying this settled profit to the contract's quote-currency cash balance in CashBook, convert the amount to quote currency using QuoteCurrency.ConversionRate to prevent cashbook and portfolio valuation drift in non-USD account currency setups. Fixes QuantConnect#9837
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
In \FutureSettlementModel.Scan, daily futures settlement P&L is computed using \FutureHolding.TotalCloseProfit(...), which calculates profit in the account currency (via \SecurityHolding.TotalCloseProfit\ converting legs into \InAccountCurrency). When this variation margin was credited or debited to \settlementParameters.Portfolio.CashBook[security.QuoteCurrency.Symbol].AddAmount(dailyProfitLoss), the account currency amount was applied directly to the quote currency balance without converting, causing the quote-currency cash to change by the wrong amount and leading to portfolio valuation drift under non-USD account currencies (e.g. an SGD account trading CME USD contracts).
Similarly in \FutureSettlementModel.ApplyFunds,
emovedSettledProfit\ is a portion of \SettledProfit\ (account currency) and was subtracted directly from \�pplyFundsParameters.CashAmount\ (which is constructed in the quote currency by \SecurityPortfolioModel.ProcessCloseTradeProfit).
This PR converts the daily settled P&L and
emovedSettledProfit\ to the quote currency using \security.QuoteCurrency.ConversionRate\ before adjusting the quote-currency cashbook balance.
Related Issue
Closes #9837
Motivation and Context
Prevents cash balance distortion and portfolio valuation drift during daily futures mark-to-market settlement and position closing when trading contracts quoted in a currency different from the account currency.
Requires Documentation Change
No.
How Has This Been Tested?
Types of changes
Checklist: