diff --git a/Cargo.lock b/Cargo.lock index ff7d0d4..285ac5d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -273,12 +273,13 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.94" +version = "1.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f6e324229dc011159fcc089755d1e2e216a90d43a7dea6853ca740b84f35e7" +checksum = "065a29261d53ba54260972629f9ca6bffa69bac13cd1fed61420f7fa68b9f8bd" dependencies = [ "jobserver", "libc", + "once_cell", ] [[package]] @@ -559,15 +560,15 @@ checksum = "95765f67b4b18863968b4a1bd5bb576f732b29a4a28c7cd84c09fa3e2875f33c" [[package]] name = "fastrand" -version = "2.0.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" [[package]] name = "flate2" -version = "1.0.28" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" dependencies = [ "crc32fast", "miniz_oxide", @@ -715,9 +716,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ "ahash", "allocator-api2", @@ -895,9 +896,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "jobserver" -version = "0.1.30" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "685a7d121ee3f65ae4fddd72b25a04bb36b6af81bc0828f7d5434c0fe60fa3a2" +checksum = "d2b099aaa34a9751c5bf0878add70444e1ed2dd73f347be99003d4577277de6e" dependencies = [ "libc", ] @@ -992,9 +993,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.153" +version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" [[package]] name = "libm" @@ -1010,9 +1011,9 @@ checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -1245,9 +1246,9 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" dependencies = [ "lock_api", "parking_lot_core", @@ -1255,15 +1256,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.9" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-targets 0.48.5", + "windows-targets 0.52.5", ] [[package]] @@ -1576,7 +1577,7 @@ dependencies = [ [[package]] name = "polygon-client" version = "0.1.1" -source = "git+https://github.com/jczaja/polygon-client-rs.git#2426e52efa12e7aeadf92185b107f9cb1f749582" +source = "git+https://github.com/jczaja/polygon-client-rs.git#b039259a3babba7f22484ad3310e16fdb1d60979" dependencies = [ "chrono", "lazy_static", @@ -1692,11 +1693,11 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.4.1" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.5.0", ] [[package]] @@ -1785,9 +1786,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.32" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ "bitflags 2.5.0", "errno", @@ -1863,18 +1864,18 @@ checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" [[package]] name = "serde" -version = "1.0.198" +version = "1.0.200" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" +checksum = "ddc6f9cc94d67c0e21aaf7eda3a010fd3af78ebf6e096aa6e2e13c79749cce4f" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.198" +version = "1.0.200" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" +checksum = "856f046b9400cee3c8c94ed572ecdb752444c24528c035cd35882aad6f492bcb" dependencies = [ "proc-macro2", "quote", @@ -1919,9 +1920,9 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" dependencies = [ "libc", ] @@ -1972,9 +1973,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.5.6" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", "windows-sys 0.52.0", @@ -2128,18 +2129,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.58" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.58" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" dependencies = [ "proc-macro2", "quote", @@ -2366,9 +2367,9 @@ dependencies = [ [[package]] name = "unicode-width" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" [[package]] name = "url" diff --git a/src/divanalysis/main.rs b/src/divanalysis/main.rs index 2433d3c..1ec2dc2 100644 --- a/src/divanalysis/main.rs +++ b/src/divanalysis/main.rs @@ -3,7 +3,8 @@ use clap::Parser; use polars::prelude::*; // TODO: make an export of POLARS_MAX_FMT_COLS -// TODO: filter out special dividends (SC) +// TODO: fix all companies list +// TODO: make downloading all companies data // TODO: Fix crash "No dividend data" to be replaced with NULL/None // TODO: handle companies that do not pay dividends // TODO: Get polygon companies list (multiple pages) (next_url + api key reqwest has to be done) @@ -205,7 +206,7 @@ fn main() -> Result<(), &'static str> { let companies = investments_forecasting::get_polygon_companies_list()?; let mut symbols: Vec = vec![]; - let mut names: Vec = vec![]; + let mut names: Vec> = vec![]; companies.into_iter().for_each(|(s, n)| { symbols.push(s); @@ -219,29 +220,48 @@ fn main() -> Result<(), &'static str> { } } } else { - let data_shortlisted_dy = analyze_div_yield( - &data.expect("Error: unable to extract XLSX data"), - args.sp500_divy, - args.inflation, - args.min_div_yield, - args.max_div_yield, - )?; - log::info!("Champions Shortlisted by DivY: {}", data_shortlisted_dy); - - let data_shortlisted_dy_dp = analyze_dividend_payout_rate( - &data_shortlisted_dy, - args.max_div_payout_rate / 100.0, - )?; - - log::info!( - "Champions Shortlisted by DivY and Div Pay-Out: {}", - data_shortlisted_dy_dp - ); - - let data_shortlisted_dy_dp_dg = - analyze_div_growth(&data_shortlisted_dy_dp, args.min_div_growth_rate)?; - - print_summary(&data_shortlisted_dy_dp_dg, None)?; + match data { + Some(data) => { + + let data_shortlisted_dy = analyze_div_yield( + &data, + args.sp500_divy, + args.inflation, + args.min_div_yield, + args.max_div_yield, + )?; + log::info!("Champions Shortlisted by DivY: {}", data_shortlisted_dy); + + let data_shortlisted_dy_dp = analyze_dividend_payout_rate( + &data_shortlisted_dy, + args.max_div_payout_rate / 100.0, + )?; + + log::info!( + "Champions Shortlisted by DivY and Div Pay-Out: {}", + data_shortlisted_dy_dp + ); + + let data_shortlisted_dy_dp_dg = + analyze_div_growth(&data_shortlisted_dy_dp, args.min_div_growth_rate)?; + + print_summary(&data_shortlisted_dy_dp_dg, None)?; + }, + None => { + + let companies = investments_forecasting::get_polygon_companies_list()?; + + let mut symbols: Vec = vec![]; + + companies.into_iter().for_each(|(s,_)| { + symbols.push(s); + }); + + + + + }, + } } } else { match data { @@ -251,6 +271,10 @@ fn main() -> Result<(), &'static str> { .try_for_each(|symbol| print_summary(&data, Some(&symbol)))?; } None => { + + // let (symbols, share_prices, curr_divs, divys, freqs, dgrs, years_growth, + // payout_ratios, sectors) = get_polygon_companies_data(&companies)?; + let mut symbols: Vec<&str> = vec![]; let mut share_prices: Vec = vec![]; let mut curr_divs: Vec = vec![]; diff --git a/src/lib.rs b/src/lib.rs index ef4ea46..0f4c112 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -195,9 +195,10 @@ fn should_try_again(maybe_resp: Result, dummy: T) -> (T, b } } -pub fn get_polygon_companies_list() -> Result, &'static str> { +pub fn get_polygon_companies_list() -> Result)>, &'static str> { let mut query_params = HashMap::new(); query_params.insert("active", "true"); + query_params.insert("market", "stocks"); let client = RESTClient::new(None, None); // Get all dividend data we can have @@ -223,17 +224,17 @@ pub fn get_polygon_companies_list() -> Result, &'static st let tickers_results_to_vec = |results: &Vec| { - let mut companies: Vec<(String, String)> = results + let mut companies: Vec<(String, Option)> = results .iter() .map(|x| { - log::info!("{}: name: {}, type: {}", x.ticker, x.name, x.market); + log::info!("{}: name: {:?}", x.ticker, x.name); (x.ticker.clone(), x.name.clone()) }) .collect(); companies }; - let mut companies: Vec<(String, String)> = tickers_results_to_vec(&resp.results); + let mut companies: Vec<(String, Option)> = tickers_results_to_vec(&resp.results); while resp.next_url.clone().is_some() { if let Some(url) = &resp.next_url.clone() { @@ -248,7 +249,7 @@ pub fn get_polygon_companies_list() -> Result, &'static st } } - return Ok::, &'static str>(companies); + return Ok::)>, &'static str>(companies); }) }