ARKB for ARKW

This commit is contained in:
Elijah McMorris 2024-01-19 19:27:19 -08:00
parent 3fc6bdc2c7
commit 3ad11c2881
Signed by: NexVeridian
SSH key fingerprint: SHA256:bsA1SKZxuEcEVHAy3gY1HUeM5ykRJl0U0kQHQn0hMg8
4 changed files with 96 additions and 38 deletions

View file

@ -2,10 +2,27 @@
- Make sure the test pass - Make sure the test pass
- Run `cargo clippy --fix --allow-dirty` - Run `cargo clippy --fix --allow-dirty`
# License # Dev Install
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 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 # 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. 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.

View file

@ -1,8 +1,8 @@
[package] [package]
name = "ark-invest-api-rust-data" name = "ark-invest-api-rust-data"
license = "Apache-2.0"
version = "1.0.0" version = "1.0.0"
edition = "2021" edition = "2021"
license = "MIT OR Apache-2.0"
[dependencies] [dependencies]
polars = { version = "0.32", features = [ polars = { version = "0.32", features = [

View file

@ -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 # 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. 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)
[Why dual license](https://github.com/bevyengine/bevy/issues/2373)

View file

@ -274,6 +274,7 @@ impl Ark {
.lazy() .lazy()
.rename(vec!["CUSIP", "weight (%)"], vec!["cusip", "weight"]) .rename(vec!["CUSIP", "weight (%)"], vec!["cusip", "weight"])
.collect()?; .collect()?;
}
if !df.get_column_names().contains(&"market_value") { if !df.get_column_names().contains(&"market_value") {
df = df df = df
@ -285,7 +286,6 @@ impl Ark {
]) ])
.collect()?; .collect()?;
} }
}
Ok(df.into()) 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<Expr> = vec![]; let mut expressions: Vec<Expr> = vec![];
if df.fields().contains(&Field::new("weight", DataType::Utf8)) { if df.fields().contains(&Field::new("weight", DataType::Utf8)) {
@ -457,6 +476,12 @@ impl Ark {
.str() .str()
.replace_all(lit("."), lit(""), true) .replace_all(lit("."), lit(""), true)
.str() .str()
.replace(lit("HLDGS"), lit(""), true)
.str()
.replace(lit("HOLDINGS"), lit(""), true)
.str()
.replace(lit("Holdings"), lit(""), true)
.str()
.replace(lit("ORATION"), lit(""), true) .replace(lit("ORATION"), lit(""), true)
.str() .str()
.replace(lit("COINBASE GLOBAL"), lit("COINBASE"), true) .replace(lit("COINBASE GLOBAL"), lit("COINBASE"), true)
@ -533,7 +558,9 @@ impl Ark {
tic, last_day 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 { (tic, None) => match source {
Some(Source::ArkFundsIoFull) => { Some(Source::ArkFundsIoFull) => {
format!("https://arkfunds.io/api/v2/etf/holdings?symbol={}", tic) format!("https://arkfunds.io/api/v2/etf/holdings?symbol={}", tic)
@ -660,4 +687,40 @@ mod tests {
assert_eq!(read, test_df); assert_eq!(read, test_df);
Ok(()) 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(())
}
} }