Expand description
A portfolio is a collection of Position
s, which are simply a combination
of an Instrument
, a quantity, a purchase price, and a current price.
You may also specify the Currency
of the instrument.
§Example
// Create a position of 100 call options.
let position_1 = Position {
instrument: BlackScholesMerton::new(
0.08,
60.0,
65.0,
0.3,
0.08,
None,
today() + Duration::days(91),
TypeFlag::Call,
),
quantity: 100,
purchase_price: 2.1045,
current_price: 3.5,
currency: Some(USD),
};
// Create a position of 100 put options.
let position_2 = Position {
instrument: BlackScholesMerton::new(
0.1 - 0.05,
100.0,
95.0,
0.2,
0.1,
None,
today() + Duration::days(182),
TypeFlag::Put,
),
quantity: 100,
purchase_price: 2.4524,
current_price: 2.0,
currency: Some(USD),
};
let positions = HashMap::from([
("Call Options".to_string(), position_1),
("Put Options".to_string(), position_2),
]);
// Create a portfolio.
let portfolio = Portfolio::new(positions);
// Check the value of the portfolio.
assert_approx_equal!(portfolio.value(), 100.0 * 3.5 + 100.0 * 2.0, 1e-10);
// Check the profit of the portfolio.
assert_approx_equal!(portfolio.profit(), 550.0 - portfolio.cost(), 1e-10);
Structs§
- Portfolio type. Simply a collection of positions.
- Position type.