Add Price, Value and Close aliases to BaseContract#9578
Merged
jhonabreul merged 5 commits intoJul 2, 2026
Merged
Conversation
Martin-Molinero
approved these changes
Jul 1, 2026
Martin-Molinero
approved these changes
Jul 1, 2026
Expose Price, Value and Close on BaseContract as aliases of LastPrice to mimic the BaseData/TradeBar API without inheriting BaseData. Marked with PandasIgnore to avoid duplicating the LastPrice column in chain DataFrames.
The pandas converter force-includes the 'Value' member for non-Lean-data types (to preserve the value column of custom data types despite BaseData.Value being PandasIgnore'd). That override made the new BaseContract.Value alias leak into option/future chain DataFrames as a redundant 'value' column. Exclude BaseContract-derived types from the forced inclusion so their PandasIgnore'd aliases are honored and the chain DataFrames stay unchanged.
OptionContract's default option data is the shared static OptionPriceModelResultData.Null singleton, which other tests mutate via Update. Reading LastPrice before setting up the contract's own data made the assertion depend on global test state (failing in CI with a leaked price). Assign a dedicated price model so the contract no longer reads from or writes to the shared singleton.
…red singleton OptionContract initialized its option data to the shared static OptionPriceModelResultData.Null singleton. Update() mutates that data, so contracts without an explicit price model shared and clobbered each other's trade/quote/open-interest state (a latent bug, and the cause of order-dependent test failures). Each contract now gets its own default OptionPriceModelResultData instance, and the alias test no longer needs to work around the shared state.
Revert OptionContract back to the shared static OptionPriceModelResultData.Null default. To keep the alias test deterministic, reset that singleton in the fixture's SetUp by updating a throwaway contract with a zero-priced trade bar, and give the tested contract its own price model so its Update doesn't re-pollute the singleton.
fd3986d to
0feb01c
Compare
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
Adds
Price,ValueandCloseproperties toBaseContract(inherited byOptionContractandFuturesContract) as aliases of the existingLastPriceproperty. This makes contracts mimic the familiarBaseData/TradeBarprice API without inheritingBaseData— a contract is an aggregator over several concurrent data streams (trade/quote bars, ticks, open interest, universe data, option price model), not a single data point, so inheritingBaseDatawould be conceptually wrong and would drag inReader/GetSource/Cloneand the ProtoBuf serialization contract.The new properties are
virtualand marked[PandasIgnore]so they compose with each contract's existingLastPriceoverride and do not add duplicate columns to the option/future chain DataFrames (mirroring howBaseDatatags its ownValue/Price).Related Issue
N/A
Motivation and Context
Users expect to be able to read
contract.Price,contract.Valueandcontract.Closethe same way they do on data/bars, for a consistent API surface across contracts and other data types.Requires Documentation Change
No.
How Has This Been Tested?
Added unit tests asserting
Price == Value == Close == LastPricefor bothOptionContractandFuturesContract, before any data (all zero) and after a trade-bar update. NewOptionContractTestsfixture and a new case inFuturesContractTests. Built the Tests project in Release (0 errors) and ran both fixtures — all 10 tests pass.Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>