forked from calumrussell/rotala
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request calumrussell#79 from calumrussell/refactor-once-more
Refactor once more
- Loading branch information
Showing
51 changed files
with
2,889 additions
and
3,983 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.