Skip to content

Commit

Permalink
some optional field
Browse files Browse the repository at this point in the history
  • Loading branch information
jczaja committed May 3, 2024
1 parent 476f839 commit d020681
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 69 deletions.
79 changes: 40 additions & 39 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 49 additions & 25 deletions src/divanalysis/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -205,7 +206,7 @@ fn main() -> Result<(), &'static str> {
let companies = investments_forecasting::get_polygon_companies_list()?;

let mut symbols: Vec<String> = vec![];
let mut names: Vec<String> = vec![];
let mut names: Vec<Option<String>> = vec![];

companies.into_iter().for_each(|(s, n)| {
symbols.push(s);
Expand All @@ -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<String> = vec![];

companies.into_iter().for_each(|(s,_)| {
symbols.push(s);
});




},
}
}
} else {
match data {
Expand All @@ -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<f64> = vec![];
let mut curr_divs: Vec<f64> = vec![];
Expand Down
11 changes: 6 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,10 @@ fn should_try_again<T>(maybe_resp: Result<T, reqwest::Error>, dummy: T) -> (T, b
}
}

pub fn get_polygon_companies_list() -> Result<Vec<(String, String)>, &'static str> {
pub fn get_polygon_companies_list() -> Result<Vec<(String, Option<String>)>, &'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
Expand All @@ -223,17 +224,17 @@ pub fn get_polygon_companies_list() -> Result<Vec<(String, String)>, &'static st

let tickers_results_to_vec =
|results: &Vec<polygon_client::types::ReferenceTickersResponseTickerV3>| {
let mut companies: Vec<(String, String)> = results
let mut companies: Vec<(String, Option<String>)> = 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<String>)> = tickers_results_to_vec(&resp.results);

while resp.next_url.clone().is_some() {
if let Some(url) = &resp.next_url.clone() {
Expand All @@ -248,7 +249,7 @@ pub fn get_polygon_companies_list() -> Result<Vec<(String, String)>, &'static st
}
}

return Ok::<Vec<(String, String)>, &'static str>(companies);
return Ok::<Vec<(String, Option<String>)>, &'static str>(companies);
})
}

Expand Down

0 comments on commit d020681

Please sign in to comment.