-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
48 changed files
with
618 additions
and
455 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -3,11 +3,16 @@ name = "cqf" | |
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
ndarray = "0.15" | ||
rand = "0.8" | ||
rand_distr = "0.4" | ||
authors = ["[email protected]"] | ||
repository = "https://github.com/liberxue/cqf" | ||
homepage = "https://github.com/liberxue" | ||
|
||
[lib] | ||
name = "cqf" | ||
path = "src/lib.rs" | ||
|
||
[workspace] | ||
members = ["bench", "cli", "core"] | ||
|
||
|
||
[profile.release] | ||
lto = true | ||
codegen-units = 1 | ||
strip = "symbols" |
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,49 @@ | ||
.PHONY: init | ||
# init env | ||
init: | ||
@echo "init" | ||
|
||
.PHONY:fmt | ||
# cargo fmt | ||
fmt: | ||
@cargo fmt -v | ||
|
||
.PHONY:unitTest | ||
# unit Test | ||
test: | ||
@export RUST_LOG=info | ||
@cargo test -v | ||
|
||
.PHONY: build | ||
# cargo build | ||
build: | ||
@ if [ "$(OS)" == "Windows_NT" ]; then \ | ||
cargo clean && cargo check && cargo build --release --target=x86_64-pc-windows-gnu; \ | ||
elif [ "$(shell uname)" == "Darwin" ]; then \ | ||
cargo clean && cargo check && cargo build --release --target=x86_64-apple-darwin; \ | ||
else \ | ||
cargo clean && cargo check && cargo build --release --target=x86_64-unknown-linux-musl; \ | ||
fi | ||
|
||
.PHONY: all | ||
# generate all | ||
all: | ||
@echo "make all done" | ||
|
||
# show help | ||
help: | ||
@echo '' | ||
@echo 'Usage:' | ||
@echo ' make [target]' | ||
@echo '' | ||
@echo 'Targets:' | ||
@awk '/^[a-zA-Z\-\_0-9]+:/ { \ | ||
helpMessage = match(lastLine, /^# (.*)/); \ | ||
if (helpMessage) { \ | ||
helpCommand = substr($$1, 0, index($$1, ":")-1); \ | ||
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \ | ||
printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \ | ||
} \ | ||
} \ | ||
{ lastLine = $$0 }' $(MAKEFILE_LIST) | ||
.DEFAULT_GOAL := help |
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,8 @@ | ||
[package] | ||
name = "bench" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[[bin]] | ||
name = "bench" | ||
path = "src/main.rs" |
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,12 @@ | ||
[package] | ||
name = "cli" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["[email protected]"] | ||
repository = "https://github.com/liberxue/cqf" | ||
homepage = "https://github.com/liberxue" | ||
[[bin]] | ||
name = "cli" | ||
path = "src/main.rs" | ||
|
||
[dependencies] |
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,3 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
} |
Binary file not shown.
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,18 @@ | ||
[package] | ||
name = "core" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
|
||
[lib] | ||
path = "src/lib.rs" | ||
|
||
|
||
rand = "0.8" | ||
rand_distr = "0.4" | ||
|
||
|
||
[[test]] | ||
name = "core_tests" | ||
path = "tests/black_scholes_tests.rs" |
Binary file not shown.
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,3 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
} |
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
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
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.
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,52 @@ | ||
use crate::models::OptionPricingModel; | ||
use crate::strategies::OptionStrategy; | ||
|
||
pub struct ButterflySpread<'a, T: OptionPricingModel> { | ||
pub model: &'a T, | ||
pub s: f64, | ||
pub k1: f64, | ||
pub k2: f64, | ||
pub k3: f64, | ||
pub r: f64, | ||
pub sigma: f64, | ||
pub t: f64, | ||
} | ||
|
||
impl<'a, T: OptionPricingModel> ButterflySpread<'a, T> { | ||
pub fn new( | ||
model: &'a T, | ||
s: f64, | ||
k1: f64, | ||
k2: f64, | ||
k3: f64, | ||
r: f64, | ||
sigma: f64, | ||
t: f64, | ||
) -> Self { | ||
Self { | ||
model, | ||
s, | ||
k1, | ||
k2, | ||
k3, | ||
r, | ||
sigma, | ||
t, | ||
} | ||
} | ||
} | ||
|
||
impl<'a, T: OptionPricingModel> OptionStrategy for ButterflySpread<'a, T> { | ||
fn price(&self) -> f64 { | ||
let c1 = self | ||
.model | ||
.call_price(self.s, self.k1, self.r, self.sigma, self.t); | ||
let c2 = self | ||
.model | ||
.call_price(self.s, self.k2, self.r, self.sigma, self.t); | ||
let c3 = self | ||
.model | ||
.call_price(self.s, self.k3, self.r, self.sigma, self.t); | ||
c1 - 2.0 * c2 + c3 | ||
} | ||
} |
Oops, something went wrong.