Skip to content

Fix FutureSettlementModel cash adjustment for non-USD account currency - #9852

Open
abhi-byte62 wants to merge 1 commit into
QuantConnect:masterfrom
abhi-byte62:contrib/fix-future-settlement-currency
Open

abhi-byte62 wants to merge 1 commit into
QuantConnect:masterfrom
abhi-byte62:contrib/fix-future-settlement-currency

Conversation

@abhi-byte62

Copy link
Copy Markdown

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?

  • Added unit test \DailySettlementNonAccountCurrency\ in \FutureSettlementModelTests.cs\ testing various price movement scenarios with non-USD account currency (\ConversionRate != 1.0).
  • Added unit test \HoldingsQuantityChangeNonAccountCurrency\ in \FutureSettlementModelTests.cs\ verifying partial position closures and position flips under non-USD account currency.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which improves implementation)
  • Performance (non-breaking change which improves performance. Please add associated performance test and results)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Non-functional change (xml comments/documentation/etc)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

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
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

Successfully merging this pull request may close these issues.

FutureSettlementModel moves the daily settled P&L in the account currency into the quote-currency cash (non-USD account currency)

1 participant