Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Cashflow Schedule Generation in Time Module for Pricing Models and Instruments #226

Open
joaquinbejar opened this issue Jun 22, 2024 · 2 comments

Comments

@joaquinbejar
Copy link
Contributor

Currently, RustQuant lacks a robust mechanism to generate cashflow schedules that can be utilized in conjunction with pricing models and financial instruments. This functionality is essential for accurately pricing a wide range of financial products, such as bonds, options, and swaps. The absence of this feature makes it challenging to perform comprehensive pricing and risk management.

I propose implementing a schedule generation feature within the time module. This feature will enable the creation of cashflow schedules based on specified parameters such as start date, end date, frequency, and conventions (day counting and date rolling). The generated schedules will integrate seamlessly with existing models and instruments, facilitating accurate pricing and valuation.

Describe alternatives:

  • Manually inputting cashflow dates for each instrument, which is time-consuming and error-prone.
  • Using external libraries for schedule generation, which might not align perfectly with RustQuant's architecture and conventions.

Additional context:

The implementation will involve:

  1. Creating functions to generate schedules based on input parameters (start date, end date, frequency, etc.).
  2. Ensuring compatibility with date rolling conventions and day counting conventions.
  3. Adding unit tests to validate the correctness of the generated schedules.
  4. Document the new functionality and provide examples of usage.

This enhancement will significantly improve RustQuant's ability to handle a variety of financial instruments and streamline the pricing and risk assessment process.

@joaquinbejar
Copy link
Contributor Author

This test is failing:

    // Test for non-matching dates during addition (should panic).
    #[test]
    #[should_panic(expected = "Dates must match.")]
    fn test_non_matching_dates_add() {
        let date1 = OffsetDateTime::now_utc();
        let date2 = date1 + Duration::days(1);
        let cf1 = SimpleCashflow::new(100.0, date1);
        let cf2 = SimpleCashflow::new(50.0, date2);
        let _ = cf1 + cf2;
    }
    
    ```
    
    Due the comparison among self.date and rhs.date is not working
    
    ```rust
    
    impl std::ops::Add for SimpleCashflow {
    type Output = Self;

    fn add(self, rhs: Self) -> Self::Output {
        assert_eq!(self.date, rhs.date, "Dates must match.");
        Self {
            amount: self.amount + rhs.amount,
            date: self.date,
        }
    }
}

Steps to Reproduce

Run the test test_non_matching_dates_add in the test suite.
Observe the test failing due to the assert_eq!(self.date, rhs.date, "Dates must match."); not working correctly.
Expected Behavior
The test should pass by panicking with the message "Dates must match." when self.date and rhs.date are not equal.

Environment
Rust version: 1.79.0
time crate version: v0.3.34

Possible Solution
Ensure that the OffsetDateTime comparison is correctly implemented or consider an alternative approach for comparing dates within the SimpleCashflow struct.

@avhz
Copy link
Owner

avhz commented Jun 24, 2024

Hi, the test passes for me.
Can you make a new issue with the error output ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants