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

Port RiskEngine to Rust #2035

Merged
merged 20 commits into from
Nov 12, 2024
Merged

Conversation

Pushkarm029
Copy link
Collaborator

@Pushkarm029 Pushkarm029 commented Nov 1, 2024

Pull Request

  • Ports RiskEngine to Rust.
  • Ports calculate_fixed_risk_position_size to Rust.

TODOs:

  • Portfolio.rs [in another PR]
  • Find a way to verify successful executions in tests.

Type of change

  • New feature (non-breaking change which adds functionality)

How has this change been tested?

  • make cargo-test

Signed-off-by: Pushkar Mishra <[email protected]>
Copy link

codspeed-hq bot commented Nov 1, 2024

CodSpeed Performance Report

Merging #2035 will not alter performance

Comparing Pushkarm029:risk_engine (dd1a4ee) with develop (9e26d37)

Summary

✅ 52 untouched benchmarks

Copy link
Collaborator

@twitu twitu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking solid! I've addressed the closure issue.

}

impl<T, F> Debug for Throttler<T, F>
impl<T, S, D> Debug for Throttler<T, S, D>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need different parameters for Send and Drop when they are the same traits Fn(T)? Have you considered removing it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, I was registering two different functions with the same parameters, which was causing an error. The compiler requires both functions to be identical, so I made this change. However, since we're now using closures as callbacks, this is no longer needed, so I have removed it.

@@ -33,6 +33,7 @@ pub use self::{
};

#[derive(Clone, Debug, Display)]
#[allow(clippy::large_enum_variant)] // TODO: why?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is a problem that will have to be fixed throughout the system. We'll tackle this once significant control flow is in Rust.

nautilus_core/risk/src/engine/tests.rs Outdated Show resolved Hide resolved
Comment on lines +72 to +74
clock: Rc<RefCell<dyn Clock>>,
cache: Rc<RefCell<Cache>>,
msgbus: Rc<RefCell<MessageBus>>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rc RefCell is equivalent to a Python pointer - a shared reference that is garbage collected. Common state between components will be shared this way.

Comment on lines 81 to 85
Box::new(move |order: SubmitOrder| {
msgbus1
.borrow_mut()
.send(&Ustr::from("ExecEngine.execute"), &order);
}) as Box<dyn Fn(SubmitOrder)>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trick here is that the closure does not need the whole RiskEngine i.e. &self state. It only needs a reference to the message bus since its own job is to send a message. By cloning and moving the message bus into the closure we can avoid the inner outer pattern.

nautilus_core/risk/src/engine/mod.rs Outdated Show resolved Hide resolved
Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
Signed-off-by: Pushkar Mishra <[email protected]>
@Pushkarm029 Pushkarm029 marked this pull request as ready for review November 12, 2024 11:09
Signed-off-by: Pushkar Mishra <[email protected]>
Copy link
Member

@cjdsellers cjdsellers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work here!

@cjdsellers cjdsellers merged commit 78fdd19 into nautechsystems:develop Nov 12, 2024
11 checks passed
@Pushkarm029 Pushkarm029 deleted the risk_engine branch November 13, 2024 10:22
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

Successfully merging this pull request may close these issues.

3 participants