pub fn create_sample_position(
option_style: OptionStyle,
side: Side,
underlying_price: Positive,
quantity: Positive,
strike_price: Positive,
implied_volatility: Positive,
) -> PositionExpand description
Creates a sample position for testing and demonstration purposes.
This function generates a Position instance with predefined values for some fields
while allowing customization of key option parameters. It’s useful for creating test
scenarios, examples, or sample data for option position analysis.
§Parameters
option_style- The style of the option (Call or Put)side- Whether the position is Long or Shortunderlying_price- The current price of the underlying assetquantity- The number of option contracts in the positionstrike_price- The price at which the option can be exercisedimplied_volatility- The market’s forecast of likely movement in the underlying asset
§Returns
A Position instance with the specified parameters and these default values:
- European-style option
- “AAPL” as the underlying symbol
- 30-day expiration
- 5% risk-free rate
- 1% dividend yield
- Premium of $5.00
- Open and close fees of $0.50 each
- Current date and time
§Example
use optionstratlib_core::model::utils::create_sample_position;
use optionstratlib_core::model::{OptionStyle, Side};
use positive::{pos_or_panic, Positive};
let sample_call = create_sample_position(
OptionStyle::Call,
Side::Long,
pos_or_panic!(150.0), // underlying price
Positive::ONE, // quantity
pos_or_panic!(155.0), // strike price
pos_or_panic!(0.25) // implied volatility
);