pub fn bet_size_dynamic(
pos: &[f64],
max_pos: &[f64],
m_p: &[f64],
f: &[f64],
) -> Result<Vec<(f64, f64, f64)>, BetSizingError>Expand description
Dynamic bet sizing from a price forecast (AFML §10.6, Snippet 10.4).
For each row of current position pos, maximum position max_pos, market price m_p
and forecast f (broadcast as in confirm_and_cast_to_df) returns
(bet_size, target_position, limit_price) using the sigmoid curve.
The width is fixed at get_w_sigmoid(10.0, 0.95): a divergence of 10 price units gives a
size of 0.95, whatever the instrument. For anything else calibrate your own w with
get_w and use get_target_pos and limit_price.
§Errors
BetSizingError::EmptyInput or BetSizingError::ShapeMismatch from
confirm_and_cast_to_df.
use openquant::bet_sizing::bet_size_dynamic;
let rows = bet_size_dynamic(&[0.0], &[100.0], &[95.0], &[100.0])?;
let (size, target, limit) = rows[0];
assert!((size - 0.836).abs() < 1e-3);
assert_eq!(target, 83.0);
assert!((limit - 98.22).abs() < 1e-2);