├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── src ├── test │ ├── java │ │ └── cn │ │ │ └── edu │ │ │ └── nju │ │ │ └── p │ │ │ ├── utils │ │ │ ├── Translate.java │ │ │ ├── ema │ │ │ │ ├── TestDate.java │ │ │ │ └── MACDUtilsTest.java │ │ │ ├── DateHelperTest.java │ │ │ ├── StockHelperTest.java │ │ │ ├── VacationDatesTest.java │ │ │ ├── DeleteCacheTest.java │ │ │ └── redis │ │ │ │ └── StockRedisDataUtilsTest.java │ │ │ ├── QuantradingApplicationTests.java │ │ │ ├── dao │ │ │ ├── MysqlHelperImplTest.java │ │ │ ├── AccountDaoTest.java │ │ │ ├── ClientDaoTest.java │ │ │ ├── StockDaoImplTest.java │ │ │ └── StockDaoTest.java │ │ │ └── serviceimpl │ │ │ ├── KLineServiceImplTest.java │ │ │ ├── ChooseBestDayServiceImplTest.java │ │ │ ├── MomentumServiceImplTest.java │ │ │ └── MeanReversionServiceImplTest.java │ └── resources │ │ └── application.properties └── main │ ├── java │ └── cn │ │ └── edu │ │ └── nju │ │ └── p │ │ ├── api │ │ └── StockDataOffered.java │ │ ├── cache │ │ ├── TokenManager.java │ │ ├── TokenManagerImpl.java │ │ └── RedisCache.java │ │ ├── utils │ │ ├── jackon │ │ │ └── CustomObjectMapper.java │ │ ├── DoubleUtils.java │ │ ├── beans │ │ │ └── ToolSpring.java │ │ ├── FileHelper.java │ │ ├── ProtoStuffSerializerUtil.java │ │ ├── EncryptHelper.java │ │ ├── DateHelper.java │ │ └── ema │ │ │ └── MACDUtils.java │ │ ├── dao │ │ ├── TestStockDao.java │ │ ├── StockDataTxtHelper.java │ │ ├── MarketPerformanceDao.java │ │ ├── daoutils │ │ │ ├── MysqlHelper.java │ │ │ ├── MysqlHelper_WY.java │ │ │ ├── GetDataFromYahooUtil.java │ │ │ ├── MysqlHelper_WYImpl.java │ │ │ ├── UpdateTodayStockRun.java │ │ │ ├── CSVUtil.java │ │ │ ├── UpdateMysqlDaily.java │ │ │ └── InsertTodayStockRun.java │ │ ├── CompanyDao.java │ │ ├── AccountDao.java │ │ ├── MyStockDao.java │ │ ├── ClientDao.java │ │ ├── StrategySquareDao.java │ │ ├── MyStrategyDao.java │ │ └── daoimpl │ │ │ ├── MarketPerformanceDaoImpl.java │ │ │ └── TestStockDaoImpl.java │ │ ├── exception │ │ ├── PasswordNotMatchException.java │ │ ├── SectorNotExistException.java │ │ ├── DateNotEnoughException.java │ │ ├── DateNotOrderedException.java │ │ ├── StockNotFoundException.java │ │ └── StockNoneException.java │ │ ├── annotation │ │ └── StockNotFoundCheck.java │ │ ├── service │ │ ├── strategy │ │ │ ├── MomentumService.java │ │ │ ├── MeanReversionService.java │ │ │ ├── SectorService.java │ │ │ └── ChooseBestDayService.java │ │ ├── exhibition │ │ │ ├── KLineService.java │ │ │ └── HomePageService.java │ │ └── personnel │ │ │ ├── MyStockService.java │ │ │ └── PersonnalInfoService.java │ │ ├── controller │ │ ├── swagger │ │ │ └── SwaggerRedirect.java │ │ ├── security │ │ │ ├── SignUpController.java │ │ │ └── LoginController.java │ │ ├── personnel │ │ │ ├── MyStockController.java │ │ │ ├── PersonnalInfoController.java │ │ │ └── MyStrategyController.java │ │ ├── stock │ │ │ ├── HomePageController.java │ │ │ └── StockController.java │ │ ├── strategysquare │ │ │ └── StrategySquareController.java │ │ ├── exhibition │ │ │ ├── CompanyController.java │ │ │ └── ExhibitionController.java │ │ └── selfstrategy │ │ │ └── CustomStrategyController.java │ │ ├── strategy │ │ ├── Strategy.java │ │ ├── customstrategy │ │ │ ├── javacompile │ │ │ │ ├── core │ │ │ │ │ ├── StringJavaFileObject.java │ │ │ │ │ └── RuntimeCompiler.java │ │ │ │ └── util │ │ │ │ │ └── RunCompileUtil.java │ │ │ └── RuntimeCompileTest.java │ │ ├── MomentumStrategyImpl.java │ │ ├── StrategyResultVO.java │ │ └── StrategyRunner.java │ │ ├── config │ │ ├── FilterConfig.java │ │ └── SwaggerConfig.java │ │ ├── po │ │ ├── UserPO.java │ │ ├── StrategyCodePO.java │ │ ├── AveragePO.java │ │ ├── SameMarketStockPO.java │ │ ├── SaveStrategyPO.java │ │ ├── ClientPO.java │ │ ├── StockMarketPO.java │ │ ├── KLinePO.java │ │ ├── StockComparedPO.java │ │ └── TestStockPO.java │ │ ├── enums │ │ └── ErrorCode.java │ │ ├── vo │ │ ├── AverageVO.java │ │ ├── BestDayResultVO.java │ │ ├── CompanyNewsVO.java │ │ ├── CompanyAnnouncementVO.java │ │ ├── KLineVO.java │ │ ├── StockVOWithSector.java │ │ ├── ClientVO.java │ │ ├── StockMarketVO.java │ │ ├── MeanReversionParamForBestDayVO.java │ │ ├── MomentumParamVO.java │ │ ├── MomentumVO.java │ │ ├── MeanReversionParamVO.java │ │ ├── MomentumResultVO.java │ │ ├── StockVO.java │ │ └── MeanReversionResultVO.java │ │ ├── serviceimpl │ │ ├── SectorServiceImpl.java │ │ ├── PersonnalInfoServiceImpl.java │ │ ├── MyStockServiceImpl.java │ │ ├── KLineServiceImpl.java │ │ └── HomePageServiceImpl.java │ │ ├── baseresult │ │ └── BaseResult.java │ │ ├── aop │ │ └── StockCodeValidationAop.java │ │ ├── QuantradingApplication.java │ │ ├── filter │ │ └── CorsFilter.java │ │ └── exceptionhandler │ │ └── GlobalExceptionHandler.java │ └── resources │ └── application.properties └── .gitignore /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DCRUNNN/QuantitiveTrading/HEAD/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/nju/p/utils/Translate.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.utils; 2 | 3 | /** 4 | * Created by Xihao on 2017/6/14. 5 | */ 6 | public class Translate { 7 | 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/api/StockDataOffered.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.api; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | /** 6 | * Created by Xihao on 2017/6/14. 7 | */ 8 | @Component 9 | public class StockDataOffered { 10 | 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/cache/TokenManager.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.cache; 2 | 3 | /** 4 | * token manager interface 5 | */ 6 | public interface TokenManager { 7 | 8 | String createToken(String phoneNumber); 9 | 10 | boolean checkToken(String token); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/utils/jackon/CustomObjectMapper.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.utils.jackon; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | 5 | /** 6 | * 自定义的json转换 7 | */ 8 | public class CustomObjectMapper extends ObjectMapper{ 9 | 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/dao/TestStockDao.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao; 2 | 3 | import cn.edu.nju.p.po.TestStockPO; 4 | 5 | /** 6 | * Created by dell- on 2017/6/8. 7 | */ 8 | public interface TestStockDao { 9 | 10 | public TestStockPO getTestStockPO(String code); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/exception/PasswordNotMatchException.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.exception; 2 | 3 | /** 4 | * Created by soft on 2017/5/17. 5 | */ 6 | public class PasswordNotMatchException extends RuntimeException { 7 | 8 | public PasswordNotMatchException(String message) { 9 | super(message); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/exception/SectorNotExistException.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.exception; 2 | 3 | /** 4 | * Created by xihao on 17-5-10. 5 | */ 6 | public class SectorNotExistException extends RuntimeException { 7 | 8 | public SectorNotExistException(String message) { 9 | 10 | super(message); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/exception/DateNotEnoughException.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.exception; 2 | 3 | /** 4 | * thrown when the given two date is too close 5 | */ 6 | public class DateNotEnoughException extends Exception { 7 | 8 | public DateNotEnoughException(String message) { 9 | 10 | super(message); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/exception/DateNotOrderedException.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.exception; 2 | 3 | /** 4 | * when date not ordered ,sys throws this exception 5 | */ 6 | public class DateNotOrderedException extends Exception { 7 | 8 | public DateNotOrderedException(String message) { 9 | super(message); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/exception/StockNotFoundException.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.exception; 2 | 3 | /** 4 | * to be thrown when stock could not find 5 | */ 6 | public class StockNotFoundException extends RuntimeException{ 7 | 8 | public StockNotFoundException(String message) { 9 | 10 | super(message); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/dao/StockDataTxtHelper.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao; 2 | 3 | import cn.edu.nju.p.po.StockPO; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * Created by dell- on 2017/6/10. 9 | */ 10 | public interface StockDataTxtHelper { 11 | 12 | public Map> getStockData(String year); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/exception/StockNoneException.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.exception; 2 | 3 | /** 4 | * thrown when the given date is holiday and festivals,causing the stock market paused 5 | */ 6 | public class StockNoneException extends Exception { 7 | 8 | public StockNoneException(String message) { 9 | super(message); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/dao/MarketPerformanceDao.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao; 2 | 3 | import cn.edu.nju.p.po.SameMarketStockPO; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Created by dell- on 2017/6/8. 9 | */ 10 | public interface MarketPerformanceDao { 11 | 12 | public List getSameMarketStockInfo(String code, int type); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/dao/daoutils/MysqlHelper.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao.daoutils; 2 | 3 | import cn.edu.nju.p.po.StockPO; 4 | 5 | import java.sql.SQLException; 6 | 7 | /** 8 | * Created by dell- on 2017/5/12. 9 | */ 10 | public interface MysqlHelper { 11 | 12 | void getDataFromCSV(String year)throws SQLException; 13 | 14 | void insertIntoDataBase(String year,StockPO po)throws SQLException; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/dao/daoutils/MysqlHelper_WY.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao.daoutils; 2 | 3 | import cn.edu.nju.p.po.StockPO; 4 | 5 | import java.sql.SQLException; 6 | 7 | /** 8 | * Created by dell- on 2017/6/9. 9 | */ 10 | public interface MysqlHelper_WY { 11 | 12 | void getDataFromCSV(String code)throws SQLException; 13 | 14 | void insertIntoDataBase(String code,StockPO po)throws SQLException; 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/nju/p/utils/ema/TestDate.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.utils.ema; 2 | 3 | import org.junit.Test; 4 | 5 | import java.time.LocalDate; 6 | 7 | /** 8 | * Created by soft on 2017/5/18. 9 | */ 10 | public class TestDate { 11 | 12 | @Test 13 | public void dateTest(){ 14 | 15 | LocalDate current = LocalDate.now(); 16 | System.out.println(current.getDayOfWeek()); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/annotation/StockNotFoundCheck.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * methods with this annotation are implied to stock not found exception check 7 | */ 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | @Documented 11 | public @interface StockNotFoundCheck { 12 | 13 | /** 14 | * to be completed 15 | */ 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/service/strategy/MomentumService.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.service.strategy; 2 | 3 | import cn.edu.nju.p.vo.MomentumResultVO; 4 | import cn.edu.nju.p.vo.MomentumVO; 5 | 6 | /** 7 | * 动量策略的接口 8 | */ 9 | public interface MomentumService { 10 | 11 | /** 12 | * 获取基本的数据 13 | * @param momentumVO 数据输入 14 | * @return 返回显示结果的vo 15 | */ 16 | MomentumResultVO getResult(MomentumVO momentumVO); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/nju/p/QuantradingApplicationTests.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class QuantradingApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/service/strategy/MeanReversionService.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.service.strategy; 2 | 3 | 4 | import cn.edu.nju.p.vo.MeanReversionParamVO; 5 | import cn.edu.nju.p.vo.MeanReversionResultVO; 6 | 7 | /** 8 | * Created by xihao on 17-4-15. 9 | */ 10 | public interface MeanReversionService { 11 | 12 | /** 13 | * 实现均线回归策略 直观返回对比 14 | * @param paramVO 参数集合 15 | * @return 显示图片需要的数据 16 | */ 17 | MeanReversionResultVO getResult(MeanReversionParamVO paramVO); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/controller/swagger/SwaggerRedirect.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.controller.swagger; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import springfox.documentation.annotations.ApiIgnore; 6 | 7 | /** 8 | * to redirect the api request 9 | */ 10 | @Controller 11 | @ApiIgnore 12 | public class SwaggerRedirect { 13 | 14 | @RequestMapping("/api") 15 | public String redirect() { 16 | return "redirect:swagger-ui.html"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/strategy/Strategy.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.strategy; 2 | 3 | import java.time.LocalDate; 4 | import java.util.List; 5 | 6 | /** 7 | * Created by xihao on 17-6-13. 8 | */ 9 | public interface Strategy { 10 | 11 | List setStockPool(); 12 | 13 | List setWinner(LocalDate beginDate, LocalDate endDate, List stockPool); 14 | 15 | LocalDate setBeginDate(); 16 | 17 | LocalDate setEndDate(); 18 | 19 | int setHoldingDay(); 20 | 21 | int setFormativeDayNum(); 22 | 23 | } 24 | 25 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/dao/CompanyDao.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao; 2 | 3 | import cn.edu.nju.p.vo.CompanyAnnouncementVO; 4 | import cn.edu.nju.p.vo.CompanyInfoVO; 5 | import cn.edu.nju.p.vo.CompanyNewsVO; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by dell- on 2017/5/17. 11 | */ 12 | public interface CompanyDao { 13 | 14 | CompanyInfoVO getCompanyInfoVO(String code); 15 | 16 | List getCompanyNewsVOList(String code); 17 | 18 | List getCompanyAnnouncementVOList(String code); 19 | } 20 | -------------------------------------------------------------------------------- /src/test/resources/application.properties: -------------------------------------------------------------------------------- 1 | mybatis.configuration.call-setters-on-nulls=true 2 | mybatis.configuration.map-underscore-to-camel-case=true 3 | #mybatis.type-handlers-package=cn.edu.nju.p.utils.mybatis 4 | 5 | spring.datasource.url=jdbc:mysql://106.14.224.189:3306/quantitivetrading?useUnicode=true&characterEncoding=UTF-8 6 | #spring.datasource.url=jdbc:mysql://localhost:3306/quantitivetrading 7 | spring.datasource.username=root 8 | spring.datasource.password=mysql 9 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 10 | #spring.datasource.tomcat.max-active=50 11 | 12 | #spring.aop.proxy-target-class=true 13 | spring.redis.timeout=20000 -------------------------------------------------------------------------------- /src/test/java/cn/edu/nju/p/utils/DateHelperTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.utils; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.cglib.core.Local; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | import org.springframework.test.context.web.WebAppConfiguration; 9 | 10 | import java.time.LocalDate; 11 | 12 | import static org.junit.Assert.*; 13 | 14 | /** 15 | * Created by xihao on 17-6-7. 16 | */ 17 | @RunWith(SpringRunner.class) 18 | @WebAppConfiguration 19 | @SpringBootTest 20 | public class DateHelperTest { 21 | 22 | 23 | } -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/service/exhibition/KLineService.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.service.exhibition; 2 | 3 | import cn.edu.nju.p.exception.StockNotFoundException; 4 | import cn.edu.nju.p.vo.KLineVO; 5 | 6 | import java.time.LocalDate; 7 | import java.util.List; 8 | 9 | /** 10 | * 构建K线提供的接口 11 | */ 12 | public interface KLineService { 13 | 14 | /** 15 | * 通过股票代码获得KLine需要的所有VO 16 | * @param code 股票代码 17 | * @param beginDate 开始日期 18 | * @param endDate 结束日期 19 | * @return 返回每一天的KLine数据 20 | */ 21 | KLineVO getKLineVOSByCode(String code, LocalDate beginDate, LocalDate endDate) throws StockNotFoundException; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/service/strategy/SectorService.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.service.strategy; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 板块相关的service 7 | */ 8 | public interface SectorService { 9 | 10 | 11 | /** 12 | * get all string info of a sector 13 | * @param sector the sector name 14 | * @return 15 | */ 16 | List getStocks(String sector); 17 | 18 | /** 19 | * get all stocks ,simply get a string formatted like "stockname+'|'+stockcode" 20 | * @return stockinfo list 21 | */ 22 | List getAllStocks(); 23 | 24 | /** 25 | * 26 | */ 27 | 28 | String getStockName(String code); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/service/personnel/MyStockService.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.service.personnel; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by pc on 2017/6/7. 7 | */ 8 | 9 | public interface MyStockService { 10 | /** 11 | * 根据用户id得到该用户的自选股票 12 | * 13 | * @param userId 客户id 14 | * @return 一个包含该用户自选股的list 15 | */ 16 | 17 | List getMyStock(String userId); 18 | 19 | /** 20 | * 添加自选股 21 | * @param userId 22 | * @param stockCode 23 | */ 24 | void addStock(String userId, String stockCode); 25 | 26 | void deleteStock(String userId, String code); 27 | 28 | void deleteAllStock(String phoneNumber); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | mybatis.configuration.call-setters-on-nulls=true 2 | mybatis.configuration.map-underscore-to-camel-case=true 3 | mybatis.configuration.cache-enabled=true 4 | #mybatis.type-handlers-package=cn.edu.nju.p.utils.mybatis 5 | 6 | spring.datasource.url=jdbc:mysql://106.14.224.189:3306/quantitivetrading?useUnicode=true&characterEncoding=UTF-8 7 | #spring.datasource.url=jdbc:mysql://localhost:3306/quantitivetrading 8 | spring.datasource.username=root 9 | spring.datasource.password=mysql 10 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 11 | #spring.datasource.tomcat.max-active=50 12 | 13 | #spring.redis.host=106.14.224.189 14 | spring.redis.timeout=200000 -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/strategy/customstrategy/javacompile/core/StringJavaFileObject.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.strategy.customstrategy.javacompile.core; 2 | 3 | 4 | import java.net.URI; 5 | 6 | import javax.tools.SimpleJavaFileObject; 7 | 8 | /** 9 | * Created by dell- on 2017/6/7. 10 | */ 11 | class StringJavaFileObject extends SimpleJavaFileObject { 12 | 13 | final String code; 14 | 15 | StringJavaFileObject(String className, String code) { 16 | super(URI.create(className + Kind.SOURCE.extension), Kind.SOURCE); 17 | this.code = code; 18 | } 19 | 20 | @Override 21 | public CharSequence getCharContent(boolean ignoreEncodingErrors) { 22 | return code; 23 | } 24 | } -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/utils/DoubleUtils.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.utils; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | /** 8 | * the util to operate on Double 9 | */ 10 | public class DoubleUtils { 11 | 12 | public static double formatDouble(double d,int scale) { 13 | BigDecimal bigDecimal = new BigDecimal(d); 14 | return bigDecimal.setScale(scale, BigDecimal.ROUND_HALF_UP).doubleValue(); 15 | } 16 | 17 | public static List adjDoubleList(List doubles) { 18 | 19 | List newList = new ArrayList<>(); 20 | for (Double aDouble : doubles) { 21 | newList.add(formatDouble(aDouble * 100,2)); 22 | } 23 | return newList; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/config/FilterConfig.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.config; 2 | 3 | import cn.edu.nju.p.filter.CorsFilter; 4 | import org.springframework.boot.web.servlet.FilterRegistrationBean; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | /** 9 | * Created by soft on 2017/5/18. 10 | */ 11 | @Configuration 12 | public class FilterConfig { 13 | 14 | /* @Bean 15 | public FilterRegistrationBean corsFilter(){ 16 | 17 | FilterRegistrationBean corsFilterReg = new FilterRegistrationBean(); 18 | corsFilterReg.setFilter(new CorsFilter()); 19 | corsFilterReg.addUrlPatterns("*//*"); 20 | corsFilterReg.setName("corsFilter"); 21 | return corsFilterReg; 22 | }*/ 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/dao/AccountDao.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao; 2 | 3 | import org.apache.ibatis.annotations.Insert; 4 | import org.apache.ibatis.annotations.Mapper; 5 | import org.apache.ibatis.annotations.Param; 6 | import org.apache.ibatis.annotations.Select; 7 | import org.springframework.stereotype.Repository; 8 | 9 | /** 10 | * Created by xihao on 17-6-5. 11 | */ 12 | @Mapper 13 | @Repository 14 | public interface AccountDao { 15 | 16 | @Insert("insert into account (phone_number,password) values (#{phoneNumber},#{password})") 17 | void addAccount(@Param("phoneNumber") String phoneNumber, @Param("password") String password); 18 | 19 | @Select("select password from account where phone_number =#{phoneNumber}") 20 | String getPassword(String phoneNumber); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/service/strategy/ChooseBestDayService.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.service.strategy; 2 | 3 | import cn.edu.nju.p.vo.BestDayResultVO; 4 | import cn.edu.nju.p.vo.MeanReversionParamForBestDayVO; 5 | import cn.edu.nju.p.vo.MomentumParamVO; 6 | 7 | /** 8 | * Created by xihao on 17-4-3. 9 | */ 10 | public interface ChooseBestDayService { 11 | 12 | /** 13 | * 获得动量策略的超额收益率和策略收益率和形成期(持有期)的关系 14 | * @param momentumParamVO 动量策略的一些参数 15 | * @return 画图需要的参数 16 | */ 17 | BestDayResultVO getResultReturnsOfMomentum(MomentumParamVO momentumParamVO); 18 | 19 | /** 20 | * 获得均值回归的超额收益率和策略胜率和持有期的关系 21 | * @param vo 输入的必要的参数 22 | * @return 返回画图需要的参数(超额收益和策略胜率和持有期的关系) 23 | */ 24 | BestDayResultVO getResultReturnsOfMeanReversion(MeanReversionParamForBestDayVO vo); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/po/UserPO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.po; 2 | 3 | /** 4 | * the information of user 5 | */ 6 | public class UserPO { 7 | 8 | private String phoneNumber; 9 | private String password; 10 | private String userName; 11 | 12 | public String getPhoneNumber() { 13 | return phoneNumber; 14 | } 15 | 16 | public void setPhoneNumber(String phoneNumber) { 17 | this.phoneNumber = phoneNumber; 18 | } 19 | 20 | public String getPassword() { 21 | return password; 22 | } 23 | 24 | public void setPassword(String password) { 25 | this.password = password; 26 | } 27 | 28 | public String getUserName() { 29 | return userName; 30 | } 31 | 32 | public void setUserName(String userName) { 33 | this.userName = userName; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/po/StrategyCodePO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.po; 2 | 3 | /** 4 | * Created by pc on 2017/6/15. 5 | */ 6 | public class StrategyCodePO { 7 | 8 | private String phoneNumber; 9 | private String code; 10 | private String strategyName; 11 | 12 | public String getPhoneNumber() { 13 | return phoneNumber; 14 | } 15 | 16 | public void setPhoneNumber(String phoneNumber) { 17 | this.phoneNumber = phoneNumber; 18 | } 19 | 20 | public String getCode() { 21 | return code; 22 | } 23 | 24 | public void setCode(String code) { 25 | this.code = code; 26 | } 27 | 28 | public String getStrategyName() { 29 | return strategyName; 30 | } 31 | 32 | public void setStrategyName(String strategyName) { 33 | this.strategyName = strategyName; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/service/exhibition/HomePageService.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.service.exhibition; 2 | 3 | import cn.edu.nju.p.exception.StockNoneException; 4 | import cn.edu.nju.p.exception.StockNotFoundException; 5 | import cn.edu.nju.p.vo.StockMarketVO; 6 | import cn.edu.nju.p.vo.StockVO; 7 | 8 | import java.time.LocalDate; 9 | import java.util.List; 10 | 11 | /** 12 | * Created by cyz on 2017/6/6. 13 | */ 14 | public interface HomePageService{ 15 | 16 | 17 | /** 18 | * 获取当天的股票行情 19 | * @param date 日期 20 | * @return 返回当日的股票数据 21 | */ 22 | StockMarketVO getMarketVO(LocalDate date) throws StockNoneException, StockNotFoundException; 23 | 24 | /** 25 | * 获取当日的所有股票行情 26 | * 27 | * @param date 日期 28 | * @return 返回当日所有股票的信息 29 | * 30 | */ 31 | 32 | List getStockVO(LocalDate date); 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/nju/p/utils/StockHelperTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.utils; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | import org.springframework.test.context.web.WebAppConfiguration; 8 | 9 | import java.time.LocalDate; 10 | 11 | /** 12 | * Created by xihao on 17-6-5. 13 | */ 14 | @RunWith(SpringRunner.class) 15 | @WebAppConfiguration 16 | @SpringBootTest 17 | public class StockHelperTest { 18 | 19 | /* @Test 20 | public void hasStoppedTest() { 21 | 22 | String code = "000010"; 23 | LocalDate beginDate = LocalDate.of(2012, 2, 3); 24 | LocalDate endDate = beginDate.minusYears(1); 25 | System.out.println(StockHelper.hasStopped(code,endDate,beginDate)); 26 | }*/ 27 | 28 | 29 | } -------------------------------------------------------------------------------- /src/test/java/cn/edu/nju/p/dao/MysqlHelperImplTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao; 2 | 3 | 4 | import cn.edu.nju.p.QuantradingApplication; 5 | import cn.edu.nju.p.dao.daoutils.MysqlHelperImpl; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.test.context.ContextConfiguration; 10 | import org.springframework.test.context.junit4.SpringRunner; 11 | import org.springframework.test.context.web.WebAppConfiguration; 12 | 13 | /** 14 | * Created by soft on 2017/5/17. 15 | */ 16 | @RunWith(SpringRunner.class) 17 | @WebAppConfiguration 18 | @ContextConfiguration(classes = QuantradingApplication.class) 19 | public class MysqlHelperImplTest { 20 | @Autowired 21 | private MysqlHelperImpl helper; 22 | 23 | @Test 24 | public void getDataFromCSV() throws Exception { 25 | helper.getDataFromCSV("2016"); 26 | } 27 | } -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/cache/TokenManagerImpl.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.cache; 2 | 3 | import cn.edu.nju.p.utils.EncryptHelper; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Service; 6 | import org.springframework.util.StringUtils; 7 | 8 | /** 9 | * Created by xihao on 17-6-5. 10 | */ 11 | @Service 12 | public class TokenManagerImpl implements TokenManager { 13 | 14 | @Autowired 15 | RedisCache redisCache; 16 | 17 | @Override 18 | public String createToken(String phoneNumber) { 19 | 20 | String token = EncryptHelper.getShaEncryption(phoneNumber); 21 | redisCache.putCacheWithExpireTime(token, phoneNumber, 60 * 20); //20 minutes 22 | return token; 23 | } 24 | 25 | @Override 26 | public boolean checkToken(String token) { 27 | return !StringUtils.isEmpty(token) && redisCache.getCache(token,String.class)!=null; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/nju/p/dao/AccountDaoTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | import org.springframework.test.context.web.WebAppConfiguration; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Created by xihao on 17-6-5. 14 | */ 15 | @RunWith(SpringRunner.class) 16 | @WebAppConfiguration 17 | @SpringBootTest 18 | public class AccountDaoTest { 19 | 20 | @Autowired 21 | private AccountDao accountDao; 22 | 23 | @Test 24 | public void addAccount() throws Exception { 25 | accountDao.addAccount("test", "test"); 26 | } 27 | 28 | @Test 29 | public void getPassword() throws Exception { 30 | assertEquals("test",accountDao.getPassword("test")); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/utils/beans/ToolSpring.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.utils.beans; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.stereotype.Component; 5 | import org.springframework.web.context.support.WebApplicationObjectSupport; 6 | 7 | /** 8 | * Created by Xihao on 2017/6/14. 9 | */ 10 | @Component 11 | public class ToolSpring extends WebApplicationObjectSupport { 12 | 13 | private static ApplicationContext applicationContext = null; 14 | 15 | @Override 16 | protected void initApplicationContext(ApplicationContext context) { 17 | super.initApplicationContext(context); 18 | if (ToolSpring.applicationContext == null) { 19 | ToolSpring.applicationContext = context; 20 | System.out.println("初始化bean获取类成功!"); 21 | } 22 | 23 | } 24 | 25 | public static T getBeans(Class tClass) { 26 | return applicationContext.getBean(tClass); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/service/personnel/PersonnalInfoService.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.service.personnel; 2 | 3 | import cn.edu.nju.p.vo.ClientVO; 4 | 5 | /** 6 | * Created by pc on 2017/6/10. 7 | */ 8 | public interface PersonnalInfoService { 9 | 10 | /** 11 | * 12 | * @param phoneNumber 13 | * @return 14 | */ 15 | ClientVO getClientInfo(String phoneNumber); 16 | 17 | /** 18 | * 19 | * @param phone_number 20 | * @param user_name 21 | * @param sex 22 | * @param email 23 | * @param unit 24 | * @param place 25 | */ 26 | void updateClient(String phone_number, String user_name,String sex,String email,String unit,String place); 27 | 28 | /** 29 | * 30 | * @param userName 31 | * @param phoneNumber 32 | */ 33 | void addClient(String userName,String phoneNumber,String password); 34 | 35 | /** 36 | * 37 | * @param phone_number 38 | */ 39 | void updatePass(String phone_number,String password); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/dao/MyStockDao.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao; 2 | 3 | import org.apache.ibatis.annotations.*; 4 | import org.springframework.stereotype.Repository; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by pc on 2017/6/7. 11 | */ 12 | @Mapper 13 | @Repository 14 | public interface MyStockDao { 15 | 16 | @Insert("insert into my_stock(userId,stock_code) values (#{userId},#{stockCode})") 17 | void addStock(@Param("userId") String userId, @Param("stockCode") String stockCode); 18 | 19 | @Select(value="select stock_code from my_stock where userId = #{userId}") 20 | List getMyStockCode(String userId); 21 | 22 | @Delete("delete from my_stock where userId=#{phoneNumber} and stock_code=#{code}") 23 | void deleteStock(@Param("phoneNumber") String phoneNumber, @Param("code") String code); 24 | 25 | @Delete("delete from my_stock where userId=#{phoneNumber}") 26 | void deleteAllStock(@PathVariable String phoneNumber); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/enums/ErrorCode.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.enums; 2 | 3 | /** 4 | * imply all the error codes here 5 | */ 6 | public enum ErrorCode { 7 | 8 | //Date Error 9 | DATE_NOT_ORDERED(10000001), 10 | DATE_PARSE_ERROR(10000002), 11 | 12 | //Stock Error 13 | STOCK_NOT_FOUND(20000001), 14 | STOCK_NONE(20000002), 15 | 16 | //User Check Error 17 | PASSWORD_NOT_MATCH(30000001), 18 | 19 | //code error 20 | NO_CLASS_NAME(40000001), 21 | COMPILE_ERROR(40000002), 22 | 23 | //Dao Error 24 | MY_STOCK_DUPLI_ERROR(50000001) 25 | ; 26 | 27 | private int errorCode; 28 | 29 | ErrorCode(int errorCode) { 30 | this.errorCode = errorCode; 31 | } 32 | 33 | public int getErrorCode() { 34 | return errorCode; 35 | } 36 | 37 | public static ErrorCode stateOf(int errorCode) { 38 | for (ErrorCode error : values()) { 39 | if (error.getErrorCode() == errorCode) { 40 | return error; 41 | } 42 | } 43 | return null; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/nju/p/utils/VacationDatesTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.utils; 2 | 3 | import cn.edu.nju.p.utils.holiday.VacationDates; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.test.context.junit4.SpringRunner; 9 | import org.springframework.test.context.web.WebAppConfiguration; 10 | 11 | import java.time.LocalDate; 12 | 13 | /** 14 | * Created by xihao on 17-6-5. 15 | */ 16 | @SpringBootTest 17 | @RunWith(SpringRunner.class) 18 | @WebAppConfiguration 19 | public class VacationDatesTest { 20 | 21 | @Autowired 22 | private VacationDates vacationDates; 23 | 24 | @Test 25 | public void isVacation() throws Exception { 26 | 27 | LocalDate date = LocalDate.of(2012, 1, 31); 28 | System.out.println(vacationDates.isVacation(date)); 29 | } 30 | 31 | @Test 32 | public void isVacationTest() throws Exception { 33 | 34 | LocalDate date = LocalDate.of(2017, 10, 6); 35 | System.out.println(vacationDates.isVacation(date)); 36 | 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/dao/daoutils/GetDataFromYahooUtil.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao.daoutils; 2 | 3 | 4 | 5 | import java.io.BufferedReader; 6 | import java.io.InputStreamReader; 7 | import java.net.URL; 8 | import java.net.URLConnection; 9 | 10 | /** 11 | * Created by dell- on 2017/6/7. 12 | */ 13 | public class GetDataFromYahooUtil { 14 | 15 | 16 | public static void main(String[] args) { 17 | try { 18 | URL url = new URL("http://finance.yahoo.com/d/quotes.csv?s=000001.sz&f=d1snohgl1vv"); 19 | URLConnection urlConn = url.openConnection(); 20 | InputStreamReader inputStreamReader = new InputStreamReader(urlConn.getInputStream()); 21 | BufferedReader bufferedReader = new BufferedReader(inputStreamReader); 22 | String line=bufferedReader.readLine(); 23 | System.out.println(line); 24 | while ((line = bufferedReader.readLine()) != null) { 25 | System.out.println(line); 26 | } 27 | bufferedReader.close(); 28 | inputStreamReader.close(); 29 | } catch (Exception e) { 30 | e.printStackTrace(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/vo/AverageVO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.vo; 2 | 3 | import java.time.LocalDate; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | /** 8 | * 均线画图需要的数据 9 | */ 10 | public class AverageVO { 11 | 12 | private List> averageLines; 13 | 14 | private String stockCode; 15 | private String stockName; 16 | 17 | public AverageVO(List> averageLines, String stockCode, String stockName) { 18 | this.averageLines = averageLines; 19 | this.stockCode = stockCode; 20 | this.stockName = stockName; 21 | } 22 | 23 | public List> getAverageLines() { 24 | return averageLines; 25 | } 26 | 27 | public String getStockCode() { 28 | return stockCode; 29 | } 30 | 31 | public String getStockName() { 32 | return stockName; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return "AverageVO{" + 38 | "averageLines=" + averageLines + 39 | ", stockCode='" + stockCode + '\'' + 40 | ", stockName='" + stockName + '\'' + 41 | '}'; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/utils/FileHelper.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.utils; 2 | 3 | import java.io.FileWriter; 4 | import java.io.IOException; 5 | import java.io.PrintWriter; 6 | import java.text.SimpleDateFormat; 7 | import java.util.Calendar; 8 | 9 | /** 10 | * 往日志文件里面写进数据,和从日志文件读取数据 11 | */ 12 | public class FileHelper { 13 | 14 | private String logPath; 15 | 16 | public FileHelper(String logPath){ 17 | this.logPath = logPath; 18 | } 19 | /** 20 | * 往log文件写入日志信息 21 | * @param message 信息 22 | */ 23 | public void writeMessage(String message){ 24 | 25 | FileWriter fw = null; 26 | try { 27 | fw = new FileWriter(logPath,true); 28 | } catch (IOException e) { 29 | e.printStackTrace(); 30 | return; 31 | } 32 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 33 | PrintWriter pw = new PrintWriter(fw,true); 34 | pw.println(sdf.format(Calendar.getInstance().getTime())+" "+message); 35 | 36 | try { 37 | fw.close(); 38 | pw.close(); 39 | } catch (IOException e) { 40 | e.printStackTrace(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/serviceimpl/SectorServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.serviceimpl; 2 | 3 | import cn.edu.nju.p.dao.StockDao; 4 | import cn.edu.nju.p.exception.SectorNotExistException; 5 | import cn.edu.nju.p.service.strategy.SectorService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * sectorService的实现类 13 | */ 14 | @Service 15 | public class SectorServiceImpl implements SectorService { 16 | 17 | @Autowired 18 | private StockDao stockDao; 19 | 20 | @Override 21 | public List getStocks(String sector) { 22 | 23 | boolean isSectorExist = "创业板".equals(sector) || "中小板".equals(sector) || "主板".equals(sector); 24 | if (!isSectorExist) { 25 | throw new SectorNotExistException("Sector " + sector + " does not exist"); 26 | } 27 | return stockDao.getStockBySector(sector); 28 | } 29 | 30 | @Override 31 | public List getAllStocks() { 32 | return stockDao.getAllStocks(); 33 | } 34 | 35 | @Override 36 | public String getStockName(String code){ 37 | return stockDao.getStockName(code); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/strategy/customstrategy/javacompile/util/RunCompileUtil.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.strategy.customstrategy.javacompile.util; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | /** 7 | * Created by dell- on 2017/6/7. 8 | */ 9 | public class RunCompileUtil { 10 | 11 | private static Pattern classNamePattern = Pattern.compile("\\s+class\\s+([a-zA-Z_$]+[0-9a-zA-Z_$]+)[\\s{]"); 12 | private static Pattern packagePattern = Pattern.compile("\\s*package\\s+([a-z\\.]+)[\\s;]"); 13 | 14 | public static String getClassName(String str) { 15 | Matcher matcher = classNamePattern.matcher(str); 16 | if (!matcher.find()) { 17 | throw new RuntimeException("Can't find class name in content: \n" + str); 18 | } 19 | return matcher.group(1); 20 | } 21 | 22 | public static String getFullClassName(String str) { 23 | String className = getClassName(str); 24 | 25 | Matcher matcher = packagePattern.matcher(str); 26 | if (!matcher.find()) { 27 | return className; 28 | } 29 | String packageName = matcher.group(1); 30 | 31 | return packageName + "." + className; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/nju/p/serviceimpl/KLineServiceImplTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.serviceimpl; 2 | 3 | import cn.edu.nju.p.service.exhibition.KLineService; 4 | import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | import org.springframework.test.context.web.WebAppConfiguration; 11 | 12 | import java.time.LocalDate; 13 | 14 | import static org.junit.Assert.*; 15 | 16 | /** 17 | * Created by soft on 2017/5/18. 18 | */ 19 | @WebAppConfiguration 20 | @RunWith(SpringRunner.class) 21 | @SpringBootTest 22 | public class KLineServiceImplTest { 23 | 24 | @Autowired 25 | private KLineService kLineService; 26 | 27 | @Test 28 | public void getKLineVOSByCode() throws Exception { 29 | 30 | LocalDate beginDate = LocalDate.of(2006, 2, 3); 31 | LocalDate endDate = LocalDate.of(2006, 5, 30); 32 | String stockCode = "000001"; 33 | System.out.println(kLineService.getKLineVOSByCode(stockCode, beginDate, endDate)); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/baseresult/BaseResult.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.baseresult; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * data transfer base object 7 | */ 8 | public class BaseResult implements Serializable{ 9 | 10 | private static final long serialVersionUID = -4185151304730685014L; 11 | 12 | private int errorCode; //0 means success 13 | private T data; 14 | 15 | /** 16 | * successfully get the result data,error code is 0 17 | * @param errorCode 18 | * @param data the data to be transferred 19 | */ 20 | public BaseResult(int errorCode, T data) { 21 | this.data = data; 22 | this.errorCode = 0; 23 | } 24 | 25 | /** 26 | * occurs error 27 | * @param errorCode the error code 28 | * @param message the error message 29 | */ 30 | public BaseResult(int errorCode, String message) { 31 | this.errorCode = errorCode; 32 | this.data = (T) message; 33 | } 34 | 35 | public static long getSerialVersionUID() { 36 | return serialVersionUID; 37 | } 38 | 39 | public int getErrorCode() { 40 | return errorCode; 41 | } 42 | 43 | public T getData() { 44 | return data; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/vo/BestDayResultVO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.vo; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * Created by xihao on 17-4-3. 7 | */ 8 | public class BestDayResultVO { 9 | 10 | private Map abnormalReturns; //超额收益 11 | private Map filedWins; //策略胜率 12 | 13 | public BestDayResultVO(Map abnormalReturns, Map filedWins) { 14 | this.abnormalReturns = abnormalReturns; 15 | this.filedWins = filedWins; 16 | } 17 | 18 | public Map getAbnormalReturns() { 19 | return abnormalReturns; 20 | } 21 | 22 | public void setAbnormalReturns(Map abnormalReturns) { 23 | this.abnormalReturns = abnormalReturns; 24 | } 25 | 26 | public Map getFiledWins() { 27 | return filedWins; 28 | } 29 | 30 | public void setFiledWins(Map filedWins) { 31 | this.filedWins = filedWins; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "BestDayResultVO{" + 37 | "abnormalReturns=" + abnormalReturns + 38 | ", filedWins=" + filedWins + 39 | '}'; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/nju/p/utils/ema/MACDUtilsTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.utils.ema; 2 | 3 | import cn.edu.nju.p.QuantradingApplication; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.test.context.ContextConfiguration; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | import org.springframework.test.context.junit4.SpringRunner; 11 | import org.springframework.test.context.web.WebAppConfiguration; 12 | 13 | import java.time.LocalDate; 14 | 15 | import static org.junit.Assert.*; 16 | 17 | /** 18 | * Created by soft on 2017/5/18. 19 | */ 20 | @RunWith(SpringJUnit4ClassRunner.class) 21 | @SpringBootTest 22 | @WebAppConfiguration 23 | public class MACDUtilsTest { 24 | 25 | @Autowired 26 | private MACDUtils macdUtils; 27 | 28 | @Test 29 | public void getEmaValue() throws Exception { 30 | System.out.println(macdUtils.getEmaValue(12, LocalDate.of(2012, 10, 20), "000001")); 31 | } 32 | 33 | @Test 34 | public void getDea() throws Exception { 35 | System.out.println(macdUtils.getDea(9,LocalDate.of(2012, 10, 20), "000001")); 36 | } 37 | } -------------------------------------------------------------------------------- /src/test/java/cn/edu/nju/p/utils/DeleteCacheTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.utils; 2 | 3 | import cn.edu.nju.p.cache.RedisCache; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.data.redis.core.StringRedisTemplate; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | import org.springframework.test.context.web.WebAppConfiguration; 11 | 12 | import java.util.Set; 13 | 14 | /** 15 | * Created by Xihao on 2017/6/14. 16 | */ 17 | @RunWith(SpringRunner.class) 18 | @WebAppConfiguration 19 | @SpringBootTest 20 | public class DeleteCacheTest { 21 | 22 | @Autowired 23 | private StringRedisTemplate redisTemplate; 24 | 25 | @Autowired 26 | private RedisCache redisCache; 27 | 28 | @Test 29 | public void deleteStockVolumeCache(){ 30 | 31 | Set keys = redisTemplate.keys("getStockVolumeFromRedis*"); 32 | for (String key : keys) { 33 | redisTemplate.delete(key); 34 | } 35 | } 36 | 37 | @Test 38 | public void deleteStockVolumeByRedisCache(){ 39 | 40 | redisCache.deleteCacheWithPattern("getStockVolumeFromRedis*"); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/vo/CompanyNewsVO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.vo; 2 | 3 | /** 4 | * Created by dell- on 2017/5/16. 5 | */ 6 | public class CompanyNewsVO { 7 | 8 | private String date; //新闻日期 9 | private String link; //新闻的URL链接 10 | private String title; //新闻标题 11 | 12 | public CompanyNewsVO(String title, String link, String date) { 13 | this.title = title; 14 | this.link = link; 15 | this.date = date; 16 | } 17 | 18 | public CompanyNewsVO() { 19 | 20 | } 21 | 22 | public String getDate() { 23 | return date; 24 | } 25 | 26 | public void setDate(String date) { 27 | this.date = date; 28 | } 29 | 30 | public String getLink() { 31 | return link; 32 | } 33 | 34 | public void setLink(String link) { 35 | this.link = link; 36 | } 37 | 38 | public String getTitle() { 39 | return title; 40 | } 41 | 42 | public void setTitle(String title) { 43 | this.title = title; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "CompanyNewsVO{" + 49 | "date='" + date + '\'' + 50 | ", link='" + link + '\'' + 51 | ", title='" + title + '\'' + 52 | '}'; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/vo/CompanyAnnouncementVO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.vo; 2 | 3 | /** 4 | * Created by dell- on 2017/5/17. 5 | */ 6 | public class CompanyAnnouncementVO { 7 | 8 | private String title; 9 | private String link; 10 | private String date; 11 | 12 | public CompanyAnnouncementVO(String title, String link, String date) { 13 | this.title = title; 14 | this.link = link; 15 | this.date = date; 16 | } 17 | 18 | public CompanyAnnouncementVO() { 19 | 20 | } 21 | 22 | public String getTitle() { 23 | return title; 24 | } 25 | 26 | public void setTitle(String title) { 27 | this.title = title; 28 | } 29 | 30 | public String getLink() { 31 | return link; 32 | } 33 | 34 | public void setLink(String link) { 35 | this.link = link; 36 | } 37 | 38 | public String getDate() { 39 | return date; 40 | } 41 | 42 | public void setDate(String date) { 43 | this.date = date; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "CompanyAnnouncementVO{" + 49 | "title='" + title + '\'' + 50 | ", link='" + link + '\'' + 51 | ", date='" + date + '\'' + 52 | '}'; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/serviceimpl/PersonnalInfoServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.serviceimpl; 2 | 3 | import cn.edu.nju.p.dao.ClientDao; 4 | import cn.edu.nju.p.service.personnel.PersonnalInfoService; 5 | import cn.edu.nju.p.vo.ClientVO; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * Created by pc on 2017/6/10. 11 | */ 12 | @Service 13 | public class PersonnalInfoServiceImpl implements PersonnalInfoService{ 14 | @Autowired 15 | private ClientDao clientDao; 16 | 17 | @Override 18 | public void addClient(String userName,String phoneNumber,String password){ 19 | clientDao.addClient(userName,phoneNumber,password); 20 | } 21 | 22 | @Override 23 | public ClientVO getClientInfo(String phoneNumber){ 24 | ClientVO vo = clientDao.selectClient(phoneNumber); 25 | return vo; 26 | } 27 | 28 | @Override 29 | public void updateClient(String phone_number, String user_name,String sex,String email,String unit,String place){ 30 | clientDao.updateClient(phone_number,user_name,sex,email,unit,place); 31 | } 32 | 33 | @Override 34 | public void updatePass(String phone_number,String password){ 35 | clientDao.updatePass(phone_number,password); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/po/AveragePO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.po; 2 | 3 | import java.time.LocalDate; 4 | import java.util.List; 5 | 6 | public class AveragePO { 7 | 8 | private List closeList; 9 | private List validDates; 10 | private String stockCode; 11 | private String stockName; 12 | 13 | public AveragePO(String stockCode,String stockName){ 14 | this.stockCode=stockCode; 15 | this.stockName=stockName; 16 | } 17 | 18 | public String getStockCode(){ 19 | return stockCode; 20 | } 21 | 22 | public void setStockCode(String stockCode){ 23 | this.stockCode=stockCode; 24 | } 25 | 26 | public String getStockName(){ 27 | return stockName; 28 | } 29 | 30 | public void setStockName(String stockName){ 31 | this.stockName=stockName; 32 | } 33 | 34 | public List getCloseList(){ 35 | return closeList; 36 | } 37 | 38 | public List getValidDates(){ 39 | return validDates; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "AveragePO{" + 45 | "closeList=" + closeList + 46 | ", validDates=" + validDates + 47 | ", stockCode='" + stockCode + '\'' + 48 | ", stockName='" + stockName + '\'' + 49 | '}'; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/aop/StockCodeValidationAop.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.aop; 2 | 3 | import cn.edu.nju.p.baseresult.BaseResult; 4 | import cn.edu.nju.p.enums.ErrorCode; 5 | import cn.edu.nju.p.utils.StockHelper; 6 | import org.aspectj.lang.ProceedingJoinPoint; 7 | import org.aspectj.lang.annotation.Around; 8 | import org.aspectj.lang.annotation.Aspect; 9 | import org.aspectj.lang.annotation.Pointcut; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Component; 12 | 13 | /** 14 | * an aop to validate stock code to see whether the stock code exists 15 | */ 16 | @Aspect 17 | @Component 18 | public class StockCodeValidationAop { 19 | 20 | @Pointcut("execution(* cn.edu.nju.p.controller.exhibition.*.*(..))") 21 | public void getCompanyInfoAndNews() { 22 | } 23 | 24 | @Autowired 25 | private StockHelper stockHelper; 26 | 27 | /*@Around("getCompanyInfoAndNews()") 28 | public Object stockCodeExistCheck(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { 29 | String code = (String) proceedingJoinPoint.getArgs()[0]; 30 | if (! stockHelper.codeExists(code)) { 31 | return new BaseResult(ErrorCode.STOCK_NOT_FOUND.getErrorCode(), "Code of "+ code + " Not Exists!"); 32 | } 33 | return proceedingJoinPoint.proceed(); 34 | }*/ 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/vo/KLineVO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.vo; 2 | 3 | import cn.edu.nju.p.po.KLinePO; 4 | 5 | import java.time.LocalDate; 6 | import java.util.List; 7 | 8 | 9 | /** 10 | * KLine需要使用到的VO 11 | * name 股票名称 12 | * code 股票代码 13 | * date 日期 14 | * isGoHigh 是否走高 15 | * low 最低指数 16 | * high 最高指数 17 | * open 开盘指数 18 | * close 收盘指数 19 | * range 最高指数与最低指数之差 20 | * dBetweenOpenAndClose 开盘收盘指数之差的绝对值 21 | */ 22 | public class KLineVO { 23 | 24 | private String stockName; 25 | private List> klineData; 26 | 27 | public KLineVO(String stockName, List> klineData) { 28 | this.stockName = stockName; 29 | this.klineData = klineData; 30 | } 31 | 32 | public String getStockName() { 33 | return stockName; 34 | } 35 | 36 | public void setStockName(String stockName) { 37 | this.stockName = stockName; 38 | } 39 | 40 | public List> getKlineData() { 41 | return klineData; 42 | } 43 | 44 | public void setKlineData(List> klineData) { 45 | this.klineData = klineData; 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return "KLineVO{" + 51 | "stockName='" + stockName + '\'' + 52 | ", klineData=" + klineData + 53 | '}'; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/po/SameMarketStockPO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.po; 2 | 3 | /** 4 | * Created by dell- on 2017/6/8. 5 | */ 6 | public class SameMarketStockPO { 7 | 8 | private String name; 9 | private double newestPrice; 10 | private String third; 11 | 12 | public SameMarketStockPO(){ 13 | 14 | } 15 | 16 | public SameMarketStockPO(String name, double newestPrice, String third) { 17 | this.name = name; 18 | this.newestPrice = newestPrice; 19 | this.third = third; 20 | } 21 | 22 | public String getName() { 23 | return name; 24 | } 25 | 26 | public void setName(String name) { 27 | this.name = name; 28 | } 29 | 30 | public double getNewestPrice() { 31 | return newestPrice; 32 | } 33 | 34 | public void setNewestPrice(double newestPrice) { 35 | this.newestPrice = newestPrice; 36 | } 37 | 38 | public String getThird() { 39 | return third; 40 | } 41 | 42 | public void setThird(String third) { 43 | this.third = third; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "SameMarketStockPO{" + 49 | "name='" + name + '\'' + 50 | ", newestPrice=" + newestPrice + 51 | ", third='" + third + '\'' + 52 | '}'; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import springfox.documentation.builders.ApiInfoBuilder; 6 | import springfox.documentation.builders.PathSelectors; 7 | import springfox.documentation.builders.RequestHandlerSelectors; 8 | import springfox.documentation.service.ApiInfo; 9 | import springfox.documentation.spi.DocumentationType; 10 | import springfox.documentation.spring.web.plugins.Docket; 11 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 12 | 13 | @Configuration 14 | @EnableSwagger2 15 | public class SwaggerConfig { 16 | 17 | @Bean 18 | public Docket createRestApi() { 19 | return new Docket(DocumentationType.SWAGGER_2) 20 | .apiInfo(apiInfo()) 21 | .select() 22 | .apis(RequestHandlerSelectors.basePackage("cn.edu.nju.p.controller")) 23 | .paths(PathSelectors.any()) 24 | .build(); 25 | } 26 | 27 | private ApiInfo apiInfo() { 28 | return new ApiInfoBuilder() 29 | .title("Quantitative Trading Apis") 30 | .description("the api docs of all the back end apis") 31 | .version("1.0") 32 | .build(); 33 | } 34 | 35 | 36 | } -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/controller/security/SignUpController.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.controller.security; 2 | 3 | import cn.edu.nju.p.baseresult.BaseResult; 4 | import cn.edu.nju.p.dao.AccountDao; 5 | import cn.edu.nju.p.dao.ClientDao; 6 | import cn.edu.nju.p.po.ClientPO; 7 | import cn.edu.nju.p.po.UserPO; 8 | import cn.edu.nju.p.utils.EncryptHelper; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.web.bind.annotation.PostMapping; 11 | import org.springframework.web.bind.annotation.RequestBody; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | import javax.validation.Valid; 16 | 17 | /** 18 | * Created by soft on 2017/5/17. 19 | */ 20 | @RestController 21 | @RequestMapping("/signup") 22 | public class SignUpController { 23 | 24 | @Autowired 25 | private ClientDao clientDao; 26 | 27 | @PostMapping 28 | public BaseResult signUp(@RequestBody @Valid ClientPO userPO) { 29 | 30 | String password = userPO.getPassword(); 31 | password = EncryptHelper.getShaEncryption(password); 32 | String userName = userPO.getUserName(); 33 | String phoneNumber = userPO.getPhoneNumber(); 34 | clientDao.addClient(userName, phoneNumber, password); 35 | return new BaseResult(0, "successfully add a user!"); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/dao/ClientDao.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao; 2 | 3 | import cn.edu.nju.p.po.ClientPO; 4 | import cn.edu.nju.p.vo.ClientVO; 5 | import org.apache.ibatis.annotations.*; 6 | import org.springframework.stereotype.Repository; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | 9 | /** 10 | * Created by pc on 2017/6/6. 11 | */ 12 | @Mapper 13 | @Repository 14 | public interface ClientDao { 15 | 16 | @Insert(value = "insert into client_information(phone_number,user_name,password) values (#{phoneNumber},#{userName},#{password})") 17 | void addClient(@Param("userName") String userName, @Param("phoneNumber") String phoneNumber , @Param("password") String password); 18 | 19 | @Update(value = "update client_information set sex=#{sex},user_name=#{user_name},email=#{email}," + 20 | "unit=#{unit},place=#{place} where phone_number=#{phone_number}") 21 | void updateClient(@Param("phone_number") String phone_number,@Param("user_name") String user_name,@Param("sex") String sex,@Param("email") String email,@Param("unit") String unit,@Param("place") String place); 22 | 23 | @Select(value = "select * from client_information where phone_number=#{phoneNumber}") 24 | ClientVO selectClient(String phoneNumber); 25 | 26 | @Update(value = "update client_information set password=#{password} where phone_number=#{phone_number}") 27 | void updatePass(@Param("phone_number") String phone_number,@Param("password") String password); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/po/SaveStrategyPO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.po; 2 | 3 | /** 4 | * Created by dell- on 2017/6/15. 5 | */ 6 | public class SaveStrategyPO { 7 | 8 | private String phone_number; 9 | private String strategy_name; 10 | private String strategy_url; 11 | 12 | 13 | public SaveStrategyPO(String phone_number, String strategy_name, String strategy_url) { 14 | this.phone_number = phone_number; 15 | this.strategy_name = strategy_name; 16 | this.strategy_url = strategy_url; 17 | } 18 | 19 | public String getPhone_number() { 20 | return phone_number; 21 | } 22 | 23 | public void setPhone_number(String phone_number) { 24 | this.phone_number = phone_number; 25 | } 26 | 27 | public String getStrategy_name() { 28 | return strategy_name; 29 | } 30 | 31 | public void setStrategy_name(String strategy_name) { 32 | this.strategy_name = strategy_name; 33 | } 34 | 35 | public String getStrategy_url() { 36 | return strategy_url; 37 | } 38 | 39 | public void setStrategy_url(String strategy_url) { 40 | this.strategy_url = strategy_url; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "SaveStrategyPO{" + 46 | "phone_number='" + phone_number + '\'' + 47 | ", strategy_name='" + strategy_name + '\'' + 48 | ", strategy_url='" + strategy_url + '\'' + 49 | '}'; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/serviceimpl/MyStockServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.serviceimpl; 2 | 3 | import cn.edu.nju.p.dao.MyStockDao; 4 | import cn.edu.nju.p.dao.StockDao; 5 | import cn.edu.nju.p.service.personnel.MyStockService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | /** 13 | * Created by pc on 2017/6/7. 14 | */ 15 | 16 | /** 17 | * MyStockService的实现类 18 | */ 19 | @Service 20 | public class MyStockServiceImpl implements MyStockService{ 21 | 22 | @Autowired 23 | private MyStockDao myStockDao; 24 | 25 | @Autowired 26 | private StockDao stockDao; 27 | 28 | 29 | @Override 30 | public List getMyStock(String userId) { 31 | 32 | List stockCodes = myStockDao.getMyStockCode(userId); 33 | List messages = new ArrayList<>(); 34 | for (String code : stockCodes) { 35 | messages.add(code + "-" + stockDao.getStockName(code)); 36 | } 37 | return messages; 38 | } 39 | 40 | @Override 41 | public void addStock(String userId, String stockCode) { 42 | 43 | myStockDao.addStock(userId, stockCode); 44 | } 45 | 46 | @Override 47 | public void deleteStock(String userId, String code) { 48 | myStockDao.deleteStock(userId, code); 49 | } 50 | 51 | 52 | @Override 53 | public void deleteAllStock(String phoneNumber){ 54 | myStockDao.deleteAllStock(phoneNumber); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/nju/p/serviceimpl/ChooseBestDayServiceImplTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.serviceimpl; 2 | 3 | import cn.edu.nju.p.service.strategy.ChooseBestDayService; 4 | import cn.edu.nju.p.vo.MomentumParamVO; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | import org.springframework.test.context.web.WebAppConfiguration; 11 | 12 | import java.time.LocalDate; 13 | 14 | import static org.junit.Assert.*; 15 | 16 | /** 17 | * Created by Xihao on 2017/6/14. 18 | */ 19 | @SpringBootTest 20 | @RunWith(SpringRunner.class) 21 | @WebAppConfiguration 22 | public class ChooseBestDayServiceImplTest { 23 | 24 | @Autowired 25 | private ChooseBestDayService chooseBestDayService; 26 | 27 | @Test 28 | public void getResultReturnsOfMomentum() throws Exception { 29 | 30 | MomentumParamVO momentumParamVO = new MomentumParamVO(LocalDate.of(2016, 5, 2), LocalDate.of(2017, 2, 5), true, 10); 31 | System.out.println(chooseBestDayService.getResultReturnsOfMomentum(momentumParamVO)); 32 | 33 | } 34 | 35 | @Test 36 | public void getResultReturnsOfMomentum2() throws Exception { 37 | 38 | MomentumParamVO momentumParamVO = new MomentumParamVO(LocalDate.of(2016, 5, 2), LocalDate.of(2017, 2, 5), true, 9); 39 | System.out.println(chooseBestDayService.getResultReturnsOfMomentum(momentumParamVO)); 40 | 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/controller/personnel/MyStockController.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.controller.personnel; 2 | 3 | import cn.edu.nju.p.baseresult.BaseResult; 4 | import cn.edu.nju.p.service.personnel.MyStockService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Created by pc on 2017/6/7. 12 | */ 13 | @RestController 14 | @RequestMapping("/personnel") 15 | 16 | public class MyStockController { 17 | 18 | @Autowired 19 | private MyStockService myStockService; 20 | 21 | @GetMapping("/mystock/{userId}") 22 | public BaseResult getMyStock(@PathVariable String userId){ 23 | List list = myStockService.getMyStock(userId); 24 | return new BaseResult<>(0, list); 25 | } 26 | 27 | @GetMapping("/addStock") 28 | public BaseResult addStock(@RequestParam String userId,@RequestParam String stockCode){ 29 | 30 | myStockService.addStock(userId,stockCode); 31 | return new BaseResult<>(0, "插入成功!"); 32 | } 33 | 34 | @GetMapping("/deleteStock") 35 | public BaseResult deleteStock(@RequestParam String phoneNumber, @RequestParam String stockCode) { 36 | myStockService.deleteStock(phoneNumber, stockCode); 37 | return new BaseResult<>(0, "删除成功!"); 38 | } 39 | 40 | @GetMapping("/deleteAllStock/{phoneNumber}") 41 | public BaseResult deleteAllStock(@PathVariable String phoneNumber){ 42 | myStockService.deleteAllStock(phoneNumber); 43 | return new BaseResult<>(0, "删除成功!"); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/dao/StrategySquareDao.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao; 2 | 3 | import cn.edu.nju.p.po.StrategyCodePO; 4 | import org.apache.ibatis.annotations.*; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by dell- on 2017/6/15. 11 | */ 12 | @Mapper 13 | @Repository 14 | public interface StrategySquareDao { 15 | 16 | @Select("select * from strategy_square") 17 | List getAllStrategy(); 18 | 19 | @Insert("insert into strategy_square (phone_number,strategy_name,code) values(#{phoneNumber},#{strategyName},#{code})") 20 | void shareStrategy(@Param("phoneNumber") String phoneNumber, @Param("strategyName") String strategyName,@Param("code")String code); 21 | 22 | // @Select("select strategy_name from my_strategy where phone_number = #{phoneNumber}") 23 | // List getStrategyName(String phoneNumber); 24 | 25 | @Select("select code from my_strategy where phone_number=#{phoneNumber} and locate(strategy_name,#{strategyName}) > 0") 26 | String getCode(@Param("phoneNumber") String phoneNumber, @Param("strategyName") String strategyName); 27 | 28 | @Insert("insert into strategy_square (code) values(#{phoneNumber},#{strategyName},#{strategyName})") 29 | void setCode(@Param("phoneNumber") String phoneNumber, @Param("strategyName") String strategyName); 30 | 31 | @Delete("delete from strategy_square where phone_number=#{phoneNumber} and strategy_name=#{strategyName}") 32 | void deleteStrategy(@Param("phoneNumber") String phoneNumber, @Param("strategyName") String strategyName); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/nju/p/serviceimpl/MomentumServiceImplTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.serviceimpl; 2 | 3 | import cn.edu.nju.p.vo.MomentumVO; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.test.context.junit4.SpringRunner; 9 | import org.springframework.test.context.web.WebAppConfiguration; 10 | 11 | import java.time.LocalDate; 12 | 13 | import static org.junit.Assert.*; 14 | 15 | /** 16 | * Created by xihao on 17-6-7. 17 | */ 18 | @RunWith(SpringRunner.class) 19 | @WebAppConfiguration 20 | @SpringBootTest 21 | public class MomentumServiceImplTest { 22 | 23 | @Autowired 24 | private MomentumServiceImpl momentumService; 25 | 26 | @Test 27 | public void getResult() throws Exception { 28 | 29 | MomentumVO momentumVO = new MomentumVO(10, 20, LocalDate.of(2016, 3, 5), LocalDate.of(2016, 5, 20)); 30 | System.out.println(momentumService.getResult(momentumVO)); 31 | } 32 | 33 | @Test 34 | public void getResultLongTest() throws Exception { 35 | 36 | MomentumVO momentumVO = new MomentumVO(10, 20, LocalDate.of(2016, 3, 5), LocalDate.of(2017, 5, 20)); 37 | System.out.println(momentumService.getResult(momentumVO)); 38 | } 39 | 40 | @Test 41 | public void getRsultShortTest() throws Exception{ 42 | MomentumVO momentumVO = new MomentumVO(10, 20, LocalDate.of(2016, 6, 5), LocalDate.of(2016, 8, 20)); 43 | System.out.println(momentumService.getResult(momentumVO)); 44 | } 45 | } -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/po/ClientPO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.po; 2 | 3 | import java.time.LocalDate; 4 | 5 | /** 6 | * Created by cyz on 2017/6/6. 7 | */ 8 | public class ClientPO { 9 | 10 | private String userName; 11 | private String password; 12 | private String email; 13 | private String unit; 14 | private String phoneNumber; 15 | private String place; 16 | private String sex; 17 | 18 | public String getSex(){ 19 | return sex; 20 | } 21 | 22 | public void setSex(String sex) { 23 | this.sex = sex; 24 | } 25 | 26 | public String getUserName() { 27 | return userName; 28 | } 29 | 30 | public void setUserName(String userName) { 31 | this.userName = userName; 32 | } 33 | 34 | public String getPassword() { 35 | return password; 36 | } 37 | 38 | public void setPassword(String password) { 39 | this.password = password; 40 | } 41 | 42 | public String getEmail() { 43 | return email; 44 | } 45 | 46 | public void setEmail(String email) { 47 | this.email = email; 48 | } 49 | 50 | public String getUnit() { 51 | return unit; 52 | } 53 | 54 | public void setUnit(String unit) { 55 | this.unit = unit; 56 | } 57 | 58 | public String getPhoneNumber() { 59 | return phoneNumber; 60 | } 61 | 62 | public void setPhoneNumber(String phoneNumber) { 63 | this.phoneNumber = phoneNumber; 64 | } 65 | 66 | public String getPlace() { 67 | return place; 68 | } 69 | 70 | public void setPlace(String place) { 71 | this.place = place; 72 | } 73 | } 74 | 75 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/nju/p/dao/ClientDaoTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao; 2 | 3 | import cn.edu.nju.p.po.ClientPO; 4 | import cn.edu.nju.p.vo.ClientVO; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | import org.springframework.test.context.web.WebAppConfiguration; 11 | 12 | import static org.junit.Assert.*; 13 | 14 | /** 15 | * Created by xihao on 17-6-9. 16 | */ 17 | @SpringBootTest 18 | @RunWith(SpringRunner.class) 19 | @WebAppConfiguration 20 | public class ClientDaoTest { 21 | 22 | @Autowired 23 | private ClientDao clientDao; 24 | 25 | @Test 26 | public void addUserTest(){ 27 | 28 | String userName = "我摘"; 29 | String password = "123"; 30 | String phoneNumber = "1asasdasd3927200q1qq0311q2"; 31 | 32 | clientDao.addClient(userName, phoneNumber,password); 33 | } 34 | 35 | @Test 36 | public void getTest(){ 37 | 38 | String phoneNumber = "13927200q1q0311q2"; 39 | System.out.println(clientDao.selectClient(phoneNumber).getUserName()); 40 | 41 | } 42 | 43 | // @Test 44 | // public void updateTest(){ 45 | // ClientPO clientPO = new ClientPO(); 46 | // ClientVO clientVO = new ClientVO(); 47 | // clientPO.setPhoneNumber("13927200q1q0311q" + 48 | // "2"); 49 | // clientPO.setEmail("asdasdasd"); 50 | // clientPO.setPlace("南京大学"); 51 | // clientPO.setUserName("asdasdasdasdasd"); 52 | // clientDao.updateClient(clientVO); 53 | // 54 | // } 55 | } -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/controller/stock/HomePageController.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.controller.stock; 2 | 3 | import cn.edu.nju.p.baseresult.BaseResult; 4 | import cn.edu.nju.p.exception.StockNoneException; 5 | import cn.edu.nju.p.service.exhibition.HomePageService; 6 | import cn.edu.nju.p.vo.StockMarketVO; 7 | import cn.edu.nju.p.vo.StockVO; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.PathVariable; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RestController; 13 | 14 | import java.time.LocalDate; 15 | import java.util.List; 16 | 17 | /** 18 | * Created by cyz on 2017/6/6. 19 | */ 20 | @RestController 21 | @RequestMapping("/homepage") 22 | public class HomePageController { 23 | 24 | @Autowired 25 | private HomePageService homePageService; 26 | 27 | @GetMapping("/market/{date}") 28 | public BaseResult getMarketVO(@PathVariable String date){ 29 | LocalDate currentDate = LocalDate.parse(date); 30 | StockMarketVO marketVO=null; 31 | try { 32 | StockMarketVO vo=homePageService.getMarketVO(currentDate); 33 | marketVO=vo; 34 | }catch (StockNoneException e){ 35 | e.printStackTrace(); 36 | } 37 | return new BaseResult<>(0, marketVO); 38 | } 39 | 40 | @GetMapping("/allstock/{date}") 41 | public BaseResult getAllStock(@PathVariable String date){ 42 | List voList=homePageService.getStockVO(LocalDate.parse(date)); 43 | return new BaseResult<>(0, voList); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/dao/daoutils/MysqlHelper_WYImpl.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao.daoutils; 2 | 3 | import cn.edu.nju.p.dao.StockDao; 4 | import cn.edu.nju.p.po.StockPO; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | 7 | import java.io.*; 8 | import java.sql.SQLException; 9 | 10 | /** 11 | * Created by dell- on 2017/6/9. 12 | */ 13 | public class MysqlHelper_WYImpl implements MysqlHelper_WY { 14 | 15 | public static final String FILE_PATH = "D://StockData//"; 16 | 17 | @Autowired 18 | private StockDao stockDao; 19 | 20 | @Override 21 | public void getDataFromCSV(String code) throws SQLException { 22 | String path = FILE_PATH + code + ".csv"; 23 | String encoding = "GBK"; 24 | FileInputStream is = null; 25 | InputStreamReader reader = null; 26 | BufferedReader br = null; 27 | try { 28 | File file = new File(path); 29 | // is = Thread.currentThread().getContextClassLoader().getResourceAsStream(path); 30 | is = new FileInputStream(file); 31 | reader = new InputStreamReader(is, encoding); 32 | br = new BufferedReader(reader); 33 | String content = br.readLine(); 34 | content = br.readLine();//读取文件标题 35 | 36 | } catch (Exception e) { 37 | e.printStackTrace(); 38 | } finally { 39 | if (br != null) { 40 | try{ 41 | br.close(); 42 | }catch (IOException ex){ 43 | ex.printStackTrace(); 44 | } 45 | } 46 | } 47 | } 48 | 49 | @Override 50 | public void insertIntoDataBase(String code, StockPO po) throws SQLException { 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/nju/p/dao/StockDaoImplTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao; 2 | 3 | import cn.edu.nju.p.dao.daoimpl.StockDaoImpl; 4 | import cn.edu.nju.p.po.StockPO; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | import org.springframework.test.context.web.WebAppConfiguration; 11 | 12 | import java.sql.SQLException; 13 | import java.time.LocalDate; 14 | import java.util.Map; 15 | import java.util.Set; 16 | 17 | /** 18 | * Created by dell- on 2017/6/11. 19 | */ 20 | @RunWith(SpringRunner.class) 21 | @WebAppConfiguration 22 | @SpringBootTest 23 | public class StockDaoImplTest { 24 | 25 | @Autowired 26 | StockDao stockDao; 27 | 28 | @Test 29 | public void insert() throws Exception { 30 | StockDaoImpl impl=new StockDaoImpl(); 31 | LocalDate date = LocalDate.of(2008, 8, 8); 32 | Map> map = StockDaoImpl.getMap(date); //得到2008年的数据 33 | 34 | Set>> entrySet=map.entrySet(); 35 | try{ 36 | for (Map.Entry> set : entrySet) { 37 | Map inMap = set.getValue(); 38 | Set> inSet = inMap.entrySet(); 39 | for (Map.Entry set2 : inSet) { 40 | StockPO po = set2.getValue(); 41 | stockDao.insertIntoStockDatabase("2017", po); 42 | } 43 | } 44 | } catch (SQLException e) { 45 | e.printStackTrace(); 46 | } 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/utils/ProtoStuffSerializerUtil.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.utils; 2 | 3 | import com.dyuproject.protostuff.LinkedBuffer; 4 | import com.dyuproject.protostuff.ProtostuffIOUtil; 5 | import com.dyuproject.protostuff.Schema; 6 | import com.dyuproject.protostuff.runtime.RuntimeSchema; 7 | 8 | /** 9 | * 序列化对象的工具类 10 | * 不使用java自带的序列化机制,使用ProtoStuff提高性能 11 | */ 12 | public class ProtoStuffSerializerUtil { 13 | 14 | /** 15 | * 序列化对象 16 | * @param obj 17 | * @param 18 | * @return 19 | */ 20 | public static byte[] serialize(T obj) { 21 | 22 | if (obj == null) { 23 | throw new RuntimeException("序列化对象为空!"); 24 | } 25 | 26 | Schema schema = (Schema) RuntimeSchema.getSchema(obj.getClass()); 27 | LinkedBuffer linkedBuffer = LinkedBuffer.allocate(2048 * 2048); 28 | byte[] protoStuff = ProtostuffIOUtil.toByteArray(obj, schema, linkedBuffer); 29 | linkedBuffer.clear(); 30 | return protoStuff; 31 | } 32 | 33 | /** 34 | * 反序列化对象 35 | * @param bytes 36 | * @param targetClass 37 | * @param 38 | * @return 39 | */ 40 | public static T deSerialize(byte[] bytes, Class targetClass) { 41 | 42 | if (bytes == null || bytes.length == 0) { 43 | throw new RuntimeException("反序列化时传递的byte数组为空!"); 44 | } 45 | T instance; 46 | try { 47 | instance = targetClass.newInstance(); 48 | } catch (InstantiationException | IllegalAccessException e) { 49 | throw new RuntimeException("反序列化时根据类型创建对象失败!", e); 50 | } 51 | 52 | Schema schema = RuntimeSchema.getSchema(targetClass); 53 | ProtostuffIOUtil.mergeFrom(bytes, instance, schema); 54 | return instance; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/nju/p/serviceimpl/MeanReversionServiceImplTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.serviceimpl; 2 | 3 | import cn.edu.nju.p.vo.MeanReversionParamVO; 4 | import org.apache.commons.math3.stat.descriptive.moment.Mean; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | import org.springframework.test.context.web.WebAppConfiguration; 11 | 12 | import java.time.LocalDate; 13 | 14 | import static org.junit.Assert.*; 15 | 16 | /** 17 | * Created by xihao on 17-6-7. 18 | */ 19 | @RunWith(SpringRunner.class) 20 | @WebAppConfiguration 21 | @SpringBootTest 22 | public class MeanReversionServiceImplTest { 23 | 24 | @Autowired 25 | private MeanReversionServiceImpl meanReversionService; 26 | 27 | 28 | @Test 29 | public void getResult() throws Exception { 30 | 31 | System.out.println(meanReversionService.getResult(new MeanReversionParamVO(10,10, LocalDate.of(2015,10,20),LocalDate.of(2016,10,20),10))); 32 | } 33 | 34 | @Test 35 | public void shortTest() throws Exception { 36 | 37 | System.out.println(meanReversionService.getResult(new MeanReversionParamVO(10,10, LocalDate.of(2015,10,20),LocalDate.of(2016,1,20),10))); 38 | } 39 | 40 | @Test 41 | public void shortTest2() throws Exception { 42 | 43 | System.out.println(meanReversionService.getResult(new MeanReversionParamVO(10,10, LocalDate.of(2014,10,20),LocalDate.of(2015,1,20),10))); 44 | } 45 | 46 | @Test 47 | public void shortTest3() throws Exception { 48 | 49 | System.out.println(meanReversionService.getResult(new MeanReversionParamVO(10,10, LocalDate.of(2016,10,20),LocalDate.of(2017,1,20),10))); 50 | 51 | } 52 | } -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/controller/strategysquare/StrategySquareController.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.controller.strategysquare; 2 | 3 | import cn.edu.nju.p.baseresult.BaseResult; 4 | import cn.edu.nju.p.dao.MyStrategyDao; 5 | import cn.edu.nju.p.dao.StrategySquareDao; 6 | import cn.edu.nju.p.po.StrategyCodePO; 7 | import com.alibaba.fastjson.JSONObject; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | import java.sql.SQLException; 12 | import java.util.List; 13 | 14 | /** 15 | * Created by dell- on 2017/6/15. 16 | */ 17 | @RestController 18 | @RequestMapping("/strategysquare") 19 | public class StrategySquareController { 20 | 21 | @Autowired 22 | private MyStrategyDao myStrategyDao; 23 | 24 | @Autowired 25 | private StrategySquareDao squareDao; 26 | 27 | @PostMapping("/square") 28 | public BaseResult shareStrategy(@RequestBody JSONObject strategyPo) { 29 | String phoneNumber = strategyPo.getString("phoneNumber"); 30 | // String code = strategyPo.getString("code"); 31 | String strategyName = strategyPo.getString("strategyName"); 32 | String code= myStrategyDao.getCode(phoneNumber,strategyName); 33 | squareDao.shareStrategy(phoneNumber, strategyName,code); 34 | return new BaseResult(0, "share a strategy sucessfully!"); 35 | } 36 | 37 | @GetMapping 38 | public BaseResult getAllStrategy() { 39 | List codePOS = squareDao.getAllStrategy(); 40 | return new BaseResult<>(0, codePOS); 41 | } 42 | 43 | @GetMapping("/deleteStrategy") 44 | public BaseResult deleteStock(@RequestParam String phoneNumber, @RequestParam String strategyName) { 45 | squareDao.deleteStrategy(phoneNumber, strategyName); 46 | return new BaseResult<>(0, "删除成功!"); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/controller/personnel/PersonnalInfoController.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.controller.personnel; 2 | 3 | import cn.edu.nju.p.baseresult.BaseResult; 4 | import cn.edu.nju.p.service.personnel.PersonnalInfoService; 5 | import com.alibaba.fastjson.JSONObject; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | /** 10 | * Created by cyz on 2017/6/6. 11 | */ 12 | @RestController 13 | @RequestMapping("/personnel") 14 | public class PersonnalInfoController { 15 | 16 | @Autowired 17 | private PersonnalInfoService personnalInfoService; 18 | 19 | @GetMapping("/{phoneNumber}") 20 | public BaseResult getClientInfo(@PathVariable String phoneNumber) { 21 | return new BaseResult<>(0,personnalInfoService.getClientInfo(phoneNumber)); 22 | } 23 | 24 | @PostMapping("/update") 25 | public BaseResult updateClientInfo(@RequestBody JSONObject object) { 26 | String phone_number = object.getString("phone_number"); 27 | String user_name= object.getString("user_name"); 28 | String sex = object.getString("sex"); 29 | String email = object.getString("email"); 30 | String unit = object.getString("unit"); 31 | String place = object.getString("place"); 32 | personnalInfoService.updateClient(phone_number, user_name, sex, email, unit, place); 33 | return new BaseResult(0, "update client info successfully!"); 34 | } 35 | 36 | 37 | @PostMapping("/updatePass") 38 | public BaseResult updatePass(@RequestBody JSONObject jsonObject){ 39 | String phone_number = jsonObject.getString("phone_number"); 40 | String password = jsonObject.getString("password"); 41 | personnalInfoService.updatePass(phone_number,password); 42 | return new BaseResult(0,"update password successfully!"); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/vo/StockVOWithSector.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.vo; 2 | 3 | import cn.edu.nju.p.po.StockPO; 4 | 5 | /** 6 | * Created by dell- on 2017/6/12. 7 | */ 8 | public class StockVOWithSector { 9 | 10 | private String name; 11 | private String code; 12 | private String sector; 13 | 14 | public StockVOWithSector(String name, String code, String sector) { 15 | this.name = name; 16 | this.code = code; 17 | this.sector = sector; 18 | } 19 | 20 | public StockVOWithSector(StockPO po) { 21 | this.name = po.getName(); 22 | this.code = po.getCode(); 23 | this.sector = setSector(this.code); 24 | } 25 | 26 | private String setSector(String code) { 27 | String sector = ""; 28 | if(code.startsWith("000")||code.startsWith("001") 29 | ||code.startsWith("600")||code.startsWith("601")){ 30 | sector="主板"; 31 | } 32 | else if(code.startsWith("002")){ 33 | sector="中小板"; 34 | }else if(code.startsWith("300")){ 35 | sector="创业板"; 36 | }else{ 37 | sector="没有找到对应板块"; 38 | } 39 | return sector; 40 | } 41 | 42 | public String getName() { 43 | return name; 44 | } 45 | 46 | public void setName(String name) { 47 | this.name = name; 48 | } 49 | 50 | public String getCode() { 51 | return code; 52 | } 53 | 54 | public void setCode(String code) { 55 | this.code = code; 56 | } 57 | 58 | public String getSector() { 59 | return sector; 60 | } 61 | 62 | @Override 63 | public String toString() { 64 | return "StockVOWithSector{" + 65 | "name='" + name + '\'' + 66 | ", code='" + code + '\'' + 67 | ", sector='" + sector + '\'' + 68 | '}'; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/controller/security/LoginController.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.controller.security; 2 | 3 | import cn.edu.nju.p.baseresult.BaseResult; 4 | import cn.edu.nju.p.cache.TokenManager; 5 | import cn.edu.nju.p.dao.AccountDao; 6 | import cn.edu.nju.p.dao.ClientDao; 7 | import cn.edu.nju.p.exception.PasswordNotMatchException; 8 | import cn.edu.nju.p.utils.EncryptHelper; 9 | import com.alibaba.fastjson.JSONObject; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.web.bind.annotation.PostMapping; 12 | import org.springframework.web.bind.annotation.RequestBody; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | import javax.servlet.ServletRequest; 17 | import javax.servlet.http.HttpServletResponse; 18 | 19 | /** 20 | * to login 21 | */ 22 | @RestController 23 | @RequestMapping("/login") 24 | public class LoginController { 25 | 26 | @Autowired 27 | private ClientDao clientDao; 28 | 29 | @Autowired 30 | private TokenManager tokenManager; 31 | 32 | @PostMapping 33 | public BaseResult login(@RequestBody JSONObject user) { 34 | 35 | String phoneNumber = user.getString("phoneNumber"); 36 | String password = user.getString("password"); 37 | String actualPassword = clientDao.selectClient(phoneNumber).getPassword(); 38 | if (!EncryptHelper.checkPassword(password, actualPassword)) { 39 | throw new PasswordNotMatchException(phoneNumber + " login failed!Password not match!"); 40 | } 41 | String token = tokenManager.createToken(phoneNumber); 42 | /* 43 | * 登录成功之后响应头会带有一个x-token的值,前端写进cookie,每次访问后端时都要带上x-token即可, 44 | * 使用aop拦截请求判断是否存在x-token完成验证 45 | * */ 46 | // response.addHeader("x-token",token); 47 | return new BaseResult(0, token); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/strategy/customstrategy/RuntimeCompileTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.strategy.customstrategy; 2 | 3 | import cn.edu.nju.p.strategy.customstrategy.javacompile.core.RuntimeCompiler; 4 | import cn.edu.nju.p.strategy.customstrategy.javacompile.util.RunCompileUtil; 5 | 6 | import java.io.IOException; 7 | import java.lang.reflect.InvocationTargetException; 8 | 9 | /** 10 | * Created by dell- on 2017/6/7. 11 | */ 12 | public class RuntimeCompileTest { 13 | 14 | public static void main(String args[]) throws IOException { 15 | StringBuffer str = new StringBuffer(); 16 | // str.append("package cn.edu.nju.p.controller.customstrategy;"); 17 | str.append("public class HelloWorld {"); 18 | str.append(" public static void main(String args[]) {"); 19 | str.append(" System.out.println(\"This is in my first java file\");"); 20 | str.append(" }"); 21 | str.append("}"); 22 | String code = str.toString(); 23 | System.out.println(code); 24 | String className = RunCompileUtil.getClassName(code); 25 | String fullClassName = RunCompileUtil.getFullClassName(code); 26 | 27 | // Compile source code to folder bin 28 | RuntimeCompiler rc = new RuntimeCompiler("-d", ".\\target\\classes"); 29 | boolean success = rc.compile(className, code); 30 | 31 | if (success) { 32 | try { 33 | Class.forName(fullClassName).getDeclaredMethod("main", new Class[] { 34 | String[].class 35 | }).invoke(null, new Object[] { 36 | null 37 | }); 38 | 39 | } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException 40 | | InvocationTargetException e) { 41 | System.err.println("Load class error: " + e); 42 | } 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/utils/EncryptHelper.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.utils; 2 | 3 | import java.security.MessageDigest; 4 | import java.security.NoSuchAlgorithmException; 5 | 6 | /** 7 | * helper to encrypt 8 | */ 9 | public class EncryptHelper { 10 | 11 | /** 12 | * to encrypt the password 13 | * @param raw the string to be encrypted 14 | * @return 15 | */ 16 | public static String getShaEncryption(String raw) { 17 | String type = "SHA-256"; 18 | return Encrypt(raw, type); 19 | } 20 | 21 | /** 22 | * to check the two password to see whether they are the same 23 | * @param rawPassword the raw password 24 | * @param actualPassword the password from database 25 | * @return 26 | */ 27 | public static boolean checkPassword(String rawPassword, String actualPassword) { 28 | String passwordEncrypted = Encrypt(rawPassword, "SHA-256"); 29 | return actualPassword.equals(passwordEncrypted); 30 | } 31 | 32 | private static String Encrypt(String strSrc, String encName) { 33 | MessageDigest md = null; 34 | String strDes = null; 35 | byte[] bt = strSrc.getBytes(); 36 | try { 37 | md = MessageDigest.getInstance(encName); 38 | md.update(bt); 39 | strDes = bytes2Hex(md.digest()); // to HexString 40 | } catch (NoSuchAlgorithmException e) { 41 | System.out.println("签名失败!"); 42 | return null; 43 | } 44 | return strDes; 45 | } 46 | 47 | private static String bytes2Hex(byte[] bts) { 48 | StringBuilder des = new StringBuilder(); 49 | String tmp; 50 | for (byte bt : bts) { 51 | tmp = (Integer.toHexString(bt & 0xFF)); 52 | if (tmp.length() == 1) { 53 | des.append("0"); 54 | } 55 | des.append(tmp); 56 | } 57 | return des.toString(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/strategy/customstrategy/javacompile/core/RuntimeCompiler.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.strategy.customstrategy.javacompile.core; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | import javax.tools.Diagnostic; 7 | import javax.tools.DiagnosticCollector; 8 | import javax.tools.FileObject; 9 | import javax.tools.JavaCompiler; 10 | import javax.tools.JavaFileObject; 11 | import javax.tools.ToolProvider; 12 | import javax.tools.JavaCompiler.CompilationTask; 13 | 14 | /** 15 | * Created by dell- on 2017/6/7. 16 | */ 17 | public class RuntimeCompiler { 18 | 19 | private List options = null; 20 | private JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 21 | private DiagnosticCollector diagnostics = new DiagnosticCollector(); 22 | private StringBuffer traceMsg = new StringBuffer(); 23 | 24 | public RuntimeCompiler(String... options) { 25 | // inital compile params 26 | if (options != null && options.length > 0) { 27 | this.options = Arrays.asList(options); 28 | } 29 | } 30 | 31 | public boolean compile(String className, String code) { 32 | JavaFileObject sourceFile = new StringJavaFileObject(className, code); 33 | Iterable compilationUnits = Arrays.asList(sourceFile); 34 | CompilationTask task = compiler.getTask(null, null, diagnostics, options, null, compilationUnits); 35 | boolean result = task.call(); 36 | 37 | // Record compile error messages 38 | for (Diagnostic diagnostic : diagnostics.getDiagnostics()) { 39 | traceMsg.append(diagnostic.getMessage(null)).append("\n"); 40 | traceMsg.append(String.format("Error on line %d in %s%n", diagnostic.getLineNumber(), 41 | ((FileObject) diagnostic.getSource()).toUri())); 42 | } 43 | 44 | return result; 45 | } 46 | 47 | public String getTraceMsg() { 48 | return traceMsg.toString(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/utils/DateHelper.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.utils; 2 | 3 | 4 | import cn.edu.nju.p.exception.DateNotOrderedException; 5 | import cn.edu.nju.p.utils.holiday.VacationDates; 6 | 7 | import java.time.DayOfWeek; 8 | import java.time.LocalDate; 9 | import java.util.function.Predicate; 10 | 11 | /** 12 | * 日期辅助类 13 | */ 14 | public class DateHelper { 15 | 16 | /** 17 | * 判断输入的两个日期是否符合前面小于后面的要求 18 | * @param beginDate 开始日期 19 | * @param endDate 结束日期 20 | * @return 开始日期在结束日期之前返回true,否则false 21 | */ 22 | private static boolean isOkDate(LocalDate beginDate, LocalDate endDate) { 23 | 24 | if(beginDate.isBefore(endDate)){ 25 | return true; 26 | } 27 | //不符合格式的话抛出异常 28 | DateNotOrderedException dateNotOrderedException = new DateNotOrderedException(beginDate+"不是在"+endDate+"之前"); 29 | throw new RuntimeException(dateNotOrderedException); 30 | } 31 | 32 | 33 | /** 34 | * 返回当前日期的上一个日期 35 | * @param date 日期 36 | * @param predicate 日期过滤的条件(没有的话可以传递a->true) 37 | * @return 上一个不是周末的(有效日期)日期 38 | */ 39 | public static LocalDate getLastDate(LocalDate date,Predicate predicate) { 40 | date = date.plusDays(-1); 41 | VacationDates vacationDates = new VacationDates(); 42 | while (date.getDayOfWeek() == DayOfWeek.SATURDAY || date.getDayOfWeek() == DayOfWeek.SUNDAY || vacationDates.isVacation(date) || 43 | !predicate.test(date)) { 44 | date = date.plusDays(-1); 45 | } 46 | return date; 47 | } 48 | 49 | /** 50 | * 获取去除周末的前interval个有效日期 51 | * @param sourceDate 当前日期 52 | * @param interval 间隔 53 | * @return 间隔前的有效日期 54 | */ 55 | public static LocalDate getIntervalEffectiveDate(LocalDate sourceDate,int interval){ 56 | 57 | LocalDate result = sourceDate; 58 | for (int i = 0; i < interval; i++) { 59 | result = getLastDate(result, a -> true); 60 | } 61 | return result; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/utils/ema/MACDUtils.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.utils.ema; 2 | 3 | import cn.edu.nju.p.utils.StockHelper; 4 | import cn.edu.nju.p.utils.redis.StockRedisDataUtils; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.cache.annotation.Cacheable; 7 | import org.springframework.stereotype.Component; 8 | 9 | import java.time.LocalDate; 10 | 11 | /** 12 | * The MACD calculator utils 13 | */ 14 | @Component 15 | public class MACDUtils { 16 | 17 | /* @Autowired 18 | private StockDao stockDao;*/ 19 | 20 | @Autowired 21 | private StockRedisDataUtils stockRedisDataUtils; 22 | 23 | @Autowired 24 | private StockHelper stockHelper; 25 | 26 | @Cacheable(value = "emaValue") 27 | public double getEmaValue(int emaValue,LocalDate currentDate,String stockCode) { 28 | 29 | currentDate = stockHelper.getFirstValidDate(stockCode, currentDate); 30 | 31 | double close = stockRedisDataUtils.getStockClose(stockCode, currentDate); //当日收盘价 32 | 33 | if (emaValue == 1) { 34 | //last efficient date 35 | return close; 36 | } 37 | 38 | return (2 * close + 39 | (emaValue - 1) * getEmaValue(emaValue - 1 40 | , stockHelper.getFirstValidDate(stockCode,currentDate.minusDays(1)) 41 | , stockCode)) 42 | / (emaValue + 1); 43 | } 44 | 45 | 46 | @Cacheable("deaValue") 47 | public double getDea(int deaValue, LocalDate currentDate, String stockCode) { 48 | 49 | currentDate = stockHelper.getFirstValidDate(stockCode, currentDate); 50 | 51 | double diff = getEmaValue(12, currentDate, stockCode) - getEmaValue(26, currentDate, stockCode); 52 | 53 | if (deaValue == 1) { 54 | return diff; 55 | } 56 | 57 | return (2 * diff + (deaValue - 1) * getDea(deaValue - 1 58 | , stockHelper.getFirstValidDate(stockCode,currentDate.minusDays(1)) 59 | , stockCode)) 60 | / (deaValue + 1); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/dao/MyStrategyDao.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao; 2 | 3 | import cn.edu.nju.p.po.SaveStrategyPO; 4 | import cn.edu.nju.p.po.StrategyCodePO; 5 | import org.apache.ibatis.annotations.*; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Created by cyz on 2017/6/14. 12 | */ 13 | 14 | 15 | @Mapper 16 | @Repository 17 | public interface MyStrategyDao { 18 | 19 | @Select("select * from my_strategy where phone_number = #{phoneNumber}") 20 | List getMyStrategy(String phoneNumber); 21 | 22 | @Insert("insert into my_strategy (phone_number,code,strategy_name) values(#{phoneNumber},#{code},#{strategyName})") 23 | void addMyStrategy(@Param("phoneNumber") String phoneNumber, @Param("code") String code, @Param("strategyName") String strategyName); 24 | 25 | @Insert("insert into my_save (phone_number,strategy_name,strategy_url) values(#{phoneNumber},#{strategyName},#{strategyURL})") 26 | void addSaveStrategy(@Param("phoneNumber") String phoneNumber,@Param("strategyName") String strategyName,@Param("strategyURL")String strategyURL); 27 | 28 | @Select("select strategy_name from my_strategy where phone_number = #{phoneNumber}") 29 | List getMyStrategyName(String phoneNumber); 30 | 31 | @Select("select code from my_strategy where phone_number=#{phoneNumber} and locate(strategy_name,#{strategyName}) > 0") 32 | String getCode(@Param("phoneNumber") String phoneNumber, @Param("strategyName") String strategyName); 33 | 34 | @Delete("delete from my_strategy where phone_number=#{phoneNumber} and strategy_name=#{strategyName}") 35 | void deleteStrategy(@Param("phoneNumber") String phoneNumber, @Param("strategyName") String strategyName); 36 | 37 | @Select("select * from my_save where phone_number=#{phoneNumber}") 38 | List getMySaveStrategyList(String phoneNumber); 39 | 40 | @Delete("delete from my_save where phone_number=#{phoneNumber} and strategy_name=#{strategyName}") 41 | void deleteSaveStrategy(@Param("phoneNumber") String phoneNumber,@Param("strategyName")String strategyName); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/dao/daoutils/UpdateTodayStockRun.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao.daoutils; 2 | 3 | import org.quartz.*; 4 | import org.quartz.impl.StdSchedulerFactory; 5 | 6 | import java.util.Date; 7 | 8 | /** 9 | * Created by dell- on 2017/6/13. 10 | */ 11 | 12 | /** 13 | * 调用定时执行任务的类 14 | */ 15 | public class UpdateTodayStockRun { 16 | 17 | public void Run() { 18 | //用工厂模式构建Scheduler的Factory,其中STD为Quartz默认的Factory 19 | SchedulerFactory schedulerfactory=new StdSchedulerFactory(); 20 | 21 | //通过schedulerFactory获取一个调度器对象 22 | Scheduler scheduler=null; 23 | 24 | try{ 25 | //通过schedulerFactory获取一个调度器 26 | scheduler=schedulerfactory.getScheduler(); 27 | 28 | //创建jobDetail实例,绑定Job实现类 29 | //指明job的名称,所在组的名称,以及绑定job类 30 | JobDetail job= JobBuilder.newJob(UpdateTodayStockJob.class).withIdentity("job2", "group2").build(); 31 | 32 | //定义调度触发规则 33 | //使用simpleTrigger规则 34 | // Trigger trigger=TriggerBuilder.newTrigger().withIdentity("simpleTrigger", "triggerGroup") 35 | // .withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(1).withRepeatCount(8)) 36 | // .startNow().build(); 37 | 38 | //使用cornTrigger规则 每天9点执行 39 | Trigger trigger=TriggerBuilder.newTrigger().withIdentity("simpleTrigger2", "triggerGroup2") 40 | .withSchedule(CronScheduleBuilder.cronSchedule("0 0/30 9-16 * * ?") //从早上9点到下午四点每隔30分钟执行一次任务 41 | ).build(); 42 | 43 | //把作业和触发器注册到任务调度中 44 | scheduler.scheduleJob(job, trigger); 45 | 46 | //启动调度 47 | scheduler.start(); 48 | 49 | //任务结束后结束 50 | //scheduler.shutdown(true); 51 | }catch(Exception e){ 52 | e.printStackTrace(); 53 | } 54 | } 55 | 56 | public static void main(String[] args) { 57 | UpdateTodayStockRun runner = new UpdateTodayStockRun(); 58 | try { 59 | runner.Run(); 60 | } catch (Exception e) { 61 | e.printStackTrace(); 62 | } 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/controller/exhibition/CompanyController.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.controller.exhibition; 2 | 3 | import cn.edu.nju.p.baseresult.BaseResult; 4 | import cn.edu.nju.p.dao.CompanyDao; 5 | import cn.edu.nju.p.dao.TestStockDao; 6 | import cn.edu.nju.p.dao.daoutils.GetDataFromSinaUtil; 7 | import cn.edu.nju.p.po.StockPO; 8 | import cn.edu.nju.p.po.TestStockPO; 9 | import cn.edu.nju.p.vo.CompanyAnnouncementVO; 10 | import cn.edu.nju.p.vo.CompanyInfoVO; 11 | import cn.edu.nju.p.vo.CompanyNewsVO; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.web.bind.annotation.*; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * Created by soft on 2017/5/17. 19 | */ 20 | @RestController 21 | @RequestMapping("/company") 22 | public class CompanyController { 23 | 24 | @Autowired 25 | private CompanyDao companyDao; 26 | 27 | @Autowired 28 | private TestStockDao testStockDao; 29 | 30 | @GetMapping("/info/{code}") 31 | public BaseResult getCompanyInfo(@PathVariable String code) { 32 | CompanyInfoVO infoVO = companyDao.getCompanyInfoVO(code); 33 | return new BaseResult<>(0, infoVO); 34 | } 35 | 36 | @GetMapping("/news/{code}") 37 | public BaseResult getCompanyNews(@PathVariable String code) { 38 | List newsVOS = companyDao.getCompanyNewsVOList(code); 39 | return new BaseResult<>(0, newsVOS); 40 | } 41 | 42 | @GetMapping("/details/{code}") 43 | public BaseResult getStockDetails(@PathVariable String code) { 44 | StockPO po = GetDataFromSinaUtil.getInstance().getStockCurrentData(code, "sz"); 45 | return new BaseResult<>(0, po); 46 | } 47 | 48 | @GetMapping("/announcement/{code}") 49 | public BaseResult getStockAnnouncement(@PathVariable String code) { 50 | List announcementVOS = companyDao.getCompanyAnnouncementVOList(code); 51 | return new BaseResult<>(0, announcementVOS); 52 | } 53 | 54 | @GetMapping("/diagnosis/{code}") 55 | public BaseResult getStockDiagnosis(@PathVariable String code) { 56 | TestStockPO po = testStockDao.getTestStockPO(code); 57 | return new BaseResult<>(0, po); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/QuantradingApplication.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p; 2 | 3 | import cn.edu.nju.p.dao.StockDao; 4 | import cn.edu.nju.p.dao.daoutils.InsertTodayStockRun; 5 | import cn.edu.nju.p.dao.daoutils.UpdateTodayStockRun; 6 | import cn.edu.nju.p.utils.CalculateHelper; 7 | import cn.edu.nju.p.utils.beans.ToolSpring; 8 | import org.apache.ibatis.session.Configuration; 9 | import org.apache.tomcat.jdbc.pool.DataSource; 10 | import org.mybatis.spring.SqlSessionFactoryBean; 11 | import org.mybatis.spring.boot.autoconfigure.SpringBootVFS; 12 | import org.springframework.boot.SpringApplication; 13 | import org.springframework.boot.autoconfigure.SpringBootApplication; 14 | import org.springframework.cache.annotation.EnableCaching; 15 | import org.springframework.context.annotation.Bean; 16 | import org.springframework.context.annotation.EnableAspectJAutoProxy; 17 | import org.springframework.core.io.ClassPathResource; 18 | import org.springframework.core.io.Resource; 19 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 20 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 21 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 22 | 23 | import java.time.LocalDate; 24 | 25 | @SpringBootApplication 26 | @EnableCaching 27 | public class QuantradingApplication { 28 | 29 | public static void main(String[] args) { 30 | 31 | SpringApplication.run(QuantradingApplication.class, args); 32 | InsertTodayStockRun insertRun = new InsertTodayStockRun(); 33 | UpdateTodayStockRun updateRun = new UpdateTodayStockRun(); 34 | try { 35 | insertRun.insertDaily(); 36 | updateRun.Run(); 37 | } catch (Exception e) { 38 | e.printStackTrace(); 39 | } 40 | 41 | // /*StockDao stockDao = ToolSpring.getBeans(StockDao.class); 42 | // System.out.println(stockDao.getStockClose("000001", LocalDate.of(2012,2,3)));*/ 43 | } 44 | 45 | 46 | @Bean 47 | public CalculateHelper calculateHelper() { 48 | 49 | return new CalculateHelper(0.0023); 50 | } 51 | 52 | @Bean 53 | public WebMvcConfigurer corsConfigurer() { 54 | return new WebMvcConfigurerAdapter() { 55 | @Override 56 | public void addCorsMappings(CorsRegistry registry) { 57 | registry.addMapping("/**").allowedOrigins("*"); 58 | } 59 | }; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/controller/stock/StockController.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.controller.stock; 2 | 3 | import cn.edu.nju.p.baseresult.BaseResult; 4 | import cn.edu.nju.p.dao.StockDao; 5 | import cn.edu.nju.p.enums.ErrorCode; 6 | import cn.edu.nju.p.po.StockPO; 7 | import cn.edu.nju.p.service.strategy.SectorService; 8 | import cn.edu.nju.p.utils.StockHelper; 9 | import cn.edu.nju.p.vo.StockVOWithSector; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.web.bind.annotation.GetMapping; 12 | import org.springframework.web.bind.annotation.PathVariable; 13 | import org.springframework.web.bind.annotation.RequestParam; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | /** 20 | * the stock controller 21 | */ 22 | @RestController 23 | public class StockController { 24 | 25 | @Autowired 26 | private SectorService sectorService; 27 | 28 | @Autowired 29 | private StockDao stockDao; 30 | 31 | @Autowired 32 | private StockHelper stockHelper; 33 | 34 | @GetMapping("/stock") 35 | public BaseResult getSectorStocks(@RequestParam String sector) { 36 | List stocks = sectorService.getStocks(sector); 37 | return new BaseResult<>(0, stocks); 38 | } 39 | 40 | @GetMapping("/check/{code}") 41 | public BaseResult checkStock(@PathVariable String code) { 42 | if (stockHelper.codeExists(code)) { 43 | return new BaseResult<>(0, true); 44 | } else { 45 | return new BaseResult<>(ErrorCode.STOCK_NOT_FOUND.getErrorCode(), code + " not found!"); 46 | } 47 | } 48 | 49 | @GetMapping("/stockName/{code}") 50 | public BaseResult getStockName(@PathVariable String code){ 51 | String name = sectorService.getStockName(code); 52 | return new BaseResult<>(0, name); 53 | } 54 | 55 | @GetMapping("/stockWithSector/{date}") 56 | public BaseResult getStockVOWithSector(@PathVariable String date) { 57 | List poList = stockDao.getPOList(date); 58 | List voList = new ArrayList<>(); 59 | for (StockPO po : poList) { 60 | voList.add(new StockVOWithSector(po)); 61 | } 62 | return new BaseResult<>(0, voList); 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/vo/ClientVO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.vo; 2 | 3 | import cn.edu.nju.p.po.ClientPO; 4 | import cn.edu.nju.p.po.StockPO; 5 | 6 | /** 7 | * Created by cyz on 2017/6/10. 8 | */ 9 | public class ClientVO { 10 | private String user_name; 11 | private String password; 12 | private String email; 13 | private String unit; 14 | private String phone_number; 15 | private String place; 16 | private String sex; 17 | 18 | public ClientVO(String phoneNumber,String user_name,String sex,String email,String unit,String place,String password){ 19 | this.user_name = user_name; 20 | this.password = password; 21 | this.email = email; 22 | this.unit = unit; 23 | this.phone_number = phoneNumber; 24 | this.place = place; 25 | this.sex = sex; 26 | } 27 | public String getSex(){return sex;} 28 | 29 | public void setSex(String sex) {this.sex = sex;} 30 | 31 | public String getUserName() { 32 | return user_name; 33 | } 34 | 35 | public void setUserName(String userName) { 36 | this.user_name = userName; 37 | } 38 | 39 | public String getPassword() { 40 | return password; 41 | } 42 | 43 | public void setPassword(String password) { 44 | this.password = password; 45 | } 46 | 47 | public String getEmail() { 48 | return email; 49 | } 50 | 51 | public void setEmail(String email) { 52 | this.email = email; 53 | } 54 | 55 | public String getUnit() { 56 | return unit; 57 | } 58 | 59 | public void setUnit(String unit) { 60 | this.unit = unit; 61 | } 62 | 63 | public String getPhoneNumber() { 64 | return phone_number; 65 | } 66 | 67 | public void setPhoneNumber(String phoneNumber) { 68 | this.phone_number = phoneNumber; 69 | } 70 | 71 | public String getPlace() { 72 | return place; 73 | } 74 | 75 | public void setPlace(String place) { 76 | this.place = place; 77 | } 78 | 79 | @Override 80 | public String toString() { 81 | return "ClientVO{" + 82 | "phoneNumber='" + phone_number + '\'' + 83 | ", userName=" + user_name + 84 | ", password=" + password + 85 | ", sex=" + sex + 86 | ", email=" + email + 87 | ", unit=" + unit + 88 | ", place=" + place + 89 | '}'; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/dao/daoimpl/MarketPerformanceDaoImpl.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao.daoimpl; 2 | 3 | import cn.edu.nju.p.dao.MarketPerformanceDao; 4 | import cn.edu.nju.p.po.*; 5 | import org.jsoup.Jsoup; 6 | import org.jsoup.nodes.Document; 7 | import org.jsoup.nodes.Element; 8 | import org.jsoup.select.Elements; 9 | 10 | import java.io.IOException; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | /** 15 | * Created by dell- on 2017/6/8. 16 | */ 17 | public class MarketPerformanceDaoImpl implements MarketPerformanceDao { 18 | 19 | private static final String THS_URL = "http://stockpage.10jqka.com.cn/"; 20 | 21 | /** 22 | * Jsoup初始化 23 | * @param URL 24 | * @return 25 | */ 26 | private Document getDocument(String URL) { 27 | try{ 28 | return Jsoup.connect(URL).get(); 29 | } catch (IOException e) { 30 | e.printStackTrace(); 31 | } 32 | return null; 33 | } 34 | 35 | public static String createParam(int type) { 36 | String result = ""; 37 | switch (type) { 38 | case 0: 39 | result = "order_199112_desc"; 40 | break; 41 | case 1: 42 | result = "order_199112_asc"; 43 | break; 44 | case 2: 45 | result = "order_13_desc"; 46 | break; 47 | case 3: 48 | result = "order_1968584_desc"; 49 | break; 50 | case 4: 51 | result = "order_1771976_desc"; 52 | break; 53 | case 5: 54 | result = "order_2034120_desc"; 55 | break; 56 | default: 57 | break; 58 | } 59 | return result; 60 | } 61 | 62 | @Override 63 | public List getSameMarketStockInfo(String code, int type) { 64 | String param = MarketPerformanceDaoImpl.createParam(type); 65 | List list = new ArrayList(); 66 | 67 | Document doc = getDocument(THS_URL + code + "/"); 68 | Elements html = doc.select("[class=hydb_column a_blue_d_all data_table]");//选择公司新闻所在的class 69 | // Element html = doc.head(); 70 | Elements data=html.select("tr[class$=row_0]"); 71 | System.out.println(doc); 72 | return null; 73 | } 74 | 75 | 76 | public static void main(String[] args) { 77 | MarketPerformanceDaoImpl test=new MarketPerformanceDaoImpl(); 78 | test.getSameMarketStockInfo("000001", 0); 79 | 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/filter/CorsFilter.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.filter; 2 | 3 | 4 | import javax.servlet.*; 5 | import javax.servlet.http.HttpServletRequest; 6 | import javax.servlet.http.HttpServletResponse; 7 | import java.io.IOException; 8 | 9 | /** 10 | * a filter to handle cross domain request 11 | */ 12 | public class CorsFilter implements Filter { 13 | 14 | /*private String allowOrigin; 15 | private String allowMethods; 16 | private String allowCredentials; 17 | private String allowHeaders; 18 | private String exposeHeaders;*/ 19 | 20 | @Override 21 | public void init(FilterConfig filterConfig) throws ServletException { 22 | /*allowOrigin = filterConfig.getInitParameter("allowOrigin"); 23 | allowMethods = filterConfig.getInitParameter("allowMethods"); 24 | allowCredentials = filterConfig.getInitParameter("allowCredentials"); 25 | allowHeaders = filterConfig.getInitParameter("allowHeaders"); 26 | exposeHeaders = filterConfig.getInitParameter("exposeHeaders");*/ 27 | } 28 | 29 | @Override 30 | public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { 31 | HttpServletRequest request = (HttpServletRequest) req; 32 | HttpServletResponse response = (HttpServletResponse) res; 33 | /*if (StringUtils.isNotEmpty(allowOrigin)) { 34 | List allowOriginList = Arrays.asList(allowOrigin.split(",")); 35 | if (allowOriginList==null || allowOriginList.size()==0) { 36 | String currentOrigin = request.getHeader("Origin"); 37 | if (allowOriginList.contains(currentOrigin)) { 38 | response.setHeader("Access-Control-Allow-Origin", currentOrigin); 39 | } 40 | } 41 | }*/ 42 | response.setHeader("Access-Control-Allow-Origin","*"); 43 | 44 | /*if (StringUtils.isNotEmpty(allowMethods)) { 45 | response.setHeader("Access-Control-Allow-Methods", allowMethods); 46 | } 47 | if (StringUtils.isNotEmpty(allowCredentials)) { 48 | response.setHeader("Access-Control-Allow-Credentials", allowCredentials); 49 | } 50 | if (StringUtils.isNotEmpty(allowHeaders)) { 51 | response.setHeader("Access-Control-Allow-Headers", allowHeaders); 52 | } 53 | if (StringUtils.isNotEmpty(exposeHeaders)) { 54 | response.setHeader("Access-Control-Expose-Headers", exposeHeaders); 55 | }*/ 56 | chain.doFilter(req, res); 57 | } 58 | 59 | @Override 60 | public void destroy() { 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/po/StockMarketPO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.po; 2 | 3 | 4 | /** 5 | * 某一日股票市场的需要显示的所有数据 6 | * volume 成交量 7 | * amountOfLimitUp 涨停股票的数目 8 | * amountOfLimitDown 跌停股票的数目 9 | * amountOf5PercentUp 涨幅超过5%的股票数目 10 | * amountOf5PercentDown 跌幅超过5%的股票数目 11 | * amountOf5PercentUptolastClose 开盘减去收盘大于5%*上个收盘指数的股票数目 12 | * amountOf5PercentDowntolastClose 开盘减去收盘小于-5%*上个收盘指数的股票数目 13 | */ 14 | public class StockMarketPO { 15 | private long volume; 16 | private int amountOfLimitUp; 17 | private int amountOfLimitDown; 18 | private int amountOf5PercentUp; 19 | private int amountOf5PercentDown; 20 | private int amountOf5PercentUptolastClose; 21 | private int amountOf5PercentDowntolastClose; 22 | 23 | public long getVolume() { 24 | return volume; 25 | } 26 | 27 | public int getAmountOfLimitUp() { 28 | return amountOfLimitUp; 29 | } 30 | 31 | public int getAmountOfLimitDown() { 32 | return amountOfLimitDown; 33 | } 34 | 35 | public int getAmountOf5PercentUp() { 36 | return amountOf5PercentUp; 37 | } 38 | 39 | public int getAmountOf5PercentDown() { 40 | return amountOf5PercentDown; 41 | } 42 | 43 | public int getAmountOf5PercentUptolastClose() { 44 | return amountOf5PercentUptolastClose; 45 | } 46 | 47 | public int getAmountOf5PercentDowntolastClose() { 48 | return amountOf5PercentDowntolastClose; 49 | } 50 | 51 | public StockMarketPO(long volume, int amountOfLimitUp, int amountOfLimitDown, int amountOf5PercentUp, int amountOf5PercentDown, int amountOf5PercentUptolastClose, int amountOf5PercentDowntolastClose) { 52 | this.volume = volume; 53 | this.amountOfLimitUp = amountOfLimitUp; 54 | this.amountOfLimitDown = amountOfLimitDown; 55 | this.amountOf5PercentUp = amountOf5PercentUp; 56 | this.amountOf5PercentDown = amountOf5PercentDown; 57 | this.amountOf5PercentUptolastClose = amountOf5PercentUptolastClose; 58 | this.amountOf5PercentDowntolastClose = amountOf5PercentDowntolastClose; 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return "StockMarketPO{" + 64 | "volume=" + volume + 65 | ", amountOfLimitUp=" + amountOfLimitUp + 66 | ", amountOfLimitDown=" + amountOfLimitDown + 67 | ", amountOf5PercentUp=" + amountOf5PercentUp + 68 | ", amountOf5PercentDown=" + amountOf5PercentDown + 69 | ", amountOf5PercentUptolastClose=" + amountOf5PercentUptolastClose + 70 | ", amountOf5PercentDowntolastClose=" + amountOf5PercentDowntolastClose + 71 | '}'; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/vo/StockMarketVO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.vo; 2 | 3 | 4 | /** 5 | * Created by Shinelon on 2017/3/6. 6 | * 某一日股票市场的需要显示的所有数据 7 | * volume 成交量 8 | * amountOfLimitUp 涨停股票的数目 9 | * amountOfLimitDown 跌停股票的数目 10 | * amountOf5PercentUp 涨幅超过5%的股票数目 11 | * amountOf5PercentDown 跌幅超过5%的股票数目 12 | * amountOf5PercentUptolastClose 开盘减去收盘大于5%*上个收盘指数的股票数目 13 | * amountOf5PercentDowntolastClose 开盘减去收盘小于-5%*上个收盘指数的股票数目 14 | */ 15 | public class StockMarketVO { 16 | 17 | private long volume; 18 | private int amountOfLimitUp; 19 | private int amountOfLimitDown; 20 | private int amountOf5PercentUp; 21 | private int amountOf5PercentDown; 22 | private int amountOf5PercentUptolastClose; 23 | private int amountOf5PercentDowntolastClose; 24 | 25 | public long getVolume() { 26 | return volume; 27 | } 28 | 29 | public int getAmountOfLimitUp() { 30 | return amountOfLimitUp; 31 | } 32 | 33 | public int getAmountOfLimitDown() { 34 | return amountOfLimitDown; 35 | } 36 | 37 | public int getAmountOf5PercentUp() { 38 | return amountOf5PercentUp; 39 | } 40 | 41 | public int getAmountOf5PercentDown() { 42 | return amountOf5PercentDown; 43 | } 44 | 45 | public int getAmountOf5PercentUptolastClose() { 46 | return amountOf5PercentUptolastClose; 47 | } 48 | 49 | public int getAmountOf5PercentDowntolastClose() { 50 | return amountOf5PercentDowntolastClose; 51 | } 52 | 53 | public StockMarketVO(long volume, int amountOfLimitUp, int amountOfLimitDown, int amountOf5PercentUp, int amountOf5PercentDown, int amountOf5PercentUptolastClose, int amountOf5PercentDowntolastClose) { 54 | this.volume = volume; 55 | this.amountOfLimitUp = amountOfLimitUp; 56 | this.amountOfLimitDown = amountOfLimitDown; 57 | this.amountOf5PercentUp = amountOf5PercentUp; 58 | this.amountOf5PercentDown = amountOf5PercentDown; 59 | this.amountOf5PercentUptolastClose = amountOf5PercentUptolastClose; 60 | this.amountOf5PercentDowntolastClose = amountOf5PercentDowntolastClose; 61 | } 62 | 63 | 64 | @Override 65 | public String toString() { 66 | return "StockMarketVO{" + 67 | "volume=" + volume + 68 | ", amountOfLimitUp=" + amountOfLimitUp + 69 | ", amountOfLimitDown=" + amountOfLimitDown + 70 | ", amountOf5PercentUp=" + amountOf5PercentUp + 71 | ", amountOf5PercentDown=" + amountOf5PercentDown + 72 | ", amountOf5PercentUptolastClose=" + amountOf5PercentUptolastClose + 73 | ", amountOf5PercentDowntolastClose=" + amountOf5PercentDowntolastClose + 74 | '}'; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/exceptionhandler/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.exceptionhandler; 2 | 3 | import cn.edu.nju.p.baseresult.BaseResult; 4 | import cn.edu.nju.p.enums.ErrorCode; 5 | import cn.edu.nju.p.exception.DateNotOrderedException; 6 | import cn.edu.nju.p.exception.PasswordNotMatchException; 7 | import cn.edu.nju.p.exception.StockNoneException; 8 | import cn.edu.nju.p.exception.StockNotFoundException; 9 | import org.springframework.dao.DuplicateKeyException; 10 | import org.springframework.http.HttpStatus; 11 | import org.springframework.stereotype.Component; 12 | import org.springframework.web.bind.annotation.ControllerAdvice; 13 | import org.springframework.web.bind.annotation.ExceptionHandler; 14 | import org.springframework.web.bind.annotation.ResponseBody; 15 | import org.springframework.web.bind.annotation.ResponseStatus; 16 | 17 | import java.time.format.DateTimeParseException; 18 | 19 | /** 20 | * controller exception handler 21 | */ 22 | @ControllerAdvice 23 | @Component 24 | @ResponseBody 25 | public class GlobalExceptionHandler { 26 | 27 | @ExceptionHandler(DateNotOrderedException.class) 28 | @ResponseStatus(HttpStatus.BAD_REQUEST) 29 | public BaseResult handleDateNotOrdered(DateNotOrderedException de) { 30 | String message = de.getMessage(); 31 | return new BaseResult(ErrorCode.DATE_NOT_ORDERED.getErrorCode(), message); 32 | } 33 | 34 | @ExceptionHandler(DateTimeParseException.class) 35 | @ResponseStatus(HttpStatus.BAD_REQUEST) 36 | public BaseResult handleDateParseException(DateTimeParseException de) { 37 | String message = de.getMessage(); 38 | return new BaseResult(ErrorCode.DATE_PARSE_ERROR.getErrorCode(), message); 39 | } 40 | 41 | @ExceptionHandler(StockNotFoundException.class) 42 | @ResponseStatus(HttpStatus.NOT_FOUND) 43 | public BaseResult handleStockNotFound(StockNotFoundException se) { 44 | String message = se.getMessage(); 45 | return new BaseResult(ErrorCode.STOCK_NOT_FOUND.getErrorCode(), message); 46 | } 47 | 48 | @ExceptionHandler 49 | @ResponseStatus(HttpStatus.BAD_REQUEST) 50 | public BaseResult handlePasswordNotMatch(PasswordNotMatchException pe){ 51 | String message = pe.getMessage(); 52 | return new BaseResult(ErrorCode.PASSWORD_NOT_MATCH.getErrorCode(), message); 53 | } 54 | 55 | @ExceptionHandler 56 | @ResponseStatus(HttpStatus.BAD_REQUEST) 57 | public BaseResult handleNoneStock(StockNoneException se) { 58 | String message = se.getMessage(); 59 | return new BaseResult(ErrorCode.STOCK_NONE.getErrorCode(), message); 60 | } 61 | 62 | @ExceptionHandler 63 | // @ResponseStatus(HttpStatus.BAD_REQUEST) 64 | public BaseResult handleDuplicateException(DuplicateKeyException de) { 65 | String message = de.getMessage(); 66 | return new BaseResult(ErrorCode.MY_STOCK_DUPLI_ERROR.getErrorCode(), message); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/po/KLinePO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.po; 2 | 3 | import java.time.LocalDate; 4 | 5 | /** 6 | * KLine需要使用到的VO 7 | * name 股票名称 8 | * code 股票代码 9 | * date 日期 10 | * isGoHigh 是否走高 11 | * low 最低指数 12 | * high 最高指数 13 | * open 开盘指数 14 | * close 收盘指数 15 | * range 最高指数与最低指数之差 16 | * dBetweenOpenAndClose 开盘收盘指数之差的绝对值 17 | */ 18 | 19 | public class KLinePO { 20 | 21 | private String name; 22 | private String code; 23 | private LocalDate date; 24 | private boolean isGoHigh; 25 | private double low; 26 | private double high; 27 | private double open; 28 | private double close; 29 | private double range; 30 | private double dBetweenOpenAndClose; 31 | private int volume; 32 | 33 | public KLinePO(String name,String code, LocalDate date, boolean isGoHigh, double low, double high, double open, double close, double range, double dBetweenOpenAndClose,int volume){ 34 | this.name = name; 35 | this.code = code; 36 | this.date = date; 37 | this.isGoHigh = isGoHigh; 38 | this.low = low; 39 | this.high = high; 40 | this.open = open; 41 | this.close = close; 42 | this.range = range; 43 | this.dBetweenOpenAndClose = dBetweenOpenAndClose; 44 | this.volume = volume; 45 | } 46 | 47 | public String getName() { 48 | return name; 49 | } 50 | 51 | public LocalDate getDate() { 52 | return date; 53 | } 54 | 55 | public double getLow() { 56 | return low; 57 | } 58 | 59 | public double getHigh() { 60 | return high; 61 | } 62 | 63 | public double getOpen() { 64 | return open; 65 | } 66 | 67 | public double getClose() { 68 | return close; 69 | } 70 | 71 | public String getCode() { 72 | return code; 73 | } 74 | 75 | public boolean isGoHigh() { 76 | return isGoHigh; 77 | } 78 | 79 | public double getRange() { 80 | return range; 81 | } 82 | 83 | public double getdBetweenOpenAndClose() { 84 | return dBetweenOpenAndClose; 85 | } 86 | 87 | public int getVolume(){ 88 | return this.volume; 89 | } 90 | 91 | @Override 92 | public String toString() { 93 | return "KLinePO{" + 94 | "name='" + name + '\'' + 95 | ", code='" + code + '\'' + 96 | ", date='" + date + '\'' + 97 | ", isGoHigh=" + isGoHigh + 98 | ", low=" + low + 99 | ", high=" + high + 100 | ", open=" + open + 101 | ", close=" + close + 102 | ", range=" + range + 103 | ", dBetweenOpenAndClose=" + dBetweenOpenAndClose + 104 | ", volume=" + volume + 105 | '}'; 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/vo/MeanReversionParamForBestDayVO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.vo; 2 | 3 | import java.time.LocalDate; 4 | import java.util.List; 5 | 6 | /** 7 | * Created by xihao on 17-4-15. 8 | */ 9 | public class MeanReversionParamForBestDayVO { 10 | 11 | private List stockPool; 12 | 13 | private LocalDate beginDate; 14 | 15 | private LocalDate endDate; 16 | 17 | private int holdingNum; //每次持有的股票数目 18 | 19 | private int meanDayNum; //使用几日均线作为标准 20 | 21 | /** 22 | * 自己输入股票池 23 | * @param stockPool 24 | * @param beginDate 25 | * @param endDate 26 | * @param holdingNum 27 | * @param meanDayNum 28 | */ 29 | public MeanReversionParamForBestDayVO(List stockPool, LocalDate beginDate, LocalDate endDate, int holdingNum, int meanDayNum) { 30 | this.stockPool = stockPool; 31 | this.beginDate = beginDate; 32 | this.endDate = endDate; 33 | this.holdingNum = holdingNum; 34 | this.meanDayNum = meanDayNum; 35 | } 36 | 37 | /** 38 | * 使用默认的股票池 39 | * @param beginDate 40 | * @param endDate 41 | * @param holdingNum 42 | * @param meanDayNum 43 | */ 44 | public MeanReversionParamForBestDayVO(LocalDate beginDate, LocalDate endDate, int holdingNum, int meanDayNum) { 45 | this.beginDate = beginDate; 46 | this.endDate = endDate; 47 | this.holdingNum = holdingNum; 48 | this.meanDayNum = meanDayNum; 49 | } 50 | 51 | public List getStockPool() { 52 | return stockPool; 53 | } 54 | 55 | public void setStockPool(List stockPool) { 56 | this.stockPool = stockPool; 57 | } 58 | 59 | public LocalDate getBeginDate() { 60 | return beginDate; 61 | } 62 | 63 | public void setBeginDate(LocalDate beginDate) { 64 | this.beginDate = beginDate; 65 | } 66 | 67 | public LocalDate getEndDate() { 68 | return endDate; 69 | } 70 | 71 | public void setEndDate(LocalDate endDate) { 72 | this.endDate = endDate; 73 | } 74 | 75 | public int getHoldingNum() { 76 | return holdingNum; 77 | } 78 | 79 | public void setHoldingNum(int holdingNum) { 80 | this.holdingNum = holdingNum; 81 | } 82 | 83 | public int getMeanDayNum() { 84 | return meanDayNum; 85 | } 86 | 87 | public void setMeanDayNum(int meanDayNum) { 88 | this.meanDayNum = meanDayNum; 89 | } 90 | 91 | @Override 92 | public String toString() { 93 | return "MeanReversionParamForBestDayVO{" + 94 | "stockPool=" + stockPool + 95 | ", beginDate=" + beginDate + 96 | ", endDate=" + endDate + 97 | ", holdingNum=" + holdingNum + 98 | ", meanDayNum=" + meanDayNum + 99 | '}'; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/vo/MomentumParamVO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.vo; 2 | 3 | import java.time.LocalDate; 4 | import java.util.List; 5 | 6 | 7 | /** 8 | * Created by xihao on 17-4-3. 9 | */ 10 | public class MomentumParamVO { 11 | 12 | private LocalDate beginDate; //开始日期 13 | private LocalDate endDate; //结束日期 14 | private boolean isFormativeDay; //是否输入了形成期天数,输入的话为true,没有为false 15 | private int dayNum; //输入了形成期就是形成期的天数,否则为持有期天数 16 | 17 | private List stockCodes; //自输入的股票池 18 | 19 | /** 20 | * 输入股票池的话 使用输入的股票池 21 | * @param beginDate 22 | * @param endDate 23 | * @param isFormativeDay 24 | * @param dayNum 25 | * @param stockCodes 26 | */ 27 | public MomentumParamVO(LocalDate beginDate, LocalDate endDate, boolean isFormativeDay, int dayNum, List stockCodes) { 28 | this.beginDate = beginDate; 29 | this.endDate = endDate; 30 | this.isFormativeDay = isFormativeDay; 31 | this.dayNum = dayNum; 32 | this.stockCodes = stockCodes; 33 | } 34 | 35 | /** 36 | * 不输入股票池的话就是使用默认的股票池 37 | * @param beginDate 38 | * @param endDate 39 | * @param isFormativeDay 40 | * @param dayNum 41 | */ 42 | public MomentumParamVO(LocalDate beginDate, LocalDate endDate, boolean isFormativeDay, int dayNum) { 43 | this.beginDate = beginDate; 44 | this.endDate = endDate; 45 | this.isFormativeDay = isFormativeDay; 46 | this.dayNum = dayNum; 47 | } 48 | 49 | public LocalDate getBeginDate() { 50 | return beginDate; 51 | } 52 | 53 | public void setBeginDate(LocalDate beginDate) { 54 | this.beginDate = beginDate; 55 | } 56 | 57 | public LocalDate getEndDate() { 58 | return endDate; 59 | } 60 | 61 | public void setEndDate(LocalDate endDate) { 62 | this.endDate = endDate; 63 | } 64 | 65 | public boolean isFormativeDay() { 66 | return isFormativeDay; 67 | } 68 | 69 | public void setFormativeDay(boolean formativeDay) { 70 | isFormativeDay = formativeDay; 71 | } 72 | 73 | public int getDayNum() { 74 | return dayNum; 75 | } 76 | 77 | public void setDayNum(int dayNum) { 78 | this.dayNum = dayNum; 79 | } 80 | 81 | 82 | public List getStockCodes() { 83 | return stockCodes; 84 | } 85 | 86 | public void setStockCodes(List stockCodes) { 87 | this.stockCodes = stockCodes; 88 | } 89 | 90 | @Override 91 | public String toString() { 92 | return "MomentumParamVO{" + 93 | "beginDate=" + beginDate + 94 | ", endDate=" + endDate + 95 | ", isFormativeDay=" + isFormativeDay + 96 | ", dayNum=" + dayNum + 97 | ", stockCodes=" + stockCodes + 98 | '}'; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/po/StockComparedPO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.po; 2 | 3 | import java.util.ArrayList; 4 | 5 | /** 6 | * CompareVO 比较两只股票时候使用的股票信息 7 | * highest 一段日期之间的最高指数 8 | * lowest 一段日期的最低指数 9 | * hasIncreased 这段时间之内是否上涨 10 | * amountOfChange 涨幅/跌幅 11 | * closeList 每日的收盘指数 12 | * logList 每日的对数收益率 13 | * squareDifference 这段时间的收益率方差 14 | */ 15 | public class StockComparedPO { 16 | private String stockCode; 17 | private String stockName; 18 | private double highest; 19 | private double lowest; 20 | private boolean hasIncreased; 21 | private double amountOfChange; 22 | private ArrayList closeList; 23 | private ArrayList logList; 24 | private double squareDifference; 25 | 26 | /** 27 | * 28 | * @param stockCode 股票代码 29 | * @param stockName 股票名称 30 | * @param highest 最高支书 31 | * @param lowest 最低指数 32 | * @param hasIncreased 是否上涨 33 | * @param amountOfChange 涨幅/跌幅 34 | * @param closeList 每日收盘指数 35 | * @param logList 每日对数收益率 36 | * @param squareDifference 对数收益率方差 37 | */ 38 | public StockComparedPO(String stockCode,String stockName,double highest, double lowest, boolean hasIncreased, double amountOfChange, ArrayList closeList, ArrayList logList, double squareDifference){ 39 | this.stockCode = stockCode; 40 | this.stockName = stockName; 41 | this.highest = highest; 42 | this.lowest = lowest; 43 | this.hasIncreased = hasIncreased; 44 | this.amountOfChange = amountOfChange; 45 | this.closeList = closeList; 46 | this.logList = logList; 47 | this.squareDifference = squareDifference; 48 | } 49 | 50 | public double getHighest() { 51 | return highest; 52 | } 53 | 54 | public double getLowest() { 55 | return lowest; 56 | } 57 | 58 | public boolean isHasIncreased() { 59 | return hasIncreased; 60 | } 61 | 62 | public double getAmountOfChange() { 63 | return amountOfChange; 64 | } 65 | 66 | public ArrayList getCloseList() { 67 | return closeList; 68 | } 69 | 70 | public ArrayList getLogList() { 71 | return logList; 72 | } 73 | 74 | public double getSquareDifference() { 75 | return squareDifference; 76 | } 77 | 78 | public String getStockCode() { 79 | return stockCode; 80 | } 81 | 82 | public String getStockName() { 83 | return stockName; 84 | } 85 | 86 | @Override 87 | public String toString() { 88 | return "StockComparedVO{" + 89 | "stockCode='" + stockCode + '\'' + 90 | ", stockName='" + stockName + '\'' + 91 | ", highest=" + highest + 92 | ", lowest=" + lowest + 93 | ", hasIncreased=" + hasIncreased + 94 | ", amountOfChange=" + amountOfChange + 95 | ", closeList=" + closeList + 96 | ", logList=" + logList + 97 | ", squareDifference=" + squareDifference + 98 | '}'; 99 | } 100 | 101 | } -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/cache/RedisCache.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.cache; 2 | 3 | import cn.edu.nju.p.utils.ProtoStuffSerializerUtil; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.data.redis.core.RedisCallback; 6 | import org.springframework.data.redis.core.StringRedisTemplate; 7 | import org.springframework.stereotype.Component; 8 | 9 | import java.util.Set; 10 | 11 | /** 12 | * redis cache 13 | * Am I accessing connection only through RedisTemplate? 14 | */ 15 | @Component 16 | public class RedisCache { 17 | 18 | public final static String CACHENAME = "cache"; //use CACHENAME as prefix of key every time adding a key 19 | public final static int CACHETIME = 60; //default cache time is 60 seconds 20 | 21 | @Autowired 22 | private StringRedisTemplate redisTemplate; //default use StringRedisTemplate 23 | 24 | /** 25 | * 添加缓存 26 | * @param key 键值 27 | * @param obj 对象 28 | * @param 键值的泛型 29 | * @return 30 | */ 31 | public void putCache(String key, T obj) { 32 | 33 | final byte[] bKey = key.getBytes(); 34 | final byte[] bValue = ProtoStuffSerializerUtil.serialize(obj); 35 | redisTemplate.execute((RedisCallback) redisConnection -> redisConnection.setNX(bKey, bValue)); 36 | } 37 | 38 | /** 39 | * 按照需要的时间配置缓存 40 | * @param key 41 | * @param obj 42 | * @param expireTime 43 | * @param 44 | */ 45 | public void putCacheWithExpireTime(String key, T obj, final long expireTime) { 46 | 47 | final byte[] bKey =key.getBytes(); 48 | final byte[] bValue = ProtoStuffSerializerUtil.serialize(obj); 49 | redisTemplate.execute((RedisCallback) redisConnection -> { 50 | redisConnection.setEx(bKey, expireTime, bValue); 51 | return true; 52 | }); 53 | } 54 | 55 | /** 56 | * 获得缓存对象 57 | * @param key 58 | * @param targetClass 59 | * @param 60 | * @return 61 | */ 62 | public T getCache(final String key, Class targetClass) { 63 | 64 | byte[] result = redisTemplate.execute((RedisCallback) redisConnection -> redisConnection.get(key.getBytes())); 65 | 66 | if (result == null) { 67 | return null; 68 | } 69 | 70 | return ProtoStuffSerializerUtil.deSerialize(result, targetClass); 71 | } 72 | 73 | /** 74 | * 精确删除key 75 | * @param key 76 | */ 77 | void deleteCache(String key) { 78 | redisTemplate.execute((RedisCallback) redisConnection -> redisConnection.del(key.getBytes())); 79 | } 80 | 81 | /** 82 | * 模糊删除key 83 | * @param pattern key的模板 84 | * 85 | */ 86 | public void deleteCacheWithPattern(String pattern) { 87 | 88 | Set keys = redisTemplate.keys(pattern); 89 | keys.forEach(key-> redisTemplate.execute((RedisCallback) redisConnection -> redisConnection.del(key.getBytes()))); 90 | } 91 | 92 | /** 93 | * 清空缓存 94 | */ 95 | void deleteAllCache() { 96 | deleteCacheWithPattern("*"); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/strategy/MomentumStrategyImpl.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.strategy; 2 | 3 | import cn.edu.nju.p.po.StockPO; 4 | import cn.edu.nju.p.utils.StockHelper; 5 | import cn.edu.nju.p.utils.beans.ToolSpring; 6 | import cn.edu.nju.p.utils.redis.StockRedisDataUtils; 7 | 8 | import java.math.BigDecimal; 9 | import java.time.LocalDate; 10 | import java.util.ArrayList; 11 | import java.util.LinkedHashMap; 12 | import java.util.List; 13 | import java.util.Map; 14 | import java.util.stream.Collectors; 15 | 16 | /** 17 | * Created by xihao on 17-6-13. 18 | */ 19 | public class MomentumStrategyImpl implements Strategy { 20 | 21 | private StockHelper stockHelper; 22 | private StockRedisDataUtils redisDataUtils; 23 | private int holdingDayNum; 24 | private int formativeDayNum; 25 | private LocalDate beginDate; 26 | private LocalDate endDate; 27 | 28 | public MomentumStrategyImpl() { 29 | this.stockHelper = ToolSpring.getBeans(StockHelper.class); 30 | this.redisDataUtils = ToolSpring.getBeans(StockRedisDataUtils.class); 31 | this.holdingDayNum = 5; 32 | this.formativeDayNum = 5; 33 | this.beginDate = LocalDate.of(2016,1,10); 34 | this.endDate = LocalDate.of(2016, 12, 10); 35 | } 36 | 37 | @Override 38 | public List setStockPool() { 39 | return stockHelper.getRecommendStock(); 40 | } 41 | 42 | @Override 43 | public List setWinner(LocalDate beginDate, LocalDate endDate, List stockPool) { 44 | 45 | Map fieldRates = new LinkedHashMap<>(); 46 | stockPool.forEach(stockCode -> fieldRates.put(stockCode,countRate(beginDate,endDate,stockCode))); 47 | 48 | //对收益率进行排序 49 | List> rateList = new ArrayList<>(fieldRates.entrySet()); 50 | rateList.sort((rate1, rate2) -> new BigDecimal(rate2.getValue()).compareTo(new BigDecimal(rate1.getValue()))); 51 | 52 | int winnerNum = rateList.size() / 5; 53 | return rateList.subList(0,winnerNum) 54 | .parallelStream() 55 | .map(Map.Entry::getKey) 56 | .collect(Collectors.toList()); 57 | } 58 | 59 | private double countRate(LocalDate beginDate, LocalDate endDate, String stockCode) { 60 | 61 | try { 62 | StockPO beginPo = redisDataUtils.getStockPO(stockCode, beginDate); 63 | StockPO endPo = redisDataUtils.getStockPO(stockCode, endDate); 64 | double beginClose = beginPo.getClose(); 65 | double endClose = endPo.getClose(); 66 | return (endClose - beginClose) / beginClose; 67 | } catch (NullPointerException ne) { 68 | return -99; 69 | } 70 | } 71 | @Override 72 | public LocalDate setBeginDate() { 73 | return beginDate; 74 | } 75 | 76 | @Override 77 | public LocalDate setEndDate() { 78 | return endDate; 79 | } 80 | 81 | @Override 82 | public int setHoldingDay() { 83 | return holdingDayNum; 84 | } 85 | 86 | @Override 87 | public int setFormativeDayNum() { 88 | return formativeDayNum; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/controller/selfstrategy/CustomStrategyController.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.controller.selfstrategy; 2 | 3 | import cn.edu.nju.p.baseresult.BaseResult; 4 | import cn.edu.nju.p.strategy.customstrategy.javacompile.core.RuntimeCompiler; 5 | import cn.edu.nju.p.strategy.customstrategy.javacompile.util.RunCompileUtil; 6 | import cn.edu.nju.p.enums.ErrorCode; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | import java.io.ByteArrayOutputStream; 14 | import java.io.File; 15 | import java.io.PrintStream; 16 | import java.lang.reflect.InvocationTargetException; 17 | 18 | /** 19 | * Created by dell- on 2017/6/7. 20 | */ 21 | 22 | @RestController 23 | @RequestMapping("/customstrategy") 24 | public class CustomStrategyController { 25 | 26 | @GetMapping 27 | public BaseResult runCode(@RequestParam String code, HttpServletRequest request) { 28 | int errorCode=0; 29 | String className = null; 30 | String fullClassName = null; 31 | String result = ""; 32 | try { 33 | className = RunCompileUtil.getClassName(code); 34 | fullClassName = RunCompileUtil.getFullClassName(code); 35 | } catch (Exception e) { 36 | result = "Can't find class name in content."; 37 | return new BaseResult(ErrorCode.NO_CLASS_NAME.getErrorCode(), result); 38 | } 39 | 40 | // Compile source code to tomcat real path 41 | // String realPath = Thread.currentThread().getContextClassLoader().getResource("").toString(); 42 | RuntimeCompiler rc = new RuntimeCompiler("-d", "./target/classes"); 43 | boolean success = rc.compile(className, code); 44 | 45 | // Create a stream to hold the output 46 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 47 | PrintStream printStream = new PrintStream(baos); 48 | // Tell Java to use your special stream 49 | System.setOut(printStream); 50 | 51 | if (success) { 52 | try { 53 | Class.forName(fullClassName).getDeclaredMethod("main", new Class[] { 54 | String[].class 55 | }).invoke(null, new Object[] { 56 | null 57 | }); 58 | } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException 59 | | InvocationTargetException e) { 60 | result = "Load class error: " + e; 61 | } 62 | } 63 | 64 | // flush output stream 65 | System.out.flush(); 66 | 67 | if (success) { 68 | result = baos.toString(); 69 | errorCode = 0; 70 | } else { 71 | result = rc.getTraceMsg(); 72 | errorCode = 40000002; 73 | } 74 | 75 | //delete file 76 | File file = new File("./target/classes/" + className + ".class"); 77 | file.delete(); 78 | return new BaseResult(errorCode, result); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/vo/MomentumVO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.vo; 2 | 3 | import java.io.Serializable; 4 | import java.time.LocalDate; 5 | import java.util.List; 6 | 7 | 8 | /** 9 | * 动量策略的参数 10 | */ 11 | public class MomentumVO implements Serializable{ 12 | 13 | /** 14 | * 形成期天数 15 | */ 16 | private int dayNumFormative; 17 | 18 | /** 19 | * 持有期天数 20 | */ 21 | private int dayNumHolding; 22 | 23 | /** 24 | * 开始日期 25 | */ 26 | private LocalDate beginDate; 27 | 28 | /** 29 | * 结束日期 30 | */ 31 | private LocalDate endDate; 32 | 33 | /** 34 | * 输入的股票池 35 | */ 36 | private List stockPool; 37 | 38 | /** 39 | * 输入股票池 作为自选股票池 40 | * @param dayNumFormative 41 | * @param dayNumHolding 42 | * @param beginDate 43 | * @param endDate 44 | * @param stockPool 45 | */ 46 | public MomentumVO(int dayNumFormative, int dayNumHolding, LocalDate beginDate, LocalDate endDate, List stockPool) { 47 | this.dayNumFormative = dayNumFormative; 48 | this.dayNumHolding = dayNumHolding; 49 | this.beginDate = beginDate; 50 | this.endDate = endDate; 51 | this.stockPool = stockPool; 52 | } 53 | 54 | /** 55 | * 不输入股票池,使用默认股票池 56 | * @param dayNumFormative 57 | * @param dayNumHolding 58 | * @param beginDate 59 | * @param endDate 60 | */ 61 | public MomentumVO(int dayNumFormative, int dayNumHolding, LocalDate beginDate, LocalDate endDate) { 62 | this.dayNumFormative = dayNumFormative; 63 | this.dayNumHolding = dayNumHolding; 64 | this.beginDate = beginDate; 65 | this.endDate = endDate; 66 | } 67 | 68 | public int getDayNumFormative() { 69 | return dayNumFormative; 70 | } 71 | 72 | public void setDayNumFormative(int dayNumFormative) { 73 | this.dayNumFormative = dayNumFormative; 74 | } 75 | 76 | public int getDayNumHolding() { 77 | return dayNumHolding; 78 | } 79 | 80 | public void setDayNumHolding(int dayNumHolding) { 81 | this.dayNumHolding = dayNumHolding; 82 | } 83 | 84 | public LocalDate getBeginDate() { 85 | return beginDate; 86 | } 87 | 88 | public void setBeginDate(LocalDate beginDate) { 89 | this.beginDate = beginDate; 90 | } 91 | 92 | public LocalDate getEndDate() { 93 | return endDate; 94 | } 95 | 96 | public void setEndDate(LocalDate endDate) { 97 | this.endDate = endDate; 98 | } 99 | 100 | public List getStockPool() { 101 | return stockPool; 102 | } 103 | 104 | public void setStockPool(List stockPool) { 105 | this.stockPool = stockPool; 106 | } 107 | 108 | @Override 109 | public String toString() { 110 | return "MomentumVO{" + 111 | "dayNumFormative=" + dayNumFormative + 112 | ", dayNumHolding=" + dayNumHolding + 113 | ", beginDate=" + beginDate + 114 | ", endDate=" + endDate + 115 | ", stockPool=" + stockPool + 116 | '}'; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/serviceimpl/KLineServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.serviceimpl; 2 | 3 | import cn.edu.nju.p.service.exhibition.KLineService; 4 | import cn.edu.nju.p.utils.DoubleUtils; 5 | import cn.edu.nju.p.utils.StockHelper; 6 | import cn.edu.nju.p.utils.ema.MACDUtils; 7 | import cn.edu.nju.p.utils.holiday.Holidays; 8 | import cn.edu.nju.p.utils.redis.StockRedisDataUtils; 9 | import cn.edu.nju.p.vo.KLineVO; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | 13 | import java.time.LocalDate; 14 | import java.util.ArrayList; 15 | import java.util.Comparator; 16 | import java.util.List; 17 | import java.util.stream.Collectors; 18 | 19 | /** 20 | * KLineService的实现类 21 | */ 22 | @Service 23 | public class KLineServiceImpl implements KLineService { 24 | 25 | @Autowired 26 | private StockRedisDataUtils stockRedisDataUtils; 27 | 28 | @Autowired 29 | private MACDUtils macdUtils; 30 | 31 | @Autowired 32 | private Holidays holidays; 33 | 34 | /** 35 | * 通过股票代码获得KLine需要的所有VO 36 | * 37 | * @param code 股票代码 38 | * @param beginDate 开始日期 39 | * @param endDate 结束日期 40 | * @return 返回每一天的KLine数据 41 | */ 42 | public KLineVO getKLineVOSByCode(String code, LocalDate beginDate, LocalDate endDate) { 43 | 44 | // 使用lambda表达式过滤没有数据的日期 45 | List dateList = holidays.getBetweenDatesAndFilter(beginDate, endDate, aDate -> stockRedisDataUtils.getStockIsOpen(code, aDate)); 46 | 47 | List> finalResult = new ArrayList<>(300); 48 | String stockName = stockRedisDataUtils.getStockName(code); 49 | 50 | dateList.parallelStream().forEach(date -> { 51 | double low = stockRedisDataUtils.getStockLow(code,date); 52 | double high = stockRedisDataUtils.getStockHigh(code,date); 53 | double open = stockRedisDataUtils.getStockOpen(code,date); 54 | double close = stockRedisDataUtils.getStockClose(code,date); 55 | long volume = stockRedisDataUtils.getStockVolume(code,date); 56 | boolean isGoHigh = open results = new ArrayList<>(); 68 | results.add(date.toString()); 69 | results.add(open); 70 | results.add(close); 71 | results.add(low); 72 | results.add(high); 73 | results.add(volume); 74 | results.add(targ); 75 | results.add(0); 76 | results.add(0); 77 | results.add(0); 78 | finalResult.add(results); 79 | }); 80 | 81 | return new KLineVO(stockName, finalResult 82 | .parallelStream() 83 | .sorted(Comparator.comparing(a -> a.get(0).toString())) 84 | .collect(Collectors.toList())); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/controller/exhibition/ExhibitionController.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.controller.exhibition; 2 | 3 | import cn.edu.nju.p.baseresult.BaseResult; 4 | import cn.edu.nju.p.service.exhibition.KLineService; 5 | import cn.edu.nju.p.service.strategy.MeanReversionService; 6 | import cn.edu.nju.p.service.strategy.MomentumService; 7 | import cn.edu.nju.p.vo.*; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | import java.text.SimpleDateFormat; 12 | import java.time.LocalDate; 13 | import java.time.format.DateTimeFormatter; 14 | import java.util.List; 15 | import java.util.stream.Collectors; 16 | 17 | /** 18 | * Created by soft on 2017/5/17. 19 | */ 20 | @RestController 21 | @RequestMapping("/exhibition") 22 | public class ExhibitionController { 23 | 24 | @Autowired 25 | private KLineService kLineService; 26 | 27 | @Autowired 28 | private MomentumService momentumService; 29 | 30 | @Autowired 31 | private MeanReversionService meanReversionService; 32 | 33 | @GetMapping("/kline/{code}") 34 | public BaseResult getKLineDataByCode(@PathVariable String code/*, @CookieValue(value = "phoneNumber", required = false) String phoneNumber 35 | */, @RequestParam String beginDate, @RequestParam String endDate) { 36 | 37 | LocalDate begin = LocalDate.parse(beginDate); 38 | LocalDate end = LocalDate.parse(endDate); 39 | KLineVO kLineVO = kLineService.getKLineVOSByCode(code, begin, end); 40 | return new BaseResult<>(0, kLineVO); 41 | } 42 | 43 | @GetMapping("/momentumStrategy") 44 | public BaseResult runMomentumStrategy(@RequestParam int dayNumFormative, @RequestParam int dayNumHolding, @RequestParam String dateRange, @RequestParam(value = "stockPool[]", required = false) List stockPool) { 45 | 46 | String beginDate = dateRange.split(" - ")[0]; 47 | String endDate = dateRange.split(" - ")[1]; 48 | 49 | String pattern = "MM/dd/yyyy"; 50 | 51 | MomentumVO momentumVO = new MomentumVO(dayNumFormative, dayNumHolding, LocalDate.parse(beginDate,DateTimeFormatter.ofPattern(pattern)), LocalDate.parse(endDate,DateTimeFormatter.ofPattern(pattern)), stockPool); 52 | MomentumResultVO resultVO = momentumService.getResult(momentumVO); 53 | return new BaseResult<>(0, resultVO); 54 | } 55 | 56 | @GetMapping("/meanReversionStrategy") 57 | public BaseResult runMeanReversionStrategy(@RequestParam int meanDayNum, @RequestParam int holdingDayNum, @RequestParam int holdingStockNum, @RequestParam String dateRange, @RequestParam(value = "stockPool[]", required = false) List stockPool) { 58 | 59 | System.out.println(stockPool); 60 | 61 | String beginDate = dateRange.split(" - ")[0]; 62 | String endDate = dateRange.split(" - ")[1]; 63 | String pattern = "MM/dd/yyyy"; 64 | 65 | MeanReversionParamVO meanReversionParamVO = new MeanReversionParamVO(stockPool, holdingDayNum, holdingStockNum, LocalDate.parse(beginDate,DateTimeFormatter.ofPattern(pattern)), LocalDate.parse(endDate,DateTimeFormatter.ofPattern(pattern)), meanDayNum); 66 | MeanReversionResultVO reversionResultVO = meanReversionService.getResult(meanReversionParamVO); 67 | return new BaseResult<>(0, reversionResultVO); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/dao/daoimpl/TestStockDaoImpl.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao.daoimpl; 2 | 3 | import cn.edu.nju.p.dao.TestStockDao; 4 | import cn.edu.nju.p.po.TestStockPO; 5 | import io.swagger.models.auth.In; 6 | import org.jsoup.Jsoup; 7 | import org.jsoup.nodes.Document; 8 | import org.jsoup.nodes.Element; 9 | import org.jsoup.select.Elements; 10 | import org.springframework.stereotype.Repository; 11 | import org.springframework.stereotype.Service; 12 | 13 | import java.io.IOException; 14 | 15 | /** 16 | * Created by dc on 2017/6/8. 17 | */ 18 | @Repository 19 | public class TestStockDaoImpl implements TestStockDao { 20 | 21 | private static final String THS_URL = "http://stockpage.10jqka.com.cn/"; 22 | 23 | /** 24 | * Jsoup初始化 25 | * @param URL 26 | * @return 27 | */ 28 | private Document getDocument(String URL) { 29 | try{ 30 | return Jsoup.connect(URL).get(); 31 | } catch (IOException e) { 32 | e.printStackTrace(); 33 | } 34 | return null; 35 | } 36 | 37 | @Override 38 | public TestStockPO getTestStockPO(String code) { 39 | 40 | Document doc = getDocument(THS_URL + code + "/"); 41 | 42 | Elements html = doc.select("[class=clearfix analyze]");//得到诊股所在的class 43 | 44 | Elements pointEle = html.select("[class=analyze-img fl]"); 45 | 46 | double point = Double.parseDouble(pointEle.select("[class=analyze-num]").text()); //评分 47 | String overView = pointEle.select("[class=analyze-tips mt7]").text(); //综合判断 48 | String beat = pointEle.select("[class=analyze-tips]").text(); //打败了多少股票 49 | 50 | Elements trend = html.select("[class=analyze-txt fr]");//趋势所在的class 51 | Element shortEle = trend.select("[class=analyze-txt-cont]").get(0); 52 | Element midEle = trend.select("[class=analyze-txt-cont]").get(1); 53 | Element longEle = trend.select("[class=analyze-txt-cont]").get(2); 54 | Elements conclude = trend.select("[class=txt-phra]"); 55 | 56 | String shortTrend = shortEle.select("[class=txt-main]").text();//短期趋势 57 | String midTrend = midEle.select("[class=txt-main]").text();//中期趋势 58 | String longTrend = longEle.select("[class=txt-main]").text();//长期趋势 59 | String conclusion = conclude.text().split(" ")[0];//诊断 60 | String date = conclude.select("[class=date]").text().replace("[","").replace("]","");//诊断日期 61 | 62 | Elements aspect = html.select("[class=analyze-level fr]").select("[class=analyze-stars]"); 63 | String technical_test = aspect.get(0).select("[class=cred]").text(); 64 | String fund_test = aspect.get(1).select("[class=cred]").text(); 65 | String info_test = aspect.get(2).select("[class=cred]").text(); 66 | String industry_test = aspect.get(3).select("[class=cred]").text(); 67 | String basic_test = aspect.get(4).select("[class=cred]").text(); 68 | 69 | TestStockPO po = new TestStockPO(point, overView, beat, shortTrend, midTrend, longTrend, conclusion, date, technical_test, fund_test, info_test, industry_test, basic_test); 70 | return po; 71 | } 72 | 73 | public static void main(String[] args) { 74 | TestStockDaoImpl run = new TestStockDaoImpl(); 75 | TestStockPO po = run.getTestStockPO("000505"); 76 | System.out.println(po.toString()); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/dao/daoutils/CSVUtil.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao.daoutils; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.BufferedWriter; 5 | import java.io.File; 6 | import java.io.FileOutputStream; 7 | import java.io.FileReader; 8 | import java.io.IOException; 9 | import java.io.OutputStreamWriter; 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | /** 14 | * Created by dell- on 2017/6/9. 15 | */ 16 | public class CSVUtil { 17 | 18 | public static boolean exportCsv(File file, List dataList){ 19 | boolean isSucess=false; 20 | 21 | FileOutputStream out=null; 22 | OutputStreamWriter osw=null; 23 | BufferedWriter bw=null; 24 | try { 25 | out = new FileOutputStream(file); 26 | osw = new OutputStreamWriter(out,"gbk"); 27 | bw =new BufferedWriter(osw); 28 | if(dataList!=null && !dataList.isEmpty()){ 29 | for(String data : dataList){ 30 | bw.append(data).append("\r"); 31 | } 32 | } 33 | isSucess=true; 34 | } catch (Exception e) { 35 | isSucess=false; 36 | }finally{ 37 | if(bw!=null){ 38 | try { 39 | bw.close(); 40 | bw=null; 41 | } catch (IOException e) { 42 | e.printStackTrace(); 43 | } 44 | } 45 | if(osw!=null){ 46 | try { 47 | osw.close(); 48 | osw=null; 49 | } catch (IOException e) { 50 | e.printStackTrace(); 51 | } 52 | } 53 | if(out!=null){ 54 | try { 55 | out.close(); 56 | out=null; 57 | } catch (IOException e) { 58 | e.printStackTrace(); 59 | } 60 | } 61 | } 62 | 63 | return isSucess; 64 | } 65 | 66 | /** 67 | * 导入 68 | * 69 | * @param file csv文件(路径+文件) 70 | * @return 71 | */ 72 | public static List importCsv(File file){ 73 | List dataList=new ArrayList(); 74 | 75 | BufferedReader br=null; 76 | try { 77 | br = new BufferedReader(new FileReader(file)); 78 | String line = ""; 79 | while ((line = br.readLine()) != null) { 80 | dataList.add(line); 81 | } 82 | }catch (Exception e) { 83 | }finally{ 84 | if(br!=null){ 85 | try { 86 | br.close(); 87 | br=null; 88 | } catch (IOException e) { 89 | e.printStackTrace(); 90 | } 91 | } 92 | } 93 | 94 | return dataList; 95 | } 96 | 97 | public static void main(String[] args) { 98 | List dataList=new ArrayList(); 99 | dataList.add("1,张三,男"); 100 | dataList.add("2,李四,男"); 101 | dataList.add("3,小红,女"); 102 | boolean isSuccess=CSVUtil.exportCsv(new File("D://test.csv"), dataList); 103 | System.out.println(isSuccess); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/controller/personnel/MyStrategyController.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.controller.personnel; 2 | 3 | import cn.edu.nju.p.baseresult.BaseResult; 4 | import cn.edu.nju.p.dao.MyStrategyDao; 5 | import cn.edu.nju.p.dao.StockDao; 6 | import cn.edu.nju.p.dao.StrategySquareDao; 7 | import cn.edu.nju.p.po.SaveStrategyPO; 8 | import cn.edu.nju.p.po.StrategyCodePO; 9 | import com.alibaba.fastjson.JSONObject; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | import java.io.UnsupportedEncodingException; 14 | import java.net.URLDecoder; 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | /** 19 | * Created by pc on 2017/6/14. 20 | */ 21 | @RestController 22 | @RequestMapping("/strategy") 23 | public class MyStrategyController { 24 | 25 | @Autowired 26 | private MyStrategyDao myStrategyDao; 27 | 28 | @Autowired 29 | private StrategySquareDao squareDao; 30 | 31 | @GetMapping("/{phoneNumber}") 32 | public BaseResult getMyStrategy(@PathVariable String phoneNumber){ 33 | 34 | List strategyName = myStrategyDao.getMyStrategyName(phoneNumber); 35 | return new BaseResult<>(0, strategyName); 36 | } 37 | 38 | @GetMapping("/detail/{phoneNumber}") 39 | public BaseResult getMyStrategyDetail(@PathVariable String phoneNumber) { 40 | 41 | List codePOS = myStrategyDao.getMyStrategy(phoneNumber); 42 | return new BaseResult<>(0, codePOS); 43 | } 44 | 45 | @PostMapping 46 | public BaseResult addAStrategy(@RequestBody JSONObject strategyPo) { 47 | String phoneNumber = strategyPo.getString("phoneNumber"); 48 | String code = strategyPo.getString("code"); 49 | String strategyName = strategyPo.getString("strategyName"); 50 | myStrategyDao.addMyStrategy(phoneNumber, code, strategyName); 51 | return new BaseResult(0, "add a strategy sucessfully!"); 52 | } 53 | 54 | @GetMapping("/deleteStrategy") 55 | public BaseResult deleteStrategy(@RequestParam String phoneNumber, @RequestParam String strategyName) { 56 | myStrategyDao.deleteStrategy(phoneNumber, strategyName); 57 | return new BaseResult<>(0, "删除成功!"); 58 | } 59 | 60 | @GetMapping("/deleteSaveStrategy") 61 | public BaseResult deleteSaveStrategy(@RequestParam String phoneNumber, @RequestParam String strategyName) { 62 | myStrategyDao.deleteSaveStrategy(phoneNumber, strategyName); 63 | return new BaseResult<>(0, "删除成功!"); 64 | } 65 | 66 | @PostMapping("/addSaveStrategy") 67 | public BaseResult addSaveStrategy(@RequestParam String phoneNumber,@RequestParam String strategyName,@RequestParam String url) { 68 | myStrategyDao.addSaveStrategy(phoneNumber, strategyName, url); 69 | return new BaseResult(0, "add a strategy sucessfully!"); 70 | } 71 | 72 | @GetMapping 73 | public BaseResult getStrategyCode(@RequestParam String phoneNumber, @RequestParam String strategyName) { 74 | 75 | String code = myStrategyDao.getCode(phoneNumber, strategyName); 76 | return new BaseResult(0, code); 77 | } 78 | 79 | @GetMapping("/save/{phoneNumber}") 80 | public BaseResult getMySaveStrategyList(@PathVariable String phoneNumber){ 81 | List poList = myStrategyDao.getMySaveStrategyList(phoneNumber); 82 | return new BaseResult<>(0, poList); 83 | } 84 | 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/vo/MeanReversionParamVO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.vo; 2 | 3 | import java.io.Serializable; 4 | import java.time.LocalDate; 5 | import java.util.List; 6 | 7 | /** 8 | * Created by xihao on 17-4-6. 9 | */ 10 | public class MeanReversionParamVO implements Serializable{ 11 | 12 | private List stockPool; 13 | 14 | private int holdingDay; //持有天数 15 | 16 | private int holdingStockNum; //每次买入的股票数量 17 | 18 | private LocalDate beginDate; 19 | 20 | private LocalDate endDate; 21 | 22 | /** 23 | * 确定几日均线 24 | */ 25 | private int meanDayNum; 26 | 27 | /** 28 | * 自己实现了股票池 29 | * @param stockPool 股票池 30 | * @param holdingDay 每次持仓期 31 | * @param holdingStockNum 每次持有的股票数目 32 | * @param beginDate 开始日期 33 | * @param endDate 结束日期 34 | * @param meanDayNum 选择是五日均线还是10,20,30 35 | */ 36 | public MeanReversionParamVO(List stockPool, int holdingDay, int holdingStockNum, LocalDate beginDate, LocalDate endDate, int meanDayNum) { 37 | this.stockPool = stockPool; 38 | this.holdingDay = holdingDay; 39 | this.holdingStockNum = holdingStockNum; 40 | this.beginDate = beginDate; 41 | this.endDate = endDate; 42 | this.meanDayNum = meanDayNum; 43 | } 44 | 45 | /** 46 | * 没有输入股票池,默认使用所有的股票作为股票池 47 | * @param holdingDay 每次持仓期 48 | * @param holdingStockNum 每次持有的股票数目 49 | * @param beginDate 开始日期 50 | * @param endDate 结束日期 51 | * @param meanDayNum 选择是五日均线还是10,20,30 52 | */ 53 | public MeanReversionParamVO(int holdingDay, int holdingStockNum, LocalDate beginDate, LocalDate endDate, int meanDayNum) { 54 | this.holdingDay = holdingDay; 55 | this.holdingStockNum = holdingStockNum; 56 | this.beginDate = beginDate; 57 | this.endDate = endDate; 58 | this.meanDayNum = meanDayNum; 59 | } 60 | 61 | public List getStockPool() { 62 | return stockPool; 63 | } 64 | 65 | public void setStockPool(List stockPool) { 66 | this.stockPool = stockPool; 67 | } 68 | 69 | public int getHoldingDay() { 70 | return holdingDay; 71 | } 72 | 73 | public void setHoldingDay(int holdingDay) { 74 | this.holdingDay = holdingDay; 75 | } 76 | 77 | public int getHoldingStockNum() { 78 | return holdingStockNum; 79 | } 80 | 81 | public void setHoldingStockNum(int holdingStockNum) { 82 | this.holdingStockNum = holdingStockNum; 83 | } 84 | 85 | public LocalDate getBeginDate() { 86 | return beginDate; 87 | } 88 | 89 | public void setBeginDate(LocalDate beginDate) { 90 | this.beginDate = beginDate; 91 | } 92 | 93 | public LocalDate getEndDate() { 94 | return endDate; 95 | } 96 | 97 | public void setEndDate(LocalDate endDate) { 98 | this.endDate = endDate; 99 | } 100 | 101 | public int getMeanDayNum() { 102 | return meanDayNum; 103 | } 104 | 105 | public void setMeanDayNum(int meanDayNum) { 106 | this.meanDayNum = meanDayNum; 107 | } 108 | 109 | @Override 110 | public String toString() { 111 | return "MeanReversionParamVO{" + 112 | "stockPool=" + stockPool + 113 | ", holdingDay=" + holdingDay + 114 | ", holdingStockNum=" + holdingStockNum + 115 | ", beginDate=" + beginDate + 116 | ", endDate=" + endDate + 117 | ", meanDayNum=" + meanDayNum + 118 | '}'; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/strategy/StrategyResultVO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.strategy; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by Xihao on 2017/6/14. 7 | */ 8 | public class StrategyResultVO { 9 | 10 | private List primaryRates; 11 | private List yieldRates; 12 | private List dateList; 13 | 14 | private double beta ; 15 | private double alpha; 16 | private double shapeRatio; 17 | private double maxDrawnDown; 18 | private double yearYield; 19 | private double primaryYearYield; 20 | 21 | public StrategyResultVO(List primaryRates, List yieldRates, List dateList, double beta, double alpha, double shapeRatio, double maxDrawnDown, double yearYield, double primaryYearYield) { 22 | this.primaryRates = primaryRates; 23 | this.yieldRates = yieldRates; 24 | this.dateList = dateList; 25 | this.beta = beta; 26 | this.alpha = alpha; 27 | this.shapeRatio = shapeRatio; 28 | this.maxDrawnDown = maxDrawnDown; 29 | this.yearYield = yearYield; 30 | this.primaryYearYield = primaryYearYield; 31 | } 32 | 33 | public List getPrimaryRates() { 34 | return primaryRates; 35 | } 36 | 37 | public void setPrimaryRates(List primaryRates) { 38 | this.primaryRates = primaryRates; 39 | } 40 | 41 | public List getYieldRates() { 42 | return yieldRates; 43 | } 44 | 45 | public void setYieldRates(List yieldRates) { 46 | this.yieldRates = yieldRates; 47 | } 48 | 49 | public List getDateList() { 50 | return dateList; 51 | } 52 | 53 | public void setDateList(List dateList) { 54 | this.dateList = dateList; 55 | } 56 | 57 | public double getBeta() { 58 | return beta; 59 | } 60 | 61 | public void setBeta(double beta) { 62 | this.beta = beta; 63 | } 64 | 65 | public double getAlpha() { 66 | return alpha; 67 | } 68 | 69 | public void setAlpha(double alpha) { 70 | this.alpha = alpha; 71 | } 72 | 73 | public double getShapeRatio() { 74 | return shapeRatio; 75 | } 76 | 77 | public void setShapeRatio(double shapeRatio) { 78 | this.shapeRatio = shapeRatio; 79 | } 80 | 81 | public double getMaxDrawnDown() { 82 | return maxDrawnDown; 83 | } 84 | 85 | public void setMaxDrawnDown(double maxDrawnDown) { 86 | this.maxDrawnDown = maxDrawnDown; 87 | } 88 | 89 | public double getYearYield() { 90 | return yearYield; 91 | } 92 | 93 | public void setYearYield(double yearYield) { 94 | this.yearYield = yearYield; 95 | } 96 | 97 | public double getPrimaryYearYield() { 98 | return primaryYearYield; 99 | } 100 | 101 | public void setPrimaryYearYield(double primaryYearYield) { 102 | this.primaryYearYield = primaryYearYield; 103 | } 104 | 105 | @Override 106 | public String toString() { 107 | return "StrategyResultVO{" + 108 | "primaryRates=" + primaryRates + 109 | ", yieldRates=" + yieldRates + 110 | ", dateList=" + dateList + 111 | ", beta=" + beta + 112 | ", alpha=" + alpha + 113 | ", shapeRatio=" + shapeRatio + 114 | ", maxDrawnDown=" + maxDrawnDown + 115 | ", yearYield=" + yearYield + 116 | ", primaryYearYield=" + primaryYearYield + 117 | '}'; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/nju/p/utils/redis/StockRedisDataUtilsTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.utils.redis; 2 | 3 | import cn.edu.nju.p.utils.holiday.Holidays; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.data.redis.core.StringRedisTemplate; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | import org.springframework.test.context.web.WebAppConfiguration; 11 | 12 | import java.time.LocalDate; 13 | import java.util.Map; 14 | 15 | import static org.junit.Assert.*; 16 | 17 | /** 18 | * Created by xihao on 17-6-13. 19 | */ 20 | @SpringBootTest 21 | @WebAppConfiguration 22 | @RunWith(SpringRunner.class) 23 | public class StockRedisDataUtilsTest { 24 | 25 | @Autowired 26 | private StockRedisDataUtils dataUtils; 27 | 28 | @Autowired 29 | Holidays holidays; 30 | 31 | @Autowired 32 | StringRedisTemplate redisTemplate; 33 | 34 | @Test 35 | public void getStockClose() throws Exception { 36 | System.out.println(dataUtils.getStockClose("000001", LocalDate.of(2006,1,17))); 37 | LocalDate beginDate = LocalDate.of(2012, 2, 3); 38 | LocalDate endDate = LocalDate.of(2013, 2, 3); 39 | while (beginDate.isBefore(endDate)) { 40 | if (!holidays.isHoliday(beginDate)) { 41 | System.out.println(beginDate.toString() + "--->" + dataUtils.getStockClose("000001", beginDate)); 42 | } 43 | beginDate = beginDate.plusDays(1); 44 | } 45 | } 46 | 47 | @Test 48 | public void getStockOpen() throws Exception { 49 | 50 | LocalDate beginDate = LocalDate.of(2013, 2, 3); 51 | LocalDate endDate = LocalDate.of(2014, 2, 3); 52 | while (beginDate.isBefore(endDate)) { 53 | if (!holidays.isHoliday(beginDate)) { 54 | System.out.println(dataUtils.getStockOpen("000001", beginDate)); 55 | } 56 | beginDate = beginDate.plusDays(1); 57 | } 58 | } 59 | 60 | @Test 61 | public void getStockHigh() throws Exception { 62 | LocalDate beginDate = LocalDate.of(2014, 2, 3); 63 | LocalDate endDate = LocalDate.of(2015, 2, 3); 64 | while (beginDate.isBefore(endDate)) { 65 | if (!holidays.isHoliday(beginDate)) { 66 | System.out.println(dataUtils.getStockHigh("000001", beginDate)); 67 | } 68 | beginDate = beginDate.plusDays(1); 69 | } 70 | } 71 | 72 | @Test 73 | public void getStockVolume() throws Exception { 74 | LocalDate beginDate = LocalDate.of(2015, 2, 3); 75 | LocalDate endDate = LocalDate.of(2016, 2, 3); 76 | while (beginDate.isBefore(endDate)) { 77 | if (!holidays.isHoliday(beginDate)) { 78 | System.out.println(dataUtils.getStockVolume("000001", beginDate)); 79 | } 80 | beginDate = beginDate.plusDays(1); 81 | } 82 | } 83 | 84 | @Test 85 | public void getStockPO() throws Exception { 86 | 87 | LocalDate beginDate = LocalDate.of(2016, 2, 3); 88 | LocalDate endDate = LocalDate.of(2016, 12, 3); 89 | while (beginDate.isBefore(endDate)) { 90 | if (!holidays.isHoliday(beginDate)) { 91 | System.out.println(dataUtils.getStockPO("000001", beginDate)); 92 | } 93 | beginDate = beginDate.plusDays(1); 94 | } 95 | } 96 | 97 | @Test 98 | public void getMapTest() throws Exception { 99 | 100 | System.out.println(dataUtils.getStockDataOfDateMap(LocalDate.of(2012, 10, 19))); 101 | } 102 | 103 | @Test 104 | public void insertTest() throws Exception { 105 | 106 | // Map map = new 107 | } 108 | 109 | @Test 110 | public void test002730() { 111 | 112 | LocalDate localDate = LocalDate.of(2014, 10, 20); 113 | String code = "002730"; 114 | System.out.println(dataUtils.getStockPO(code,localDate)); 115 | } 116 | } -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/serviceimpl/HomePageServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.serviceimpl; 2 | 3 | import cn.edu.nju.p.dao.StockDao; 4 | import cn.edu.nju.p.exception.StockNoneException; 5 | import cn.edu.nju.p.po.StockPO; 6 | import cn.edu.nju.p.service.exhibition.HomePageService; 7 | import cn.edu.nju.p.utils.DateHelper; 8 | import cn.edu.nju.p.utils.StockHelper; 9 | import cn.edu.nju.p.utils.holiday.Holidays; 10 | import cn.edu.nju.p.utils.holiday.VacationDates; 11 | import cn.edu.nju.p.vo.StockMarketVO; 12 | import cn.edu.nju.p.vo.StockVO; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.stereotype.Service; 15 | 16 | import java.time.DayOfWeek; 17 | import java.time.LocalDate; 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | /** 22 | * Created by cyz on 2017/6/6. 23 | */ 24 | @Service 25 | public class HomePageServiceImpl implements HomePageService{ 26 | 27 | @Autowired 28 | private StockDao stockDao; 29 | 30 | @Autowired 31 | private Holidays holidays; 32 | 33 | /** 34 | * 获取当日的所有股票行情 35 | * 36 | * @param date 日期 37 | * @return 返回当日所有股票的信息 38 | * 39 | */ 40 | public List getStockVO(LocalDate date){ 41 | 42 | if (date.getDayOfWeek() == DayOfWeek.SATURDAY || date.getDayOfWeek() == DayOfWeek.SUNDAY || new VacationDates().isVacation(date)) { 43 | //当天休市 44 | date = DateHelper.getLastDate(date, a -> true); 45 | } 46 | String time=date.toString(); 47 | List voList = new ArrayList<>(); 48 | List poList = stockDao.getPOList(time); 49 | 50 | for (StockPO aPoList : poList) { 51 | voList.add(new StockVO(aPoList)); 52 | } 53 | return voList; 54 | } 55 | 56 | 57 | /** 58 | * 获取当天的股票行情 59 | * 60 | * @param date 日期 61 | * @return 返回当日的股票数据 62 | */ 63 | public StockMarketVO getMarketVO(LocalDate date) throws StockNoneException { 64 | 65 | while (holidays.isHoliday(date)) { 66 | date = date.minusDays(1); 67 | } 68 | 69 | List polist = stockDao.getPOList(date.toString()); 70 | if(polist == null|| polist.size()==0){ 71 | throw new StockNoneException("输入日期当日没有股票成交!"); 72 | } 73 | 74 | long volume = 0;//当日的成交量 75 | int amountOfLimitUp = 0;//涨停股票的数目 76 | int amountOfLimitDown = 0;//跌停股票数目 77 | int amountOf5PercentUp = 0;//涨幅超过5%的数目 78 | int amountOf5PercentDown = 0;//跌幅超过5%的数目 79 | int amountOf5PercentUptolastClose = 0;//开盘减去收盘大于5%*上个收盘指数的股票数目 80 | int amountOf5PercentDowntolastClose = 0;//开盘减去收盘小于-5%*上个收盘指数的股票数目 81 | 82 | for (StockPO po : polist) { 83 | volume += po.getVolume(); 84 | 85 | //使用lambda表达式输入过滤条件(有效日期)作为参数 86 | double lastClose = po.getLastClose(); 87 | double currentClose = po.getAdj_close(); 88 | 89 | if (lastClose < currentClose) { 90 | double percent = (currentClose - lastClose) / lastClose; 91 | if (percent >= (10 - 0.01*100/lastClose)) { 92 | amountOfLimitUp++; 93 | } else if (percent > 0.05) { 94 | amountOf5PercentUp++; 95 | } 96 | } else { 97 | double percent = (lastClose - currentClose) / lastClose; 98 | if (Math.abs(percent - 0.1) < 0.0000001) { 99 | amountOfLimitDown++; 100 | } else if (percent > 0.05) { 101 | amountOf5PercentDown++; 102 | } 103 | } 104 | 105 | double openDiffClose = po.getOpen() - po.getClose();//开盘减去收盘 106 | double lastSum = lastClose * 0.05; 107 | if (openDiffClose > lastSum) { 108 | amountOf5PercentUptolastClose++; 109 | } 110 | if (openDiffClose < -lastSum) { 111 | amountOf5PercentDowntolastClose++; 112 | } 113 | 114 | } 115 | 116 | return new StockMarketVO(volume,amountOfLimitUp,amountOfLimitDown,amountOf5PercentUp,amountOf5PercentDown,amountOf5PercentUptolastClose,amountOf5PercentDowntolastClose); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/dao/daoutils/UpdateMysqlDaily.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao.daoutils; 2 | 3 | import org.quartz.*; 4 | import org.quartz.impl.StdSchedulerFactory; 5 | 6 | import static org.quartz.JobBuilder.newJob; 7 | 8 | /** 9 | * Created by dell- on 2017/5/15. 10 | */ 11 | public class UpdateMysqlDaily { 12 | 13 | public void run(String code,String market) throws Exception{ 14 | 15 | // //用工厂模式构建Scheduler的Factory,其中STD为Quartz默认的Factory 16 | // SchedulerFactory schedulerfactory=new StdSchedulerFactory(); 17 | // //通过schedulerFactory获取一个调度器对象 18 | // Scheduler scheduler=null; 19 | // try{ 20 | // //通过schedulerFactory获取一个调度器 21 | // scheduler=schedulerfactory.getScheduler(); 22 | // 23 | // //创建jobDetail实例,绑定Job实现类 24 | // //指明job的名称,所在组的名称,以及绑定job类 25 | // JobDetail job=JobBuilder.newJob(UpdateMysqlDailyJob.class).withIdentity("job1", "group1").build(); 26 | // 27 | // //传递参数给execute方法 28 | // job.getJobDataMap().put("code", code); 29 | // job.getJobDataMap().put("market", market); 30 | // //定义调度触发规则 31 | // //使用simpleTrigger规则 32 | //// Trigger trigger=TriggerBuilder.newTrigger().withIdentity("simpleTrigger", "triggerGroup") 33 | //// .withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(1).withRepeatCount(8)) 34 | //// .startNow().build(); 35 | // 36 | // //使用cornTrigger规则 每隔2秒钟 37 | // Trigger trigger=TriggerBuilder.newTrigger().withIdentity("simpleTrigger", "triggerGroup") 38 | // .withSchedule(CronScheduleBuilder.cronSchedule("0/2 * * * * ?") 39 | // ).build(); 40 | // 41 | // //把作业和触发器注册到任务调度中 42 | // scheduler.scheduleJob(job, trigger); 43 | // 44 | // //启动调度 45 | // scheduler.start(); 46 | // try { 47 | // // 当前线程等待0.1秒 48 | // Thread.sleep(10L * 10L); 49 | // } catch (Exception e) { 50 | // e.printStackTrace(); 51 | // } 52 | // scheduler.shutdown(); 53 | // }catch(Exception e){ 54 | // e.printStackTrace(); 55 | // } 56 | } 57 | 58 | public static void main(String[] args) { 59 | UpdateMysqlDaily test = new UpdateMysqlDaily(); 60 | try { 61 | // String[] codeList = {"000001", "000002"}; 62 | // String market = "sz"; //新浪的市场是要小写的 63 | // for(String code:codeList) { 64 | // test.run(code, market); 65 | // } 66 | test.insertDaily(); 67 | } catch (Exception e) { 68 | e.printStackTrace(); 69 | } 70 | } 71 | 72 | public void insertDaily() throws Exception{ 73 | 74 | //用工厂模式构建Scheduler的Factory,其中STD为Quartz默认的Factory 75 | SchedulerFactory schedulerfactory=new StdSchedulerFactory(); 76 | 77 | //通过schedulerFactory获取一个调度器对象 78 | Scheduler scheduler=null; 79 | 80 | try{ 81 | //通过schedulerFactory获取一个调度器 82 | scheduler=schedulerfactory.getScheduler(); 83 | 84 | //创建jobDetail实例,绑定Job实现类 85 | //指明job的名称,所在组的名称,以及绑定job类 86 | JobDetail job=JobBuilder.newJob(UpdateMysqlDailyJob.class).withIdentity("job1", "group1").build(); 87 | 88 | //定义调度触发规则 89 | //使用simpleTrigger规则 90 | // Trigger trigger=TriggerBuilder.newTrigger().withIdentity("simpleTrigger", "triggerGroup") 91 | // .withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(1).withRepeatCount(8)) 92 | // .startNow().build(); 93 | 94 | //使用cornTrigger规则 每天9点执行 95 | Trigger trigger=TriggerBuilder.newTrigger().withIdentity("simpleTrigger", "triggerGroup") 96 | .withSchedule(CronScheduleBuilder.cronSchedule("0 0 9 * * ?") 97 | ).build(); 98 | 99 | //把作业和触发器注册到任务调度中 100 | scheduler.scheduleJob(job, trigger); 101 | 102 | //启动调度 103 | scheduler.start(); 104 | 105 | //任务结束后结束 106 | //scheduler.shutdown(true); 107 | }catch(Exception e){ 108 | e.printStackTrace(); 109 | } 110 | } 111 | 112 | 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/dao/daoutils/InsertTodayStockRun.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao.daoutils; 2 | 3 | import org.quartz.*; 4 | import org.quartz.impl.StdSchedulerFactory; 5 | import org.springframework.stereotype.Component; 6 | 7 | import static org.quartz.JobBuilder.newJob; 8 | 9 | /** 10 | * Created by dell- on 2017/5/15. 11 | */ 12 | @Component 13 | public class InsertTodayStockRun { 14 | 15 | public void run(String code,String market) throws Exception{ 16 | 17 | // //用工厂模式构建Scheduler的Factory,其中STD为Quartz默认的Factory 18 | // SchedulerFactory schedulerfactory=new StdSchedulerFactory(); 19 | // //通过schedulerFactory获取一个调度器对象 20 | // Scheduler scheduler=null; 21 | // try{ 22 | // //通过schedulerFactory获取一个调度器 23 | // scheduler=schedulerfactory.getScheduler(); 24 | // 25 | // //创建jobDetail实例,绑定Job实现类 26 | // //指明job的名称,所在组的名称,以及绑定job类 27 | // JobDetail job=JobBuilder.newJob(UpdateMysqlDailyJob.class).withIdentity("job1", "group1").build(); 28 | // 29 | // //传递参数给execute方法 30 | // job.getJobDataMap().put("code", code); 31 | // job.getJobDataMap().put("market", market); 32 | // //定义调度触发规则 33 | // //使用simpleTrigger规则 34 | //// Trigger trigger=TriggerBuilder.newTrigger().withIdentity("simpleTrigger", "triggerGroup") 35 | //// .withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(1).withRepeatCount(8)) 36 | //// .startNow().build(); 37 | // 38 | // //使用cornTrigger规则 每隔2秒钟 39 | // Trigger trigger=TriggerBuilder.newTrigger().withIdentity("simpleTrigger", "triggerGroup") 40 | // .withSchedule(CronScheduleBuilder.cronSchedule("0/2 * * * * ?") 41 | // ).build(); 42 | // 43 | // //把作业和触发器注册到任务调度中 44 | // scheduler.scheduleJob(job, trigger); 45 | // 46 | // //启动调度 47 | // scheduler.start(); 48 | // try { 49 | // // 当前线程等待0.1秒 50 | // Thread.sleep(10L * 10L); 51 | // } catch (Exception e) { 52 | // e.printStackTrace(); 53 | // } 54 | // scheduler.shutdown(); 55 | // }catch(Exception e){ 56 | // e.printStackTrace(); 57 | // } 58 | } 59 | 60 | public static void main(String[] args) { 61 | InsertTodayStockRun test = new InsertTodayStockRun(); 62 | try { 63 | // String[] codeList = {"000001", "000002"}; 64 | // String market = "sz"; //新浪的市场是要小写的 65 | // for(String code:codeList) { 66 | // test.run(code, market); 67 | // } 68 | test.insertDaily(); 69 | } catch (Exception e) { 70 | e.printStackTrace(); 71 | } 72 | } 73 | 74 | public void insertDaily() throws Exception{ 75 | 76 | //用工厂模式构建Scheduler的Factory,其中STD为Quartz默认的Factory 77 | SchedulerFactory schedulerfactory=new StdSchedulerFactory(); 78 | 79 | //通过schedulerFactory获取一个调度器对象 80 | Scheduler scheduler=null; 81 | 82 | try{ 83 | //通过schedulerFactory获取一个调度器 84 | scheduler=schedulerfactory.getScheduler(); 85 | 86 | //创建jobDetail实例,绑定Job实现类 87 | //指明job的名称,所在组的名称,以及绑定job类 88 | JobDetail job=JobBuilder.newJob(InsertTodayStockJob.class).withIdentity("job1", "group1").build(); 89 | 90 | //定义调度触发规则 91 | //使用simpleTrigger规则 92 | // Trigger trigger=TriggerBuilder.newTrigger().withIdentity("simpleTrigger", "triggerGroup") 93 | // .withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(1).withRepeatCount(8)) 94 | // .startNow().build(); 95 | 96 | //使用cornTrigger规则 每天9点执行 97 | Trigger trigger=TriggerBuilder.newTrigger().withIdentity("simpleTrigger", "triggerGroup") 98 | .withSchedule(CronScheduleBuilder.cronSchedule("0 0 9 * * ?") 99 | ).build(); 100 | 101 | //把作业和触发器注册到任务调度中 102 | scheduler.scheduleJob(job, trigger); 103 | 104 | //启动调度 105 | scheduler.start(); 106 | 107 | //任务结束后结束 108 | //scheduler.shutdown(true); 109 | }catch(Exception e){ 110 | e.printStackTrace(); 111 | } 112 | } 113 | 114 | 115 | } 116 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/strategy/StrategyRunner.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.strategy; 2 | 3 | import cn.edu.nju.p.utils.CalculateHelper; 4 | import cn.edu.nju.p.utils.DoubleUtils; 5 | import cn.edu.nju.p.utils.StockHelper; 6 | import cn.edu.nju.p.utils.beans.ToolSpring; 7 | import cn.edu.nju.p.utils.holiday.Holidays; 8 | import cn.edu.nju.p.utils.redis.StockRedisDataUtils; 9 | import com.alibaba.fastjson.JSON; 10 | import org.datavec.api.formats.input.impl.LibSvmInputFormat; 11 | 12 | import java.math.BigDecimal; 13 | import java.time.LocalDate; 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | import java.util.Map; 17 | import java.util.stream.Collectors; 18 | 19 | /** 20 | * Created by Xihao on 2017/6/14. 21 | */ 22 | public class StrategyRunner { 23 | 24 | public static void run(Strategy strategy) { 25 | 26 | Holidays holidays = ToolSpring.getBeans(Holidays.class); 27 | StockHelper stockHelper = ToolSpring.getBeans(StockHelper.class); 28 | CalculateHelper calculateHelper = ToolSpring.getBeans(CalculateHelper.class); 29 | 30 | List stockPool = strategy.setStockPool(); 31 | LocalDate beginDate = strategy.setBeginDate(); 32 | LocalDate endDate = strategy.setEndDate(); 33 | int holdingDay = strategy.setHoldingDay(); 34 | int formativeDay = strategy.setFormativeDayNum(); 35 | 36 | LocalDate virBeginDate = holidays.getIntervalEffectiveDate(beginDate, formativeDay); 37 | List betweenDates = holidays.getBetweenDatesAndFilter(virBeginDate, endDate, a -> true); 38 | 39 | List dailyYieldRates = new ArrayList<>(); 40 | List accumulationYieldRates = new ArrayList<>(); 41 | 42 | List stockToHold = strategy.setWinner(virBeginDate, holidays.getLastValidDate(betweenDates.get(0)),stockPool); 43 | 44 | double beginClose = stockHelper.calculateTotalClose(stockToHold, betweenDates.get(0)); //初始总收盘价 45 | int moneyPer100 = new BigDecimal(100 * beginClose).intValue(); 46 | 47 | int primaryMoney = 100000; 48 | int totalMoney = 100000; 49 | int nums = primaryMoney / moneyPer100; 50 | int leftMoney = primaryMoney - nums * moneyPer100; 51 | int lastMoney = primaryMoney; 52 | 53 | //计算策略收益率 54 | for (int i = 1; i < betweenDates.size(); i++) { 55 | LocalDate currentDate = betweenDates.get(i); 56 | if (i % holdingDay == 0) { 57 | //整除 重新选择股票 58 | virBeginDate = holidays.getIntervalEffectiveDate(currentDate, formativeDay); 59 | stockToHold = strategy.setWinner(virBeginDate, holidays.getLastValidDate(currentDate), stockPool); 60 | beginClose = stockHelper.calculateTotalClose(stockToHold, betweenDates.get(i - 1)); 61 | moneyPer100 = new BigDecimal(100 * beginClose).intValue(); 62 | nums = lastMoney / moneyPer100; 63 | leftMoney = lastMoney - nums * moneyPer100; 64 | } 65 | 66 | double totalClose = stockHelper.calculateTotalClose(stockToHold, currentDate); 67 | totalMoney = new BigDecimal(totalClose * 100).intValue() * nums + leftMoney; //当前总资产 68 | 69 | dailyYieldRates.add(DoubleUtils.formatDouble((double) (totalMoney - lastMoney) / lastMoney, 4)); 70 | accumulationYieldRates.add(DoubleUtils.formatDouble((double) (totalMoney - primaryMoney) / primaryMoney, 4)); 71 | lastMoney = totalMoney; 72 | } 73 | 74 | //基准收益率 取股票池中所有股票的平均收益 75 | ArrayList> maps = stockHelper.getPrimaryRate(stockPool, betweenDates); 76 | 77 | calculateHelper.setDailyYieldRates(dailyYieldRates); 78 | calculateHelper.setAccumulationYieldRates(accumulationYieldRates); 79 | calculateHelper.setDailyPrimaryRates(maps.get(0)); 80 | calculateHelper.setAccumulationPrimaryRates(maps.get(1)); 81 | 82 | double beta = calculateHelper.getBeta(); 83 | double alpha = calculateHelper.getAlpha(); 84 | double primaryYearYield = calculateHelper.getPrimaryYearRate(); 85 | double yearYield = calculateHelper.getFieldYearRate(); 86 | double shapeRatio = calculateHelper.getShapeRatio(); 87 | double maxDrawDown = calculateHelper.getMaxDrawDown(); 88 | 89 | List dateList = betweenDates.parallelStream().map(LocalDate::toString).sorted().collect(Collectors.toList()); 90 | 91 | String jsonString = JSON.toJSONString(new StrategyResultVO(maps.get(1), accumulationYieldRates, dateList, beta, alpha, shapeRatio, maxDrawDown, yearYield, primaryYearYield)); 92 | System.out.println(jsonString); 93 | 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/vo/MomentumResultVO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.vo; 2 | 3 | import cn.edu.nju.p.utils.DoubleUtils; 4 | 5 | import java.io.Serializable; 6 | import java.time.LocalDate; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | 12 | /** 13 | * Created by xihao on 17-3-30. 14 | */ 15 | public class MomentumResultVO implements Serializable{ 16 | 17 | private List primaryRates; 18 | private List yieldRates; 19 | private List dateList; 20 | 21 | private Map rateFrequency; //收益率频数 22 | 23 | private double beta ; 24 | private double alpha; 25 | private double shapeRatio; 26 | private double maxDrawnDown; 27 | private double yearYield; 28 | private double primaryYearYield; 29 | 30 | private List winRates; 31 | private List rateNums; 32 | 33 | public MomentumResultVO(List primaryRates, List yieldRates, List dateList, Map rateFrequency, double beta, double alpha, double shapeRatio, double maxDrawnDown, double yearYield, double primaryYearYield) { 34 | this.primaryRates = primaryRates; 35 | this.yieldRates = yieldRates; 36 | this.dateList = dateList; 37 | this.rateFrequency = rateFrequency; 38 | this.beta = beta; 39 | this.alpha = alpha; 40 | this.shapeRatio = shapeRatio; 41 | this.maxDrawnDown = maxDrawnDown; 42 | this.yearYield = yearYield; 43 | this.primaryYearYield = primaryYearYield; 44 | this.winRates = new ArrayList<>(rateFrequency.keySet()); 45 | this.rateNums = new ArrayList<>(rateFrequency.values()); 46 | } 47 | 48 | public List getPrimaryRates() { 49 | return DoubleUtils.adjDoubleList(primaryRates); 50 | } 51 | 52 | public void setPrimaryRates(List primaryRates) { 53 | this.primaryRates = primaryRates; 54 | } 55 | 56 | public List getYieldRates() { 57 | return DoubleUtils.adjDoubleList(yieldRates); 58 | } 59 | 60 | public void setYieldRates(List yieldRates) { 61 | this.yieldRates = yieldRates; 62 | } 63 | 64 | public List getDateList() { 65 | return dateList; 66 | } 67 | 68 | public void setDateList(List dateList) { 69 | this.dateList = dateList; 70 | } 71 | 72 | public Map getRateFrequency() { 73 | return rateFrequency; 74 | } 75 | 76 | public void setRateFrequency(Map rateFrequency) { 77 | this.rateFrequency = rateFrequency; 78 | } 79 | 80 | public double getBeta() { 81 | return beta; 82 | } 83 | 84 | public void setBeta(double beta) { 85 | this.beta = beta; 86 | } 87 | 88 | public double getAlpha() { 89 | return alpha; 90 | } 91 | 92 | public void setAlpha(double alpha) { 93 | this.alpha = alpha; 94 | } 95 | 96 | public double getShapeRatio() { 97 | return shapeRatio; 98 | } 99 | 100 | public void setShapeRatio(double shapeRatio) { 101 | this.shapeRatio = shapeRatio; 102 | } 103 | 104 | public double getMaxDrawnDown() { 105 | return maxDrawnDown; 106 | } 107 | 108 | public void setMaxDrawnDown(double maxDrawnDown) { 109 | this.maxDrawnDown = maxDrawnDown; 110 | } 111 | 112 | public double getYearYield() { 113 | return yearYield; 114 | } 115 | 116 | public void setYearYield(double yearYield) { 117 | this.yearYield = yearYield; 118 | } 119 | 120 | public double getPrimaryYearYield() { 121 | return primaryYearYield; 122 | } 123 | 124 | public void setPrimaryYearYield(double primaryYearYield) { 125 | this.primaryYearYield = primaryYearYield; 126 | } 127 | 128 | public List getWinRates() { 129 | return winRates; 130 | } 131 | 132 | public void setWinRates(List winRates) { 133 | this.winRates = winRates; 134 | } 135 | 136 | public List getRateNums() { 137 | return rateNums; 138 | } 139 | 140 | public void setRateNums(List rateNums) { 141 | this.rateNums = rateNums; 142 | } 143 | 144 | @Override 145 | public String toString() { 146 | return "MomentumResultVO{" + 147 | "primaryRates=" + primaryRates + 148 | ", yieldRates=" + yieldRates + 149 | ", dateList=" + dateList + 150 | ", rateFrequency=" + rateFrequency + 151 | ", beta=" + beta + 152 | ", alpha=" + alpha + 153 | ", shapeRatio=" + shapeRatio + 154 | ", maxDrawnDown=" + maxDrawnDown + 155 | ", yearYield=" + yearYield + 156 | ", primaryYearYield=" + primaryYearYield + 157 | '}'; 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/vo/StockVO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.vo; 2 | 3 | 4 | import cn.edu.nju.p.po.StockPO; 5 | 6 | /** 7 | * serial 记录编号 8 | * date 日期(月/日/年) 9 | * open 开盘指数 10 | * high 最高指数 11 | * low 最低指数 12 | * close 收盘指数 13 | * volume 成交量 14 | * adjClose 复权后的收盘指数 15 | * code 股票代码 16 | * name 股票名称 17 | * market 市场名称 18 | * time 查询时间 19 | * currentPrice 目前价格 20 | * quote_change 涨跌幅 21 | * turnover 成交金额 22 | * isopen 是否开盘 23 | * lastClose 昨日收盘价 24 | * 25 | * @author dc 26 | * 27 | */ 28 | 29 | public class StockVO { 30 | 31 | // private int serial; 32 | private String date; 33 | private double open; 34 | private double high; 35 | private double low; 36 | private double close; 37 | private long volume; 38 | private double adj_close; 39 | private String code; 40 | private String name; 41 | private String market; 42 | private String time; 43 | private double currentPrice; 44 | private String quote_change; 45 | private String turnover; 46 | private boolean isOpen; 47 | private double lastClose; 48 | 49 | public StockVO(StockPO po){ 50 | // this.serial=po.getSerial(); 51 | this.date=po.getDate(); 52 | this.open=po.getOpen(); 53 | this.high=po.getHigh(); 54 | this.low=po.getLow(); 55 | this.close=po.getClose(); 56 | this.volume=po.getVolume(); 57 | this.adj_close=po.getAdj_close(); 58 | this.code=po.getCode(); 59 | this.name=po.getName(); 60 | this.market=po.getMarket(); 61 | this.time = po.getTime(); 62 | this.currentPrice = po.getCurrentPrice(); 63 | this.quote_change = po.getQuote_change(); 64 | this.turnover = po.getTurnover(); 65 | this.isOpen = po.getIsOpen(); 66 | this.lastClose = po.getLastClose(); 67 | } 68 | 69 | public String getDate() { 70 | return date; 71 | } 72 | 73 | public void setDate(String date) { 74 | this.date = date; 75 | } 76 | 77 | public double getOpen() { 78 | return open; 79 | } 80 | 81 | public void setOpen(double open) { 82 | this.open = open; 83 | } 84 | 85 | public String getTime() { 86 | return time; 87 | } 88 | 89 | public void setTime(String time) { 90 | this.time = time; 91 | } 92 | 93 | public double getHigh() { 94 | return high; 95 | } 96 | 97 | public void setHigh(double high) { 98 | this.high = high; 99 | } 100 | 101 | public double getLow() { 102 | return low; 103 | } 104 | 105 | public void setLow(double low) { 106 | this.low = low; 107 | } 108 | 109 | public double getClose() { 110 | return close; 111 | } 112 | 113 | public void setClose(double close) { 114 | this.close = close; 115 | } 116 | 117 | public long getVolume() { 118 | return volume; 119 | } 120 | 121 | public void setVolume(long volume) { 122 | this.volume = volume; 123 | } 124 | 125 | public double getAdj_close() { 126 | return adj_close; 127 | } 128 | 129 | public void setAdj_close(double adj_close) { 130 | this.adj_close = adj_close; 131 | } 132 | 133 | public String getCode() { 134 | return code; 135 | } 136 | 137 | public void setCode(String code) { 138 | this.code = code; 139 | } 140 | 141 | public String getName() { 142 | return name; 143 | } 144 | 145 | public void setName(String name) { 146 | this.name = name; 147 | } 148 | 149 | public String getMarket() { 150 | return market; 151 | } 152 | 153 | public void setMarket(String market) { 154 | this.market = market; 155 | } 156 | 157 | public double getCurrentPrice() { 158 | return currentPrice; 159 | } 160 | 161 | public void setCurrentPrice(double currentPrice) { 162 | this.currentPrice = currentPrice; 163 | } 164 | 165 | public String getQuote_change() { 166 | return quote_change; 167 | } 168 | 169 | public void setQuote_change(String quote_change) { 170 | this.quote_change = quote_change; 171 | } 172 | 173 | public String getTurnover() { 174 | return turnover; 175 | } 176 | 177 | public void setTurnover(String turnover) { 178 | this.turnover = turnover; 179 | } 180 | 181 | public boolean getIsOpen() { 182 | return isOpen; 183 | } 184 | 185 | public void setIsOpen(boolean isOpen) { 186 | this.isOpen = isOpen; 187 | } 188 | 189 | public double getLastClose() { 190 | return lastClose; 191 | } 192 | 193 | public void setLastClose(double lastClose) { 194 | this.lastClose = lastClose; 195 | } 196 | 197 | @Override 198 | public String toString() { 199 | return "StockVO{" + 200 | "date='" + date + '\'' + 201 | ", open=" + open + 202 | ", high=" + high + 203 | ", low=" + low + 204 | ", close=" + close + 205 | ", volume=" + volume + 206 | ", adj_close=" + adj_close + 207 | ", code='" + code + '\'' + 208 | ", name='" + name + '\'' + 209 | ", market='" + market + '\'' + 210 | ", time='" + time + '\'' + 211 | ", currentPrice=" + currentPrice + 212 | ", quote_change='" + quote_change + '\'' + 213 | ", turnover='" + turnover + '\'' + 214 | ", isOpen=" + isOpen + 215 | ", lastClose=" + lastClose + 216 | '}'; 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /src/test/java/cn/edu/nju/p/dao/StockDaoTest.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.dao; 2 | 3 | import cn.edu.nju.p.po.StockPO; 4 | import cn.edu.nju.p.utils.DateHelper; 5 | import cn.edu.nju.p.utils.StockHelper; 6 | import org.apache.tomcat.jni.Local; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.test.context.SpringBootTest; 11 | import org.springframework.test.context.junit4.SpringRunner; 12 | import org.springframework.test.context.web.WebAppConfiguration; 13 | 14 | import java.time.LocalDate; 15 | import java.time.Month; 16 | import java.util.List; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | /** 20 | * attention! must use the mysql on the server,because the column current_time has been modified. 21 | */ 22 | @RunWith(SpringRunner.class) 23 | @WebAppConfiguration 24 | @SpringBootTest 25 | public class StockDaoTest { 26 | 27 | @Autowired 28 | // 提示说没有找到bean?????? 29 | private StockDao stockDao; 30 | private LocalDate date = LocalDate.of(2017, 6, 13); 31 | private String code = "002166"; 32 | private String name = "深发展A"; 33 | 34 | 35 | @Test 36 | public void getStockPO() throws Exception { 37 | System.out.println("================================================="); 38 | StockPO po = stockDao.getStockPO(code, date); 39 | if (po == null) { 40 | System.out.println("po是null!!"); 41 | } else { 42 | System.out.println(po.toString()); 43 | } 44 | System.out.println("=================================================="); 45 | } 46 | 47 | @Test 48 | public void getStockOpen() throws Exception { 49 | // assertEquals(stockDao.getStockOpen(code, date), 18.01, 0.01); 50 | System.out.println(stockDao.getStockOpen(code,date)); 51 | } 52 | 53 | @Test 54 | public void getStockHigh() throws Exception { 55 | assertEquals(stockDao.getStockHigh(code, date), 18.92, 0.01); 56 | } 57 | 58 | @Test 59 | public void getStockLow() throws Exception { 60 | assertEquals(stockDao.getStockLow("001", date), 18.00, 0.01); 61 | } 62 | 63 | @Test 64 | public void getStockClose() throws Exception { 65 | assertEquals(stockDao.getStockClose("000001", LocalDate.of(2012,10,20)), 18.68, 0.01); 66 | } 67 | 68 | @Test 69 | public void getStockVolume() throws Exception { 70 | System.out.println(stockDao.getStockVolume(code, date)); 71 | } 72 | 73 | @Test 74 | public void getStockAdjClose() throws Exception { 75 | assertEquals(stockDao.getStockAdjClose(code, date), 6.66, 0.01); 76 | } 77 | 78 | @Test 79 | public void getStockName() throws Exception { 80 | assertEquals(stockDao.getStockName(code), "深发展A"); 81 | } 82 | 83 | @Test 84 | public void getStockMarket() throws Exception { 85 | assertEquals(stockDao.getStockMarket(code), "SZ"); 86 | } 87 | 88 | @Test 89 | public void getStockCode() throws Exception { 90 | assertEquals("000001", stockDao.getStockCode(name)); 91 | } 92 | 93 | @Test 94 | public void getPOList() throws Exception { 95 | List poList = stockDao.getPOList(date.toString()); 96 | for (int i=0;i<1000;i++) { 97 | System.out.println(poList.get(i).getVolume()); 98 | } 99 | } 100 | 101 | 102 | @Test 103 | public void getStockSector() throws Exception { 104 | 105 | } 106 | 107 | @Test 108 | public void getStockBySector() throws Exception { 109 | 110 | } 111 | 112 | @Test 113 | public void getAllStocks() throws Exception { 114 | 115 | System.out.println(stockDao.getAllStocks().size() + "---->" + stockDao.getAllStocks()); 116 | } 117 | 118 | @Test 119 | public void insertIntoStockDatabase() throws Exception { 120 | 121 | } 122 | 123 | @Test 124 | public void testIsOpen() throws Exception { 125 | 126 | String code = "000001"; 127 | LocalDate date = LocalDate.of(2008, 1, 2); 128 | System.out.println(stockDao.getStockIsOpen(code,date)); 129 | } 130 | 131 | @Test 132 | public void getIsOpenTest2() throws Exception { 133 | String code = "000001"; 134 | LocalDate date = LocalDate.of(2008, 6, 12); 135 | System.out.println(stockDao.getStockIsOpen(code, date)); 136 | } 137 | 138 | @Test 139 | public void testUpdate() throws Exception { 140 | StockPO po = new StockPO(); 141 | po.setName("测试"); 142 | po.setDate("2017-06-14"); 143 | po.setCode("000001"); 144 | po.setOpen(-1); 145 | po.setHigh(-2); 146 | po.setLow(-3); 147 | po.setClose(-4); 148 | po.setAdj_close(-4); 149 | po.setLastClose(-5); 150 | po.setVolume(666); 151 | po.setQuote_change("quo"); 152 | po.setMarket("深圳呀"); 153 | po.setIsOpen(true); 154 | 155 | stockDao.updateStockDatabase("2017", po); 156 | } 157 | } -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/po/TestStockPO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.po; 2 | 3 | /** 4 | * Created by dc on 2017/6/8. 5 | */ 6 | public class TestStockPO { 7 | 8 | private double point; 9 | private String overview; 10 | private String beat; 11 | private String shortTerm_trend; 12 | private String midTerm_trend; 13 | private String longTerm_trend; 14 | private String conclude; 15 | private String testDate; 16 | private String technical_test; 17 | private String fund_test; 18 | private String info_test; 19 | private String industry_test; 20 | private String basic_test; 21 | 22 | public TestStockPO() { 23 | } 24 | 25 | public TestStockPO(double point, String overview, String beat, String shortTerm_trend, String midTerm_trend, String longTerm_trend, String conclude, String testDate, String technical_test, String fund_test, String info_test, String industry_test, String basic_test) { 26 | this.point = point; 27 | this.overview = overview; 28 | this.beat = beat; 29 | this.shortTerm_trend = shortTerm_trend; 30 | this.midTerm_trend = midTerm_trend; 31 | this.longTerm_trend = longTerm_trend; 32 | this.conclude = conclude; 33 | this.testDate = testDate; 34 | this.technical_test = technical_test; 35 | this.fund_test = fund_test; 36 | this.info_test = info_test; 37 | this.industry_test = industry_test; 38 | this.basic_test = basic_test; 39 | } 40 | 41 | public double getPoint() { 42 | return point; 43 | } 44 | 45 | public void setPoint(double point) { 46 | this.point = point; 47 | } 48 | 49 | public String getOverview() { 50 | return overview; 51 | } 52 | 53 | public void setOverview(String overview) { 54 | this.overview = overview; 55 | } 56 | 57 | public String getBeat() { 58 | return beat; 59 | } 60 | 61 | public void setBeat(String beat) { 62 | this.beat = beat; 63 | } 64 | 65 | public String getShortTerm_trend() { 66 | return shortTerm_trend; 67 | } 68 | 69 | public void setShortTerm_trend(String shortTerm_trend) { 70 | this.shortTerm_trend = shortTerm_trend; 71 | } 72 | 73 | public String getMidTerm_trend() { 74 | return midTerm_trend; 75 | } 76 | 77 | public void setMidTerm_trend(String midTerm_trend) { 78 | this.midTerm_trend = midTerm_trend; 79 | } 80 | 81 | public String getLongTerm_trend() { 82 | return longTerm_trend; 83 | } 84 | 85 | public void setLongTerm_trend(String longTerm_trend) { 86 | this.longTerm_trend = longTerm_trend; 87 | } 88 | 89 | public String getConclude() { 90 | return conclude; 91 | } 92 | 93 | public void setConclude(String conclude) { 94 | this.conclude = conclude; 95 | } 96 | 97 | public String getTestDate() { 98 | return testDate; 99 | } 100 | 101 | public void setTestDate(String testDate) { 102 | this.testDate = testDate; 103 | } 104 | 105 | public String getTechnical_test() { 106 | return technical_test; 107 | } 108 | 109 | public void setTechnical_test(String technical_test) { 110 | this.technical_test = technical_test; 111 | } 112 | 113 | public String getFund_test() { 114 | return fund_test; 115 | } 116 | 117 | public void setFund_test(String fund_test) { 118 | this.fund_test = fund_test; 119 | } 120 | 121 | public String getInfo_test() { 122 | return info_test; 123 | } 124 | 125 | public void setInfo_test(String info_test) { 126 | this.info_test = info_test; 127 | } 128 | 129 | public String getIndustry_test() { 130 | return industry_test; 131 | } 132 | 133 | public void setIndustry_test(String industry_test) { 134 | this.industry_test = industry_test; 135 | } 136 | 137 | public String getBasic_test() { 138 | return basic_test; 139 | } 140 | 141 | public void setBasic_test(String basic_test) { 142 | this.basic_test = basic_test; 143 | } 144 | 145 | @Override 146 | public String toString() { 147 | return "TestStockPO{" + 148 | "point=" + point + 149 | ", overview='" + overview + '\'' + 150 | ", beat='" + beat + '\'' + 151 | ", shortTerm_trend='" + shortTerm_trend + '\'' + 152 | ", midTerm_trend='" + midTerm_trend + '\'' + 153 | ", longTerm_trend='" + longTerm_trend + '\'' + 154 | ", conclude='" + conclude + '\'' + 155 | ", testDate='" + testDate + '\'' + 156 | ", technical_test='" + technical_test + '\'' + 157 | ", fund_test='" + fund_test + '\'' + 158 | ", info_test='" + info_test + '\'' + 159 | ", industry_test='" + industry_test + '\'' + 160 | ", basic_test='" + basic_test + '\'' + 161 | '}'; 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /src/main/java/cn/edu/nju/p/vo/MeanReversionResultVO.java: -------------------------------------------------------------------------------- 1 | package cn.edu.nju.p.vo; 2 | 3 | import cn.edu.nju.p.utils.DoubleUtils; 4 | import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils; 5 | 6 | import java.io.Serializable; 7 | import java.time.LocalDate; 8 | import java.util.ArrayList; 9 | import java.util.Collections; 10 | import java.util.List; 11 | import java.util.Map; 12 | 13 | /** 14 | * 均线策略的收益结果 15 | */ 16 | public class MeanReversionResultVO implements Serializable{ 17 | 18 | private List primaryRates; 19 | private List yieldRates; 20 | 21 | private List dateList; 22 | 23 | private Map rateFrequency; //收益率频数 24 | 25 | private List winRates; 26 | private List rateNums; 27 | 28 | private double beta ; 29 | private double alpha; 30 | private double shapeRatio; 31 | private double maxDrawnDown; 32 | private double yearYield; 33 | private double primaryYearYield; 34 | 35 | public MeanReversionResultVO(List primaryRates, List yieldRates, List dateList, Map rateFrequency, double beta, double alpha, double shapeRatio, double maxDrawnDown, double yearYield, double primaryYearYield) { 36 | this.primaryRates = primaryRates; 37 | this.yieldRates = yieldRates; 38 | this.dateList = dateList; 39 | this.rateFrequency = rateFrequency; 40 | this.beta = beta; 41 | this.alpha = alpha; 42 | this.shapeRatio = shapeRatio; 43 | this.maxDrawnDown = maxDrawnDown; 44 | this.yearYield = yearYield; 45 | this.primaryYearYield = primaryYearYield; 46 | 47 | this.winRates = new ArrayList<>(rateFrequency.keySet()); 48 | this.rateNums = new ArrayList<>(rateFrequency.values()); 49 | } 50 | 51 | public List getPrimaryRates() 52 | { 53 | return DoubleUtils.adjDoubleList(primaryRates); 54 | } 55 | 56 | public void setPrimaryRates(List primaryRates) { 57 | this.primaryRates = primaryRates; 58 | } 59 | 60 | public List getYieldRates() { 61 | 62 | return DoubleUtils.adjDoubleList(yieldRates); 63 | } 64 | 65 | public void setYieldRates(List yieldRates) { 66 | this.yieldRates = yieldRates; 67 | } 68 | 69 | public List getDateList() { 70 | return dateList; 71 | } 72 | 73 | public void setDateList(List dateList) { 74 | this.dateList = dateList; 75 | } 76 | 77 | public Map getRateFrequency() { 78 | return rateFrequency; 79 | } 80 | 81 | public void setRateFrequency(Map rateFrequency) { 82 | this.rateFrequency = rateFrequency; 83 | } 84 | 85 | public double getBeta() { 86 | return beta; 87 | } 88 | 89 | public void setBeta(double beta) { 90 | this.beta = beta; 91 | } 92 | 93 | public double getAlpha() { 94 | return alpha; 95 | } 96 | 97 | public void setAlpha(double alpha) { 98 | this.alpha = alpha; 99 | } 100 | 101 | public double getShapeRatio() { 102 | return shapeRatio; 103 | } 104 | 105 | public void setShapeRatio(double shapeRatio) { 106 | this.shapeRatio = shapeRatio; 107 | } 108 | 109 | public double getMaxDrawnDown() { 110 | return maxDrawnDown; 111 | } 112 | 113 | public void setMaxDrawnDown(double maxDrawnDown) { 114 | this.maxDrawnDown = maxDrawnDown; 115 | } 116 | 117 | public double getYearYield() { 118 | return yearYield; 119 | } 120 | 121 | public void setYearYield(double yearYield) { 122 | this.yearYield = yearYield; 123 | } 124 | 125 | public double getPrimaryYearYield() { 126 | return primaryYearYield; 127 | } 128 | 129 | public void setPrimaryYearYield(double primaryYearYield) { 130 | 131 | this.primaryYearYield = primaryYearYield; 132 | } 133 | 134 | public List getWinRates() { 135 | return winRates; 136 | } 137 | 138 | public void setWinRates(List winRates) { 139 | this.winRates = winRates; 140 | } 141 | 142 | public List getRateNums() { 143 | return rateNums; 144 | } 145 | 146 | public void setRateNums(List rateNums) { 147 | this.rateNums = rateNums; 148 | } 149 | 150 | @Override 151 | public String toString() { 152 | return "MeanReversionResultVO{" + 153 | "primaryRates=" + primaryRates + 154 | ", yieldRates=" + yieldRates + 155 | ", dateList=" + dateList + 156 | ", rateFrequency=" + rateFrequency + 157 | ", beta=" + beta + 158 | ", alpha=" + alpha + 159 | ", shapeRatio=" + shapeRatio + 160 | ", maxDrawnDown=" + maxDrawnDown + 161 | ", yearYield=" + yearYield + 162 | ", primaryYearYield=" + primaryYearYield + 163 | '}'; 164 | } 165 | } 166 | --------------------------------------------------------------------------------