Skip to content

Commit 9f9af90

Browse files
committed
Merge branch 'master' of git@github.com:Shemplo/TBS.git
2 parents 2ae8f9d + e2e736c commit 9f9af90

File tree

12 files changed

+148
-41
lines changed

12 files changed

+148
-41
lines changed

.github/workflows/github-actions.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
with:
1111
java-version: '17'
1212
- name: Build with Maven
13-
run: mvn -B package -P linux --file pom.xml
13+
run: mvn package
1414
- name: Get job's artifacts
1515
uses: actions/upload-artifact@v2
1616
with:
@@ -26,7 +26,7 @@ jobs:
2626
with:
2727
java-version: '17'
2828
- name: Build with Maven
29-
run: mvn -B package -P mac --file pom.xml
29+
run: mvn package
3030
- name: Get job's artifacts
3131
uses: actions/upload-artifact@v2
3232
with:
@@ -42,7 +42,7 @@ jobs:
4242
with:
4343
java-version: '17'
4444
- name: Build with Maven
45-
run: mvn -B package -P win --file pom.xml
45+
run: mvn package
4646
- name: Get job's artifacts
4747
uses: actions/upload-artifact@v2
4848
with:
@@ -51,6 +51,7 @@ jobs:
5151
Release:
5252
runs-on: ubuntu-latest
5353
needs: [Linux-Artifact, Mac-Artifact, Windows-Artifact]
54+
if: startsWith(github.ref, 'refs/tags/')
5455
steps:
5556
- name: Download Linux artifact
5657
uses: actions/download-artifact@v2
@@ -78,7 +79,6 @@ jobs:
7879

7980
- name: Release
8081
uses: softprops/action-gh-release@v1
81-
if: startsWith(github.ref, 'refs/tags/')
8282
with:
8383
draft: true
8484
files: |

pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,26 @@
2020
<profile>
2121
<id>win</id>
2222
<activation>
23-
<activeByDefault>true</activeByDefault>
23+
<os><family>windows</family></os>
2424
</activation>
2525
<properties>
2626
<javafx.platform>win</javafx.platform>
2727
</properties>
2828
</profile>
2929
<profile>
3030
<id>linux</id>
31+
<activation>
32+
<os><family>unix</family></os>
33+
</activation>
3134
<properties>
3235
<javafx.platform>linux</javafx.platform>
3336
</properties>
3437
</profile>
3538
<profile>
3639
<id>mac</id>
40+
<activation>
41+
<os><family>mac</family></os>
42+
</activation>
3743
<properties>
3844
<javafx.platform>mac</javafx.platform>
3945
</properties>

src/main/java/ru/shemplo/tbs/TBSBondManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ public static Double getBondPrice (String ticker) {
7575
return TBSUtils.map2IfNN (ticker, t -> getBondByTicker (t, false), Bond::getLastPrice, null);
7676
}
7777

78+
public static Double getBondAccCouponIncome (String ticker) {
79+
return TBSUtils.map2IfNN (ticker, t -> getBondByTicker (t, false), Bond::getAccCouponIncome, null);
80+
}
81+
7882
public static Currency getBondCurrency (String ticker) {
7983
return TBSUtils.map2IfNN (ticker, t -> getBondByTicker (t, false), Bond::getCurrency, null);
8084
}

