Skip to content

Commit 6648c38

Browse files
committed
- Added yahoo api based divanalysis and divforcasting
1 parent 74a9909 commit 6648c38

4 files changed

Lines changed: 294 additions & 33 deletions

File tree

src/divanalysis/main.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,7 @@ fn configure_dataframes_format() {
201201
}
202202
}
203203

204-
fn get_polygon_companies_data(
205-
companies: &[String],
206-
database: Option<String>,
207-
) -> Result<(), &'static str> {
204+
fn get_companies_data(companies: &[String], database: Option<String>) -> Result<(), &'static str> {
208205
let mut symbols: Vec<&str> = vec![];
209206
let mut share_prices: Vec<f64> = vec![];
210207
let mut curr_divs: Vec<Option<f64>> = vec![];
@@ -286,7 +283,13 @@ fn get_polygon_companies_data(
286283
years_of_growth,
287284
payout_ratio,
288285
sector_desc,
289-
) = investments_forecasting::get_polygon_data(&symbol)?;
286+
) = if std::env::var("POLYGON_AUTH_KEY").is_ok() {
287+
investments_forecasting::get_polygon_data(symbol)
288+
.expect("Error: unable to get Data from polygon IO for forecasting")
289+
} else {
290+
investments_forecasting::get_yahoo_data(symbol)
291+
.expect("Error: unable to get Data from yahoo finance for forecasting")
292+
};
290293

291294
share_prices.push(share_price);
292295
curr_divs.push(curr_div);
@@ -482,7 +485,7 @@ fn main() -> Result<(), &'static str> {
482485
companies.into_iter().for_each(|(s, _)| {
483486
symbols.push(s);
484487
});
485-
get_polygon_companies_data(&symbols, args.database)?;
488+
get_companies_data(&symbols, args.database)?;
486489
}
487490
}
488491
}
@@ -515,7 +518,7 @@ fn main() -> Result<(), &'static str> {
515518
} else {
516519
companies
517520
};
518-
get_polygon_companies_data(&companies, args.database)?;
521+
get_companies_data(&companies, args.database)?;
519522
}
520523
}
521524
}

