Skip to content

Commit

Permalink
Merge pull request calumrussell#79 from calumrussell/refactor-once-more
Browse files Browse the repository at this point in the history
Refactor once more
  • Loading branch information
calumrussell authored Jun 29, 2024
2 parents 3b072af + 0f8bdd8 commit f814dfa
Show file tree
Hide file tree
Showing 51 changed files with 2,889 additions and 3,983 deletions.
46 changes: 6 additions & 40 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,41 +1,7 @@
[package]
name = "rotala"
version = "0.4.1"
edition = "2021"
authors = ["Calum Russell <[email protected]>"]
license-file = "LICENCE"
description = "JSON server exchange and library for backtesting trading strategies"
repository = "https://github.com/calumrussell/alator"
readme = "README.md"
[workspace]

[dependencies]
actix-web = "4"
time = { version = "0.3.17", features = ["macros", "parsing"] }
rand = "0.8.4"
rand_distr = "0.4.1"
reqwest = { version = "0.12.4", features=["blocking", "json"] }
zip = "2.1.3"
csv = "1.1.6"
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"
env_logger = "0.11.0"
tokio = { version = "1.35.1", features = ["full"] }
derive_more = "0.99.17"

[dev-dependencies]
criterion = { version="0.5.1", features= ["async_tokio"] }

[[bin]]
name = "uist_server_v1"
path = "./src/bin/uist_server_v1.rs"

[[bin]]
name = "jura_server_v1"
path = "./src/bin/jura_server_v1.rs"

[lib]
bench = false

[[bench]]
name = "sim_orderbook"
harness = false
resolver = "2"
members = [
"rotala",
"example_clients/alator"
]
33 changes: 0 additions & 33 deletions benches/sim_orderbook.rs

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pyo3 = { version = "0.20.0", optional = true }
async-trait = "0.1.73"
tokio = { version = "1.32.0", features = ["full"] }
futures = "0.3.28"
rotala = { version = "0.1.0" }
rotala = { path = "../../rotala/" }

[dev-dependencies]
reqwest = { version = "0.11.11", features=["blocking"] }
Expand Down
File renamed without changes.
File renamed without changes.
73 changes: 73 additions & 0 deletions example_clients/alator/benches/sim_benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
use alator::broker::uist::UistBrokerBuilder;
use alator::broker::{BrokerCost, CashOperations, SendOrder, Update};
use criterion::{criterion_group, criterion_main, Criterion};
use std::collections::HashMap;

use alator::strategy::staticweight::StaticWeightStrategyBuilder;
use rotala::http::uist::uistv1_client::{TestClient, UistClient};
use rotala::input::penelope::Penelope;

async fn full_backtest_random_data() {
let source = Penelope::random(100, vec!["ABC", "BCD"]);

let initial_cash = 100_000.0;

let mut weights = HashMap::new();
weights.insert("ABC".to_string(), 0.5);
weights.insert("BCD".to_string(), 0.5);

let mut client = TestClient::single("Random", source);
let resp = client.init("Random".to_string()).await.unwrap();

let simbrkr = UistBrokerBuilder::new()
.with_client(client, resp.backtest_id)
.with_trade_costs(vec![BrokerCost::Flat(1.0)])
.build()
.await;

let mut strat = StaticWeightStrategyBuilder::new()
.with_brkr(simbrkr)
.with_weights(weights)
.default();

strat.init(&initial_cash);
strat.run().await;
}

async fn trade_execution_logic() {
let mut source = Penelope::new();
source.add_quote(100.00, 101.00, 100, "ABC");
source.add_quote(10.00, 11.00, 100, "BCD");
source.add_quote(100.00, 101.00, 101, "ABC");
source.add_quote(10.00, 11.00, 101, "BCD");
source.add_quote(104.00, 105.00, 102, "ABC");
source.add_quote(10.00, 11.00, 102, "BCD");
source.add_quote(104.00, 105.00, 103, "ABC");
source.add_quote(12.00, 13.00, 103, "BCD");

let mut client = TestClient::single("Random", source);
let resp = client.init("Random".to_string()).await.unwrap();

let mut brkr = UistBrokerBuilder::new()
.with_client(client, resp.backtest_id)
.build()
.await;

brkr.deposit_cash(&100_000.0);
brkr.send_order(rotala::exchange::uist_v1::Order::market_buy("ABC", 100.0));
brkr.send_order(rotala::exchange::uist_v1::Order::market_buy("BCD", 100.0));

brkr.check().await;

brkr.check().await;

brkr.check().await;
}

fn benchmarks(c: &mut Criterion) {
c.bench_function("full backtest", |b| b.iter(full_backtest_random_data));
c.bench_function("trade test", |b| b.iter(trade_execution_logic));
}

criterion_group!(benches, benchmarks);
criterion_main!(benches);
Loading

0 comments on commit f814dfa

Please sign in to comment.