-
-
Notifications
You must be signed in to change notification settings - Fork 123
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 a Curve
type.
#188
Comments
|
@Autoparallel were you looking at this? |
I was but got busy with other work |
@Autoparallel yeah no worries, just checking. |
|
Hello @Autoparallel, Is there anything in this topic that I can help you with? |
Creating a pub trait Curve {
type Point;
fn new() -> Self;
fn points(&self) -> Vec<Self::Point>;
fn interpolate(&self, index: usize, fraction: f64) ->
Option<Self::Point>;
} Next, let's define a #[derive(Debug, Clone)]
pub struct YieldCurve {
points: Vec<(DateTime<Utc>, f64)> // Date and yield
}
impl Curve for YieldCurve {
type Point = (DateTime<Utc>, f64);
fn new() -> Self {
YieldCurve::default()
}
fn points(&self) -> Vec<Self::Point> {
self.points.clone()
}
fn interpolate(&self, index: usize, fraction: f64) ->
Option<Self::Point> {
if index < self.points.len() && index >= 0 {
let point = &self.points[index];
Some((point.0 + chrono::Duration::seconds(f64::from(index as
i32 * (self.steps()))), interpolate_yield(*point,
*(self.points.get(index+1).map_or(None, |p| p.1)), fraction)))
} else {
None
}
}
}
fn interpolate_yield(prev: (DateTime<Utc>, f64), next: Option<f64>,
fraction: f64) -> f64 {
match next {
Some(next_yield) => prev.1 + ((next_yield - prev.1) * fraction),
None => prev.1,
}
} In the example above, We can extend this code snippet to add more functionality or create other @avhz , @Autoparallel Hello! I've prepared a prototype for |
A
Curve
type could represent a yield curve or discount curve, or volatility term structure, for example.The text was updated successfully, but these errors were encountered: