@@ -27,10 +27,30 @@ impl SimpleQuote {
2727 SimpleQuote { value }
2828 }
2929
30- /// Set the quote value.
30+ /// Sets the value of the quote and returns the difference between the new value and the old value.
31+ ///
32+ /// # Arguments
33+ ///
34+ /// * `value` - An optional new value to set.
35+ ///
36+ /// # Returns
37+ ///
38+ /// * `f64` - The difference between the new value and the old value. If the new value is not present,
39+ /// the difference will be 0.0.
40+ ///
41+ /// # Examples
42+ ///
43+ /// ```rust
44+ /// use RustQuant::cashflows::SimpleQuote;
45+ ///
46+ /// let mut quote = SimpleQuote::new(Some(10.0));
47+ /// let diff = quote.set_value(Some(15.0));
48+ /// assert_eq!(diff, 5.0);
49+ /// ```
3150 pub fn set_value ( & mut self , value : Option < f64 > ) -> f64 {
3251 let diff = match ( & self . value , & value) {
3352 ( Some ( old_value) , Some ( new_value) ) => new_value - old_value,
53+ ( None , Some ( new_value) ) => * new_value,
3454 _ => 0.0 ,
3555 } ;
3656
@@ -43,9 +63,24 @@ impl SimpleQuote {
4363 diff
4464 }
4565
46- /// Reset the quote value.
66+ /// Resets the value of the quote to `None`.
67+ ///
68+ /// This method clears the current value of the quote, effectively making it invalid.
69+ ///
70+ /// # Examples
71+ ///
72+ /// ```rust
73+ /// use RustQuant::cashflows::{Quote, SimpleQuote};
74+ ///
75+ /// let mut quote = SimpleQuote::new(Some(10.0));
76+ /// assert!(quote.is_valid());
77+ ///
78+ /// quote.reset();
79+ /// assert!(!quote.is_valid());
80+ /// assert_eq!(quote.value(), None);
81+ /// ```
4782 pub fn reset ( & mut self ) {
48- self . set_value ( None ) ;
83+ self . value = None ;
4984 }
5085}
5186
0 commit comments