feat: 一些细小的调整
This commit is contained in:
@@ -1,26 +1,26 @@
|
||||
package com.lanyuanxiaoyao.leopard.strategy;
|
||||
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.Daily;
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.Daily_;
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.QDaily;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.BalanceSheet;
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.CashFlow;
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.Income;
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.QBalanceSheet;
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.QCashFlow;
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.QIncome;
|
||||
import com.lanyuanxiaoyao.leopard.core.repository.BalanceSheetRepository;
|
||||
import com.lanyuanxiaoyao.leopard.core.repository.CashFlowRepository;
|
||||
import com.lanyuanxiaoyao.leopard.core.repository.DailyRepository;
|
||||
import com.lanyuanxiaoyao.leopard.core.repository.IncomeRepository;
|
||||
import com.lanyuanxiaoyao.leopard.core.repository.StockRepository;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.transaction.Transactional;
|
||||
import java.time.Duration;
|
||||
import java.time.ZoneId;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
||||
import org.ta4j.core.BaseBar;
|
||||
import org.ta4j.core.BaseBarSeriesBuilder;
|
||||
import org.ta4j.core.indicators.EMAIndicator;
|
||||
import org.ta4j.core.indicators.helpers.ClosePriceIndicator;
|
||||
import org.ta4j.core.num.DoubleNum;
|
||||
|
||||
@Slf4j
|
||||
@SpringBootApplication(scanBasePackages = "com.lanyuanxiaoyao.leopard")
|
||||
@@ -30,6 +30,12 @@ public class StrategyApplication {
|
||||
private StockRepository stockRepository;
|
||||
@Resource
|
||||
private DailyRepository dailyRepository;
|
||||
@Resource
|
||||
private BalanceSheetRepository balanceSheetRepository;
|
||||
@Resource
|
||||
private IncomeRepository incomeRepository;
|
||||
@Resource
|
||||
private CashFlowRepository cashFlowRepository;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(StrategyApplication.class, args);
|
||||
@@ -38,32 +44,76 @@ public class StrategyApplication {
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void test() {
|
||||
var dailies = dailyRepository.findAll(QDaily.daily.stock.code.eq("000001.SZ"), Sort.by(Daily_.TRADE_DATE));
|
||||
var series = new BaseBarSeriesBuilder()
|
||||
.withNumTypeOf(DoubleNum.class)
|
||||
.build();
|
||||
log.info("{}", dailies.size());
|
||||
for (Daily daily : dailies) {
|
||||
series.addBar(new BaseBar(
|
||||
Duration.ofDays(1),
|
||||
daily.getTradeDate().plusDays(1).atStartOfDay(ZoneId.systemDefault()),
|
||||
DoubleNum.valueOf(daily.getOpen() * daily.getFactor()),
|
||||
DoubleNum.valueOf(daily.getHigh() * daily.getFactor()),
|
||||
DoubleNum.valueOf(daily.getLow() * daily.getFactor()),
|
||||
DoubleNum.valueOf(daily.getClose() * daily.getFactor()),
|
||||
DoubleNum.valueOf(daily.getVolume()),
|
||||
DoubleNum.valueOf(daily.getPriceChangeAmount()),
|
||||
daily.getTurnover().longValue()
|
||||
));
|
||||
var code = "000799.SZ";
|
||||
for (int year = 2019; year <= 2019; year++) {
|
||||
var balance = balanceSheetRepository.findOne(
|
||||
QBalanceSheet.balanceSheet.stock.code.eq(code)
|
||||
.and(QBalanceSheet.balanceSheet.year.eq(year))
|
||||
).orElseThrow();
|
||||
var income = incomeRepository.findOne(
|
||||
QIncome.income.stock.code.eq(code)
|
||||
.and(QIncome.income.year.eq(year))
|
||||
).orElseThrow();
|
||||
var cashflow = cashFlowRepository.findOne(
|
||||
QCashFlow.cashFlow.stock.code.eq(code)
|
||||
.and(QCashFlow.cashFlow.year.eq(year))
|
||||
).orElseThrow();
|
||||
log.info("{} {}", year, calculateFinanceIndicator(balance, income, cashflow));
|
||||
}
|
||||
var ema = new EMAIndicator(new ClosePriceIndicator(series), 5);
|
||||
var emaValues = ema.stream().toList();
|
||||
log.info("{}", emaValues.size());
|
||||
}
|
||||
|
||||
for (int index = 0; index < dailies.size(); index++) {
|
||||
var daily = dailies.get(index);
|
||||
var emaValue = emaValues.get(index);
|
||||
log.info("{} {} {} {} {}", daily.getTradeDate().toString(), daily.getClose(), daily.getFactor(), daily.getClose() * daily.getFactor(), emaValue.doubleValue());
|
||||
private FinanceIndicator calculateFinanceIndicator(BalanceSheet balance, Income income, CashFlow cashflow) {
|
||||
return new FinanceIndicator(
|
||||
safeDiv(balance.getTotalLiabilities(), balance.getTotalAssets()),
|
||||
safeDiv(balance.getTotalAssets(), balance.getTotalNonCurrentAssets()),
|
||||
safeDiv(balance.getTotalCurrentAssets(), balance.getTotalCurrentLiabilities()),
|
||||
safeDiv(safeMinus(balance.getTotalCurrentAssets(), balance.getInventories()), balance.getTotalCurrentLiabilities()),
|
||||
safeDiv(income.getOperatingRevenue(), balance.getNotesAndAccountsReceivable()),
|
||||
safeDiv(360.0, safeDiv(income.getOperatingRevenue(), balance.getNotesAndAccountsReceivable())),
|
||||
safeDiv(income.getTotalOperatingCost(), balance.getInventories())
|
||||
);
|
||||
}
|
||||
|
||||
private Double safePlus(Double a, Double b) {
|
||||
if (ObjectUtil.isNull(a) || ObjectUtil.isNull(b)) {
|
||||
return null;
|
||||
}
|
||||
return a + b;
|
||||
}
|
||||
|
||||
private Double safeMinus(Double a, Double b) {
|
||||
if (ObjectUtil.isNull(a) || ObjectUtil.isNull(b)) {
|
||||
return null;
|
||||
}
|
||||
return a - b;
|
||||
}
|
||||
|
||||
private Double safeDiv(Double a, Double b) {
|
||||
if (ObjectUtil.isNull(a) || ObjectUtil.isNull(b) || b == 0) {
|
||||
return null;
|
||||
}
|
||||
return NumberUtil.div(a, b, 4);
|
||||
}
|
||||
|
||||
public record FinanceIndicator(
|
||||
Double debtToAssetRatio,
|
||||
Double longTermFundsToRealEstateRatio,
|
||||
Double currentRatio,
|
||||
Double quickRatio,
|
||||
Double accountsReceivableTurnoverRate,
|
||||
Double averageCashCollectionDays,
|
||||
Double inventoryTurnoverRate
|
||||
) {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "负债占资产比率=" + debtToAssetRatio +
|
||||
", 长期资金占固定资产比率=" + longTermFundsToRealEstateRatio +
|
||||
", 流动比率=" + currentRatio +
|
||||
", 速动比率=" + quickRatio +
|
||||
", 应收账款周转率=" + accountsReceivableTurnoverRate +
|
||||
", 平均现金回收天数=" + averageCashCollectionDays +
|
||||
", 库存周转率=" + inventoryTurnoverRate +
|
||||
';';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,13 @@ spring:
|
||||
application:
|
||||
name: leopard-strategy
|
||||
datasource:
|
||||
url: jdbc:postgresql://192.168.31.127:6785/leopard
|
||||
url: jdbc:postgresql://81.71.3.24:6785/leopard_dev
|
||||
username: leopard
|
||||
password: '9NEzFzovnddf@PyEP?e*AYAWnCyd7UhYwQK$pJf>7?ccFiN^x4$eKEZ5~E<7<+~X'
|
||||
driver-class-name: org.postgresql.Driver
|
||||
jpa:
|
||||
generate-ddl: false
|
||||
main:
|
||||
banner-mode: off
|
||||
fenix:
|
||||
print-banner: false
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<logger name="com.zaxxer.hikari" level="ERROR"/>
|
||||
<logger name="com.lanyuanxiaoyao.leopard" level="INFO"/>
|
||||
<logger name="org.hibernate.SQL" level="DEBUG"/>
|
||||
|
||||
<root level="INFO">
|
||||
<root level="ERROR">
|
||||
<appender-ref ref="Console"/>
|
||||
</root>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user