From 3ad11c28815aed954a422cfee54fb1ce3f85b39d Mon Sep 17 00:00:00 2001 From: NexVeridian Date: Fri, 19 Jan 2024 19:27:19 -0800 Subject: [PATCH] ARKB for ARKW --- CONTRIBUTING.md | 23 +++++++++++-- Cargo.toml | 2 +- README.md | 24 +------------- src/util.rs | 85 ++++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 96 insertions(+), 38 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7764671..e5a10ec 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,10 +2,27 @@ - Make sure the test pass - Run `cargo clippy --fix --allow-dirty` -# License -All code in this repository is dual-licensed under either [License-MIT](./LICENSE-MIT) or [LICENSE-APACHE](./LICENSE-Apache) at your option. This means you can select the license you prefer. +# Dev Install +## Dev Containers +Install docker, vscode and the [Dev Containers Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) -[Why dual license](https://github.com/bevyengine/bevy/issues/2373) +`git clone` + +`Ctrl+Shift+P` **Dev Containers: Open Folder in Container** + +Run code with `F5` or `cargo run` + +Run tests with `cargo t` + +## Docker Compose +`git clone` + +`docker compose -f docker-compose.dev.yml build && docker compose -f docker-compose.dev.yml up` + +Remove the cargo cache for buildkit with `docker builder prune --filter type=exec.cachemount` + +# License +All code in this repository is dual-licensed under either [License-MIT](./LICENSE-MIT) or [LICENSE-APACHE](./LICENSE-Apache) at your option. This means you can select the license you prefer. [Why dual license](https://github.com/bevyengine/bevy/issues/2373) # Your contributions Any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/Cargo.toml b/Cargo.toml index fc37352..56e083e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "ark-invest-api-rust-data" -license = "Apache-2.0" version = "1.0.0" edition = "2021" +license = "MIT OR Apache-2.0" [dependencies] polars = { version = "0.32", features = [ diff --git a/README.md b/README.md index 6f4a774..4948011 100644 --- a/README.md +++ b/README.md @@ -41,27 +41,5 @@ pub enum Source { } ``` -# Dev Install -## Dev Containers -Install docker, vscode and the [Dev Containers Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) - -`git clone` - -`Ctrl+Shift+P` **Dev Containers: Open Folder in Container** - -Run code with `F5` or `cargo run` - -Run tests with `cargo t` - -## Docker Compose -`git clone` - -`docker compose -f docker-compose.dev.yml build && docker compose -f docker-compose.dev.yml up` - -Remove the cargo cache for buildkit with `docker builder prune --filter type=exec.cachemount` - # License -All code in this repository is dual-licensed under either [License-MIT](./LICENSE-MIT) or [LICENSE-APACHE](./LICENSE-Apache) at your option. This means you can select the license you prefer. - -[Why dual license](https://github.com/bevyengine/bevy/issues/2373) - +All code in this repository is dual-licensed under either [License-MIT](./LICENSE-MIT) or [LICENSE-APACHE](./LICENSE-Apache) at your option. This means you can select the license you prefer. [Why dual license](https://github.com/bevyengine/bevy/issues/2373) diff --git a/src/util.rs b/src/util.rs index f162f20..fb0a56a 100644 --- a/src/util.rs +++ b/src/util.rs @@ -274,17 +274,17 @@ impl Ark { .lazy() .rename(vec!["CUSIP", "weight (%)"], vec!["cusip", "weight"]) .collect()?; + } - if !df.get_column_names().contains(&"market_value") { - df = df - .lazy() - .with_columns([ - Series::new("market_value", [None::]).lit(), - Series::new("shares", [None::]).lit(), - Series::new("share_price", [None::]).lit(), - ]) - .collect()?; - } + if !df.get_column_names().contains(&"market_value") { + df = df + .lazy() + .with_columns([ + Series::new("market_value", [None::]).lit(), + Series::new("shares", [None::]).lit(), + Series::new("share_price", [None::]).lit(), + ]) + .collect()?; } Ok(df.into()) @@ -362,6 +362,25 @@ impl Ark { } } + // format arkw, ARK BITCOIN ETF HOLDCO (ARKW) to ARKB + if let Ok(x) = df + .clone() + .lazy() + .with_columns(vec![ + when(col("company").eq(lit("ARK BITCOIN ETF HOLDCO (ARKW)"))) + .then(lit("ARKB")) + .otherwise(col("ticker")) + .alias("ticker"), + when(col("company").eq(lit("ARK BITCOIN ETF HOLDCO (ARKW)"))) + .then(lit("ARKB")) + .otherwise(col("company")) + .alias("company"), + ]) + .collect() + { + df = x; + } + let mut expressions: Vec = vec![]; if df.fields().contains(&Field::new("weight", DataType::Utf8)) { @@ -457,6 +476,12 @@ impl Ark { .str() .replace_all(lit("."), lit(""), true) .str() + .replace(lit("HLDGS"), lit(""), true) + .str() + .replace(lit("HOLDINGS"), lit(""), true) + .str() + .replace(lit("Holdings"), lit(""), true) + .str() .replace(lit("ORATION"), lit(""), true) .str() .replace(lit("COINBASE GLOBAL"), lit("COINBASE"), true) @@ -533,7 +558,9 @@ impl Ark { tic, last_day ), }, - (self::Ticker::ARKVX, None) => "https://api.nexveridian.com/ark_holdings?ticker=ARKVX".to_owned(), + (self::Ticker::ARKVX, None) => { + "https://api.nexveridian.com/ark_holdings?ticker=ARKVX".to_owned() + } (tic, None) => match source { Some(Source::ArkFundsIoFull) => { format!("https://arkfunds.io/api/v2/etf/holdings?symbol={}", tic) @@ -660,4 +687,40 @@ mod tests { assert_eq!(read, test_df); Ok(()) } + + #[test] + #[serial] + fn arkw_format_arkb() -> Result<(), Error> { + let test_df = df![ + "date" => ["2024-01-01", "2024-01-02"], + "ticker" => [None::<&str>, Some("TSLA")], + "cusip" => ["123abc", "TESLA"], + "company" => ["ARK BITCOIN ETF HOLDCO (ARKW)", "TESLA"], + "market_value" => [100, 400], + "shares" => [10, 20], + "share_price" => [10, 20], + "weight" => [10.00, 20.00] + ]?; + + Ark::write_df_parquet("data/test/ARKW.parquet".into(), test_df.clone().into())?; + let read = Ark::new(Source::Read, Ticker::ARKW, Some("data/test".to_owned()))?.collect()?; + fs::remove_file("data/test/ARKW.parquet")?; + + let df = Ark::df_format(read.into())?.collect()?; + assert_eq!( + df, + df![ + "date" => ["2024-01-01", "2024-01-02"], + "ticker" => ["ARKB", "TSLA"], + "cusip" => ["123abc", "TESLA"], + "company" => ["ARKB", "TESLA"], + "market_value" => [100, 400], + "shares" => [10, 20], + "share_price" => [10, 20], + "weight" => [10.00, 20.00] + ]? + ); + + Ok(()) + } }