src/divforecasting/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,12 @@ fn forecast_dividend_stocks(
338338
(price, dy, dyg)
339339
}
340340
None => {
341-
342341
let (share_price, _, divy, frequency, dgr, _,_,_,_,_, _, _) =
343-
investments_forecasting::get_polygon_data(&name).expect("Error: unable to get Data from polygon IO for forecasting");
342+
if std::env::var("POLYGON_AUTH_KEY").is_ok() {
343+
investments_forecasting::get_polygon_data(&name).expect("Error: unable to get Data from polygon IO for forecasting")
344+
} else {
345+
investments_forecasting::get_yahoo_data(&name).expect("Error: unable to get Data from yahoo finance for forecasting")
346+
};
344347
num_capitalizations = frequency.expect("Cannot forecast dividend gains as there is no dividend data") as u32;
345348
let divy = divy.expect("Cannot forecast dividend gains as there is no dividend data");
346349
let dgr = dgr.expect("Cannot forecast dividend gains as there is no dividend data");

src/divportfolio/main.rs

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -431,23 +431,29 @@ fn main() -> Result<(), String> {
431431
//Stock::new("ABEV", Currency::USD(121+11.91), Currency::USD(240.84), 0.0789),
432432
get_data(
433433
"ABEV",
434-
Currency::USD(121.0 + 11.20 + 80.0 + 1.91),
435-
82.09,
434+
Currency::USD(1210.0 + 11.20 + 800.0 + 11.91),
435+
827.09,
436436
None,
437437
)
438438
.unwrap(),
439439
get_data(
440440
"BBY",
441-
Currency::USD(1000.0 + 92.0 + 93.62 + 94.73),
442-
11.63,
441+
Currency::USD(10000.0 + 92.0 + 93.62 + 94.73),
442+
118.63,
443443
None,
444444
)
445445
.unwrap(),
446-
get_data("GOOGL", Currency::USD(58.68 + 60.0), 0.81, None).unwrap(),
447-
get_data("GSL", Currency::USD(276.0 + 44.36 + 2.92), 7.19, None).unwrap(),
448-
get_data("KO", Currency::USD(23.06 + 70.0 + 5.88 + 5.92), 1.75, None).unwrap(),
449-
get_data("LX", Currency::USD(3.49 + 9.72), 1.9, None).unwrap(),
450-
get_data("SM", Currency::USD(27.74), 2.0, None).unwrap(),
446+
get_data("GOOGL", Currency::USD(58.68 + 600.0), 3.81, None).unwrap(),
447+
get_data("GSL", Currency::USD(2760.0 + 44.36 + 2.92), 72.19, None).unwrap(),
448+
get_data(
449+
"KO",
450+
Currency::USD(263.06 + 700.0 + 5.88 + 5.92),
451+
13.75,
452+
None,
453+
)
454+
.unwrap(),
455+
get_data("LX", Currency::USD(30.49 + 29.72), 19.9, None).unwrap(),
456+
get_data("SM", Currency::USD(272.74), 12.0, None).unwrap(),
451457
get_data(
452458
"TGT",
453459
Currency::USD(26.9 + 744.63 + 2.0 + 8.78 + 1.0 + 8.88),
@@ -456,37 +462,37 @@ fn main() -> Result<(), String> {
456462
)
457463
.unwrap(),
458464
//Stock::new("VZ", Currency::USD(19.85), Currency::USD(24.98), 0.0671),
459-
get_data("VZ", Currency::USD(19.85), 0.49, None).unwrap(),
465+
get_data("VZ", Currency::USD(19.85 + 6.19), 0.61, None).unwrap(),
460466
];
461467

462468
print_data_frame(&ania);
463469

464470
let jacek = vec![
465471
get_data("AHOG.DE", Currency::EUR(5980.74), 179.11, None).unwrap(),
466-
get_data("BMO", Currency::USD(2100.0), 28.23, None).unwrap(),
467-
get_data("CNQ", Currency::USD(300.0 + 298.51), 138.65, None).unwrap(),
468-
get_data("CVX", Currency::USD(100.0), 6.43, None).unwrap(),
469-
get_data("EIX", Currency::USD(200.0), 6.23, None).unwrap(),
472+
get_data("BMO", Currency::USD(21500.0), 228.23, None).unwrap(),
473+
get_data("CNQ", Currency::USD(3000.0 + 2298.51), 138.65, None).unwrap(),
474+
get_data("CVX", Currency::USD(1000.0), 6.43, None).unwrap(),
475+
get_data("EIX", Currency::USD(2000.0), 36.23, None).unwrap(),
470476
get_data(
471477
"EPR",
472-
Currency::USD(500.0 + 500.0 + 987.80 + 496.86 + 5150.48 + 100.0 + 100.0 + 5340.12),
473-
79.24,
478+
Currency::USD(500.0 + 500.0 + 987.80 + 496.86 + 5150.48 + 10000.0 + 10000.0 + 5340.12),
479+
798.24,
474480
None,
475481
)
476482
.unwrap(),
477-
get_data("NVS", Currency::USD(201.0), 1.89, None).unwrap(),
478-
get_data("O", Currency::USD(336.99), 5.2, None).unwrap(),
479-
get_data("SNY", Currency::USD(200.0), 4.02, None).unwrap(),
480-
get_data("TW10.F", Currency::EUR(200.66 + 52.0), 12.02, None).unwrap(),
481-
get_data("TRN.MI", Currency::EUR(92.29), 18.86, None).unwrap(),
483+
get_data("NVS", Currency::USD(2001.0), 13.89, None).unwrap(),
484+
get_data("O", Currency::USD(3306.99 + 2674.66), 94.05, None).unwrap(),
485+
get_data("SNY", Currency::USD(2000.0), 44.02, None).unwrap(),
486+
get_data("TW10.F", Currency::EUR(2010.66 + 52.0), 132.02, None).unwrap(),
487+
get_data("TRN.MI", Currency::EUR(921.29), 108.86, None).unwrap(),
482488
get_data(
483489
"UPS",
484-
Currency::USD(1999.99 + 200.0 + 1000.0 + 1000.0),
485-
15.02,
490+
Currency::USD(19999.99 + 200.0 + 1000.0 + 1000.0),
491+
157.02,
486492
None,
487493
)
488494
.unwrap(),
489-
get_data("VVD.DE", Currency::EUR(569.23), 15.77, None).unwrap(),
495+
get_data("VVD.DE", Currency::EUR(5669.23 + 2323.69), 230.02, None).unwrap(),
490496
// Stock::new("DE000A289XJ2",Currency::USD(2594.37), Currency::EUR(2627.66), 0.0501),
491497
];
492498
print_data_frame(&jacek);

0 commit comments

Comments
 (0)