* Allow SetAccountCurrency after SetCash without throwing
Previously, calling SetAccountCurrency after SetCash threw an
InvalidOperationException. The portfolio manager now switches the
base account currency in place: the previous Cash entry (and its
balance) is preserved in the CashBook, and a notice is logged. When
the new account currency matches the existing one, an optional
startingCash overrides the previously set amount and the override
is logged.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Simplify SetAccountCurrency remarks and drop unused message
Tightens the XML remarks to two cases (different currency: keep previous
in its own entry; matching currency: override). Also removes the now
unused CannotChangeAccountCurrencyAfterSettingCash string since the
portfolio no longer throws.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Simplify in-line comment in SetAccountCurrency
Drops the "Undo that migration" wording (residue from a previous fix
attempt) and just describes what the branch does: keep the previous
balance in its own currency entry while the new account currency starts
at zero.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Differentiate implicit vs explicit SetCash on account currency switch
SetCash(decimal) is currency-agnostic: the amount is "this many units of
the (eventual) account currency". Switching the account currency now
re-labels the amount onto the new currency instead of preserving the
previous one. SetCash(symbol, ...) for the current account currency keeps
the old behaviour of preserving the balance in its own CashBook entry.
Splits the existing tests by overload and adds a starting-cash variant
for the explicit case.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Mark base cash explicit on any SetCash(symbol, ...) call
Broaden _baseCashSymbolSetExplicitly so any call to the explicit-currency
overload signals the user is committing to named currencies, not just
calls whose symbol matches the current account currency. SetAccountCurrency
then preserves the previous base-currency balance in its own CashBook
entry whenever the user has touched the explicit overload at all.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Regression Tests / build (push) Has been cancelled
Report Generator Tests / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
API Tests / build (push) Has been cancelled
Syntax Tests / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
* fix: add AJY future-option expiry definition
- map AJY (AUD/JPY) FOP to SecondFridayBeforeThirdWednesdayOfContractMonth
- prior fallback to the AJY HMUZ-only future expiry collapsed serial-month FOPs (e.g. AJYN6) into their underlying quarterly Symbol
* fix: add ANE and ECD future-option expiry definitions
- map ANE (AUD/NZD) and ECD (EUR/CAD) FOPs to SecondFridayBeforeThirdWednesdayOfContractMonth
- prior fallback to the HMUZ-only future expiry collapsed serial-month FOPs into their underlying quarterly Symbol
Build & Test Lean / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
Report Generator Tests / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
Syntax Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
* feature: add NASDAQ_SC and NASDAQ_INT equity exchanges
- map primary exchange codes S and T to new NASDAQ tier exchanges
- T was previously folded into NASDAQ, now returns NASDAQ_INT
- add V as alias for IEX in equity switch
- fix MEMX description (was copy of LTSE)
* feature: map equity exchange codes H and U to MIAX_PEARL and MEMX
* feature: consolidate NASDAQ_INT code T into NASDAQ_SC
Remove the separate NASDAQ_INT mapping in GetPrimaryExchange and map
exchange code "T" to NASDAQ_SC. Update ExchangeTest cases accordingly
and add coverage for IEX ("V") and MEMX ("U").
* feature: remove orphaned NASDAQ_INT exchange entry
Drop the NASDAQ_INT class entry from Exchange.cs. The "T" tape letter
already routes to Exchange.NASDAQ via GetPrimaryExchange, leaving the
class definition unreachable and inconsistent.
* fix: support BNFCR alternative collateral in CryptoFutureMarginModel for Binance (#9339)
* refactor: use classic switch in BinanceFuturesBrokerageModel.GetBuyingPowerModel
* fix: CryptoFutureMarginModel in BinanceCoinFuturesBrokerageModel
* refactor: simplify BinanceCryptoFutureMarginModel collateral conversion
* fix: restore IsCryptoCoinFuture guard in BinanceCryptoFutureMarginModel
* refactor: simplify BinanceCryptoFutureMarginModel to direct BNFCR lookup
Replace IsStableCoinWithoutPair foreach loop with a single TryGetValue
check for BNFCR. BNFCR is EU/EEA-only (MiCA Credits Trading Mode) so
the lookup is a no-op for all other users. Amount reflects availableBalance
from the Binance API — the total cross-margin pool already aggregated by
Binance — making the > 0 guard correct and avoiding CashBook iteration.
* feat: add regression algorithm for BNFCR as sole collateral on Binance USDⓈ-M futures
Asserts end-to-end that EU/MiCA accounts with zero USDT and BNFCR as
the only collateral can open ADAUSDT positions. Verifies buying power,
holdings AbsoluteHoldingsCost, TotalSaleVolume, TotalMarginUsed,
maintenance margin consistency and TotalUnrealizedProfit accuracy.
* refactor: BNFCR presence gate with CashBook iteration for supplementary collateral
Replace IsStableCoinWithoutPair and hardcoded asset list with CashBook
iteration gated by BNFCR presence. Binance controls which assets are in
the account — all with non-zero walletBalance are valid collateral.
Add tests for BNFCR zero balance and BTC collateral conversion.
* refactor: aggregate all collateral without reference equality check
* fix: shared collateral deduction across quote currencies for EU/MiCA BNFCR mode
- Extract virtual SharesCollateral in CryptoFutureMarginModel
- Override in BinanceCryptoFutureMarginModel: BNFCR present → all USDⓈ-M share pool
- Add BNFCRCurrency const
- Add SharedCollateralDeductsMaintenanceMarginAcrossQuoteCurrencies unit test
- Refactor regression algorithm to assert shared collateral across ADAUSDT/ETHUSDC
* refactor: remove dead IsCryptoCoinFuture guard from BinanceCryptoFutureMarginModel
- Remove IsCryptoCoinFuture() check (coin futures use BinanceCoinFuturesBrokerageModel, not this model)
- Call base.GetTotalCollateralAmount() instead of duplicating primaryCollateral.Amount
- Remove CoinFutureDoesNotIncludeBnfcrAsCollateral test (tested wrong margin model)
* refactor: make GetCollateralCash private in CryptoFutureMarginModel
- No longer accessed by subclasses after removing direct collateral checks from BinanceCryptoFutureMarginModel
Build & Test Lean / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
API Tests / build (push) Has been cancelled
Benchmarks / build (push) Has been cancelled
Report Generator Tests / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
Syntax Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
* Improves Null Key Handling in Python
We aim to mimic the following behavior:
```python
>>> d = {1:2}
>>> None in d
False
>>> d.get(None) is None
True
>>> d.pop(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: None
>>> d.pop(None, None) is None
True
```
* Reverts dispose change
Build & Test Lean / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
Report Generator Tests / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
Syntax Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
* Add ContractMultiplier setter to Cfd via CfdSymbolProperties
* Fix regression tests
* Solve review comments
* Address new review comments
* Fix regression tests
* Use ContractSymbolProperties as base class
* Minor fix
* Address review comment
* Add failing test for BRK.B OSI option ticker parsing
Adds test case to ParseOptionTickerOSI to reproduce issue #9341 where
Symbol.ParseOptionTickerOSI throws on tickers containing a dot (e.g. BRK.B).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Fix OSI option ticker regex to support dots in underlying symbol
Extends _optionTickerRegex from [A-Z0-9]+ to [A-Z0-9\.]+ so that
symbols like BRK.B are accepted by ParseOptionTickerOSI.
Fixes#9341
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
* Use universe settings when adding derivatives
Use resolution, fill forward and extended market hours settings from universe settings when adding derivative securities (options, index options, futures and future options)
* Minor python syntax check fix
* Minor change
* Default resolution from universe settings for common lean types securities
* Minor test fix
* Cleanup
Report Generator Tests / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
Syntax Tests / build (push) Has been cancelled
Benchmarks / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
* Fix: Reject unsupported 4-leg ComboLegLimit orders in InteractiveBrokersBrokerageModel (#9287)
* Minor tweaks
---------
Co-authored-by: Ahmed Ali <ahmedalli79x@gmail.com>
Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
Build & Test Lean / build (push) Has been cancelled
Syntax Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
Report Generator Tests / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
* Implement indicator-based option price model
This model uses IV and Greeks indicators to implement Lean's own option pricing model
* Minor fixes
* Address peer review
* Minor tests fixes
* Make the indicator based price model the default for options
* Address peer review
* Cleanup and minor changes
* Support indicators configuration for new pricing model
* Some cleanup
* Add QL option price model example algorithm
* Return lean models from static helpers
* Minor tests fixes
* Minor test fixes
* Address peer review
* Cleanup
* Fix unit tests
* Move QL models to OptionPriceModels.QuantLib.*
* Add forward tree helper method
* Fix trade drawdown calculation
* Cleanup
* Disable MAE. MFE and Drawdown calculation for FlatToFlat and FlatToReduced trade grouping methods
* Minor test fixes
Report Generator Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
API Tests / build (push) Has been cancelled
Benchmarks / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
Syntax Tests / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
* Add total performance statistics to live result files
* Truncate closed trades in live results
* Avoid adding totalPerformance to live minute result file
* Deprecated Trade.Symbol in favor of new Trade.Symbols
* Fixes for Trade serialization
* Add trades json serialization tests
* Cleanup
Python Virtual Environments / build (push) Has been cancelled
Syntax Tests / build (push) Has been cancelled
API Tests / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
Benchmarks / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
Report Generator Tests / build (push) Has been cancelled
* Fix NullReferenceException in SecurityService
* Simplify the unit test
* Add unit test for RandomDataGenerator
* Improve unit test name
* Solve review comments
* Return weekly contracts if no standard contracts exist
* Fix unit and regression tests
* Centralize default expiration type flags
* Add ExcludeWeeklys() method
* Mark IncludeWeeklys() as obsolete since weeklies are now default
* Refactor ApiClient to use HttpClient
* Minor fix
* Refactor and cleanup in ApiConnection
* Add normalized extension methods for string and stream json serialization
* Minor fixes
* Address peer review
* Minor fixes
* Minor fixes and peer review
* Race condition fix
* Minor changes
* Cleanup
* Minor fixes
* Minor fix
* Centralize Python/C# model detection logic
* Improve helper method
* Remove unnecessary conditionals
* Fix unit tests
* Refactor QCAlgorithm.python.cs to use the new helper method for models
* Solve review comments
* Clean up Python wrapper exception
* Update XML comments to better describe T and TWrapper in CreateModelOrWrapper
* Join unit tests in TestCases
* Solve review comments
* Replace manual TryConvert checks with CreateInstanceOrWrapper helper
Report Generator Tests / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
Syntax Tests / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
* fix: use decimal instead long in Scale's LeanData
test:feat: validate naming with large precision
* feat: use normalization in Scale's LeanData
test:fix: strike precisions
* fix: use str normalization in Scale's LeanData
Regression Tests / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
Syntax Tests / build (push) Has been cancelled
API Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
Benchmarks / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Report Generator Tests / build (push) Has been cancelled
* Increase option strike digits precision to 6
- Increase option strike digits precision to 6. Adding unit test
* test:fix: couple of build tests
* fix:test: Asset CUSIP and OrderListHash in Regression Algorithms
* test:fix: several regression algos
* test:fix: old Symbol CUSIPs to new ones
---------
Co-authored-by: Romazes <romazes20@gmail.com>
Build & Test Lean / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
API Tests / build (push) Has been cancelled
Benchmarks / build (push) Has been cancelled
Report Generator Tests / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
Syntax Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
* Add SeedInitialPrices algorithm setting
This is true by default and indicates that the engine will seed initial prices right after the security is added or selected
* Update regression algorithms
* Update regression algorithms
* Update regression algorithms
* Refactor default securities seeding
* Minor fix
* Minro fixes
* Cleanup
* Updated and add regression algorithms
* Address peer review
* Centralize logic to get last known data for multiple securities
* Some cleanup
* Minor build fix
* Minor fixes
* More logic centralization
* Some more cleanup
* Cleanup
* Update regression algorithms and minor fixes
* Update regression algorithms
* Minor fix
* More minor fixes
* Update regression algorithms
* Cleanup
* Minor test fix
* Address peer review
* Minor fix and performance improvement
* Fix to seed open interest data
* Minor test fixes
* Address peer review
* Minor change
* Minor revert
* Minor fixes and improvements
* Disable initial seeding by default
* Minor fixes
* Cleanup
* Cleanup
* Minor fix
* Refactor user define universe handling
- Normalize user define universe additions and removals to behave like
other subscriptions without requiting special handling
* Minor fixes
Build & Test Lean / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
Report Generator Tests / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
Syntax Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
* Fix performance degradation on expirying assets
- Options would expire and get removed, when the universe removed the
security it would never be reseted on universe selection, causing
leaks
- Minor improvement for composer assembly loading
- Minor improvement for loading exception interepreters, so it uses
composer
* Minor regression test fix
* Add new benchmark algorithm