pub struct Curve(/* private fields */);Expand description
A representation of a piecewise-linear, weakly monotone decreasing demand curve
Demand curves define a bidder’s willingness to pay for different quantities of a good. In flow trading, these curves must be:
- Piecewise-linear (defined by a sequence of points)
- Weakly monotone decreasing (price non-increasing as rate increases)
- Include the point rate=0 in their domain (must allow zero trade)
Implementations§
Source§impl Curve
impl Curve
Sourcepub fn new(points: Vec<Point>) -> Result<Self, ValidationError>
pub fn new(points: Vec<Point>) -> Result<Self, ValidationError>
Creates a new demand curve from a sequence of points
Validates that the points:
- Are not empty
- Have valid (non-NaN, non-infinite) coordinates
- Are ordered by ascending rate and descending price
- Include rate=0 in their domain (first point rate ≤ 0, last point rate ≥ 0)
Returns a ValidationError if any of these conditions are not met.
Sourcepub unsafe fn new_unchecked(points: Vec<Point>) -> Self
pub unsafe fn new_unchecked(points: Vec<Point>) -> Self
Creates a new Curve without validating the points
§Safety
This function should only be used when the caller can guarantee that
the points satisfy all the requirements that new would check.
Using invalid points can lead to incorrect behavior in downstream systems.
Source§impl Curve
impl Curve
Sourcepub fn as_solver(&self, scale: f64) -> PiecewiseLinearCurve
pub fn as_solver(&self, scale: f64) -> PiecewiseLinearCurve
Removes any collinearities and scales by the provided value
This optimizes the curve representation by:
- Removing intermediate points that lie on the same line segment
- Scaling rates by the provided factor to convert to quantities
The resulting curve is suitable for use with the solver library.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Curve
impl<'de> Deserialize<'de> for Curve
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for Curve
Auto Trait Implementations§
impl Freeze for Curve
impl RefUnwindSafe for Curve
impl Send for Curve
impl Sync for Curve
impl Unpin for Curve
impl UnwindSafe for Curve
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more