Skip to content

Commit

Permalink
Fix of expected coupons sum in bonds table + filter bonds that can be
Browse files Browse the repository at this point in the history
bought + emitters updated
  • Loading branch information
Shemplo committed Sep 16, 2022
1 parent 05c722e commit 406929c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Binary file modified emitters.bin
Binary file not shown.
6 changes: 5 additions & 1 deletion src/main/java/ru/shemplo/tbs/TBSBondManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ public void initialize (IProfile profile, TBSLogWrapper log) {
try {
log.info ("Loading data about bonds from Tinkoff and MOEX...");
scanned = client.getInstrumentsService ().getAllBondsSync ().stream ()
. filter (instrument -> profile.getCurrencies ().contains (Currency.from (instrument.getCurrency ()))).parallel ()
. filter (instrument ->
instrument.getApiTradeAvailableFlag ()
&& instrument.getBuyAvailableFlag ()
&& profile.getCurrencies ().contains (Currency.from (instrument.getCurrency ()))
).parallel ()
. map (instr -> new Bond (profile, instr, false)).peek (bond -> emitters.addEmitter (bond.getEmitterId (), bond.getCode ()))
. filter (profile::testBond)//.limit (profile.getMaxResults ())
. collect (Collectors.toList ());
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/ru/shemplo/tbs/entity/Bond.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ public void updateScore (IProfile profile) {
final var days = now.until (end, ChronoUnit.DAYS);

reliableCoupons = coupons.stream ().map (Coupon::isReliable).reduce (Boolean::logicalAnd).orElse (true);
couponsCredit = coupons.stream ().mapToDouble (c -> c.getCredit (profile, now, end)).sum ();
couponsCredit = coupons.stream ()
. filter (c -> !now.isAfter (TBSUtils.aOrB (c.getRecord (), c.getDate ()))) // consider only coupons that can be payed after now
. mapToDouble (c -> c.getCredit (profile, now, end))
. sum ();

final var inflationFactor = Math.pow (1 + profile.getInflation (), days / 365.0);
nominalValueWithInflation = nominalValue / inflationFactor;
Expand Down

0 comments on commit 406929c

Please sign in to comment.