src/main/java/ru/shemplo/tbs/TBSPlanner.java

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static void restore () {
5555
);
5656
} else {
5757
getInstance ().updateDistributionParameters (
58-
DistributionCategory.SUM, 0.0, 0.0
58+
DistributionCategory.SUM, 0.0, 0.0, 0.02
5959
);
6060
}
6161
}
@@ -65,7 +65,10 @@ public static void restore () {
6565
private transient Map <String, IPlanningBond> ticker2bond = new HashMap <> ();
6666

6767
@Getter
68-
private transient SimpleDoubleProperty summaryPrice = new SimpleDoubleProperty (0.0);
68+
private transient SimpleDoubleProperty summaryRecommendedPrice = new SimpleDoubleProperty (0.0);
69+
70+
@Getter
71+
private transient SimpleDoubleProperty summaryRealPrice = new SimpleDoubleProperty (0.0);
6972

7073
@Getter
7174
private transient Property <Number> summaryLots = new SimpleIntegerProperty (0);
@@ -79,6 +82,9 @@ public static void restore () {
7982
@Getter
8083
private long analyzeDays = 7L;
8184

85+
@Getter
86+
private double commission = 0.02;
87+
8288
public synchronized void addBond (String ticker) {
8389
if (ticker != null && !hasBond (ticker)) {
8490
final var bond = new PlanningBond (ticker).getProxy ();
@@ -129,8 +135,10 @@ private void updateIndices () {
129135
}
130136
}
131137

132-
public void updateDistributionParameters (DistributionCategory category, double amount, double diversification) {
133-
this.category = category; this.amount = amount; this.diversification = diversification;
138+
public void updateDistributionParameters (DistributionCategory category, double amount, double diversification, double commission) {
139+
this.category = category; this.amount = amount;
140+
this.diversification = diversification;
141+
this.commission = commission;
134142
updateDistribution ();
135143
dump ();
136144

@@ -147,32 +155,41 @@ public void updateDistribution () {
147155
sum += Math.max (0.0, linearValue (i, k, b));
148156
}
149157

150-
if (sum != 0.0) {
151-
double totalPrice = 0.0;
158+
final var commissionFactor = 1.0 - commission / 100.0;
159+
if (sum != 0.0 && commissionFactor != 0.0) {
160+
final var amount = this.amount * commissionFactor;
161+
162+
double totalRecommendedPrice = 0.0;
163+
double totalRealPrice = 0.0;
152164
int totalLots = 0;
153165

154166
for (int i = 0; i < b; i++) {
155167
final var bond = bonds.get (i);
156168

157169
final var factor = Math.max (0.0, linearValue (i, k, b)) / sum;
158-
final var price = bond.getRUBPrice ();
170+
final var accCouponIncome = bond.getAccCouponIncome ();
171+
172+
final var recommendedPrice = bond.getRUBPrice (false) + accCouponIncome;
173+
final var realPrice = bond.getRUBPrice (true) + accCouponIncome;
159174

160175
if (category == DistributionCategory.LOTS) {
161176
bond.setAmount ((int) (factor * amount));
162177
bond.updateCalculatedAmount (factor * amount);
163-
} else if (category == DistributionCategory.SUM && price != 0.0) {
164-
bond.setAmount ((int) Math.round (factor * amount / price));
165-
bond.updateCalculatedAmount (factor * amount / price);
178+
} else if (category == DistributionCategory.SUM && realPrice != 0.0) {
179+
bond.setAmount ((int) Math.round (factor * amount / realPrice));
180+
bond.updateCalculatedAmount (factor * amount / realPrice);
166181
} else {
167182
bond.updateCalculatedAmount (0.0);
168183
bond.setAmount (0);
169184
}
170185

171-
totalPrice += price * bond.getCurrentValue ();
186+
totalRecommendedPrice += (recommendedPrice * bond.getCurrentValue ()) * (1.0 + commission / 100.0);
187+
totalRealPrice += realPrice * bond.getCurrentValue () * (1.0 + commission / 100.0);
172188
totalLots += bond.getCurrentValue ();
173189
}
174190

175-
summaryPrice.setValue (totalPrice);
191+
summaryRecommendedPrice.setValue (totalRecommendedPrice);
192+
summaryRealPrice.setValue (totalRealPrice);
176193
summaryLots.setValue (totalLots);
177194
}
178195
}
@@ -202,7 +219,8 @@ private void readObject (ObjectInputStream in) throws IOException, ClassNotFound
202219
in.defaultReadObject ();
203220
instance = this;
204221

205-
summaryPrice = new SimpleDoubleProperty (0.0);
222+
summaryRecommendedPrice = new SimpleDoubleProperty (0.0);
223+
summaryRealPrice = new SimpleDoubleProperty (0.0);
206224
summaryLots = new SimpleIntegerProperty (0);
207225

208226
bonds = FXCollections.observableArrayList ();

src/main/java/ru/shemplo/tbs/entity/Bond.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import lombok.ToString;
1717
import ru.shemplo.tbs.TBSCurrencyManager;
1818
import ru.shemplo.tbs.TBSEmitterManager;
19+
import ru.shemplo.tbs.TBSUtils;
1920
import ru.shemplo.tbs.moex.MOEXRequests;
2021
import ru.shemplo.tbs.moex.MOEXResposeReader;
2122
import ru.shemplo.tbs.moex.xml.Data;
@@ -42,7 +43,7 @@ public class Bond extends AbstractObservableEntity <IBond> implements IBond {
4243

4344
private long emitterId;
4445

45-
private double nominalValue, percentage, lastPrice;
46+
private double nominalValue, percentage, lastPrice, accCouponIncome;
4647

4748
private NavigableSet <LocalDate> offers = new TreeSet <> ();
4849
private List <Coupon> coupons = new ArrayList <> ();
@@ -116,10 +117,13 @@ private Bond (String ticker, String figi, Currency currency, LocalDate scoreNow,
116117
if (MOEX_PRICE_URL != null) {
117118
final var MOEXPrice = MOEXResposeReader.read (MOEX_PRICE_URL);
118119
MOEXPrice.getMarketData ().map (Data::getRows).ifPresent (price -> {
119-
final var lastValue = price.getRows () == null || price.getRows ().isEmpty () ? ""
120-
: price.getRows ().get (0).getPrice ();
120+
final var lastValue = TBSUtils.mapIfNN (price.getFirstRow (), Row::getPrice, "");
121121
lastPrice = lastValue.isBlank () ? 1e+9 : (Double.parseDouble (lastValue) * nominalValue / 100.0);
122122
});
123+
MOEXPrice.getSecuritiesData ().map (Data::getRows).ifPresent (securities -> {
124+
final var accCouponIncomeValue = TBSUtils.mapIfNN (securities.getFirstRow (), Row::getAccCouponIncome, "");
125+
accCouponIncome = accCouponIncomeValue.isBlank () ? 0.0 : Double.parseDouble (accCouponIncomeValue);
126+
});
123127
}
124128
}
125129

src/main/java/ru/shemplo/tbs/entity/IPlanningBond.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,24 @@ public interface IPlanningBond extends Serializable, CustomValueHolder <Integer>
1919

2020
void setRecommendedPrice (double price);
2121

22+
double getRecommendedPrice ();
23+
2224
default String getFIGI () {
23-
return TBSBondManager.getBondByTicker (getCode (), true).getFigi ();
25+
return TBSUtils.mapIfNN (TBSBondManager.getBondByTicker (getCode (), true), Bond::getFigi, null);
2426
}
2527

2628
default double getPrice () {
2729
return TBSUtils.aOrB (TBSBondManager.getBondPrice (getCode ()), 0.0);
2830
}
2931

30-
default double getRUBPrice () {
32+
default double getAccCouponIncome () {
33+
return TBSUtils.aOrB (TBSBondManager.getBondAccCouponIncome (getCode ()), 0.0);
34+
}
35+
36+
default double getRUBPrice (boolean real) {
3137
final var currency = TBSBondManager.getBondCurrency (getCode ());
3238
final var cur2rub = TBSCurrencyManager.getInstance ().getToRubCoefficient (currency);
33-
return TBSUtils.mapIfNN (getPrice (), p -> p * cur2rub, 0.0);
39+
return TBSUtils.mapIfNN (real ? getPrice () : getRecommendedPrice (), p -> p * cur2rub, 0.0);
3440
}
3541

3642
default double getCalculatedAmount () {

src/main/java/ru/shemplo/tbs/gfx/TBSBondsTable.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ private Parent makeTable (TBSTableType type) {
130130
.highlighter (null).converter (null)
131131
.build ());
132132
}
133+
table.getColumns ().add (TBSUIUtils.<IBond, Number> buildTBSTableColumn ()
134+
.name ("ACI").tooltip ("Accumulated coupon income")
135+
.alignment (Pos.BASELINE_LEFT).minWidth (50.0).sortable (false)
136+
.propertyFetcher (bond -> bond.getRWProperty ("accCouponIncome", null))
137+
.highlighter (null).converter (null)
138+
.build ());
133139
table.getColumns ().add (TBSUIUtils.<IBond, Number> buildTBSTableColumn ()
134140
.name ("Nominal").tooltip (null)
135141
.alignment (Pos.BASELINE_LEFT).minWidth (80.0).sortable (false)

0 commit comments

Comments
 (0)