Comments (7)
A
Curve
type could represent a yield curve or discount curve, or volatility term structure, for example.
Hi @avhz, could you please let me know if you're currently addressing this issue? If not, I would be happy to take on the task.
from rustquant.
@Autoparallel were you looking at this?
from rustquant.
@Autoparallel were you looking at this?
I was but got busy with other work
from rustquant.
@Autoparallel yeah no worries, just checking.
@Aditya-dom you might want to discuss with @Autoparallel here.
from rustquant.
@Autoparallel yeah no worries, just checking. @Aditya-dom you might want to discuss with @Autoparallel here.
Yup!! Thank you @avhz
from rustquant.
Hello @Autoparallel, Is there anything in this topic that I can help you with?
from rustquant.
Creating a Curve
trait with required methods:
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 YieldCurve
struct that conforms to the Curve
trait and represents a yield curve:
#[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, YieldCurve
stores dates and yields in a vector of
tuples. The new()
method initializes an empty YieldCurve
. The
points()
method returns a clone of the stored points vector. The
interpolate()
method checks the index and interpolates a yield between
two points based on the given fraction.
We can extend this code snippet to add more functionality or create other
curve types, such as DiscountCurve or VolatilityCurve, by implementing the
required Curve trait methods accordingly.
@avhz , @Autoparallel Hello! I've prepared a prototype for curve
and I'm excited about its potential. Would you be so kind as to grant me permission to proceed with the full implementation? Your support would mean a lot to me. Thank you!
from rustquant.
Related Issues (20)
- Implement a `Surface` type. HOT 7
- Add more calendars. HOT 7
- Implement Interest Rate Swap pricer. HOT 2
- feat(stochastics): Have time-varying parameters for processes HOT 5
- Use Release-Plz for automatic releases. HOT 6
- Add CEV process
- Implied volatility calculation HOT 4
- feat: Portfolio to have a get_weights() function or something similar HOT 1
- has some tutorial
- Can we support built-in "factor analysis"? HOT 3
- Deprecate `calendars` sub-module and move to `calenda-rs` crate.
- Replace `OffsetDateTime` with `Date`.
- Roadmap to `v1`
- doc.rs failed to build HOT 1
- decision tree algorithm for machine learning HOT 4
- Generalized Black-Scholes (GBS) model in Rust. HOT 2
- Inconsistency between code and documentation HOT 1
- CI/CD: GitHub Action `cargo_test` runs out of space on device.
- x86_64-pc-windows-gnu vs x86_64-pc-windows-msvc HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rustquant.