├── README ├── robot ├── robot.res ├── u_main.dcu ├── u_main.ddp ├── u_main.pas ├── robot.dpr ├── robot.cfg ├── robot.dof └── u_main.dfm ├── seven ├── seven.res ├── u_main.dcu ├── u_main.ddp ├── u_main.pas ├── seven.dpr ├── seven.cfg └── seven.dof ├── analyzer ├── src │ ├── main │ │ ├── resources │ │ │ └── db.properties │ │ └── java │ │ │ └── cn │ │ │ └── nit │ │ │ └── stock │ │ │ ├── hexin │ │ │ ├── ComplexIndexType.java │ │ │ ├── ColumnHeader.java │ │ │ ├── ComplexIndexBlock.java │ │ │ ├── IntUtils.java │ │ │ ├── MN5File.java │ │ │ ├── MN30File.java │ │ │ ├── D1BarFile.java │ │ │ ├── FileHeader.java │ │ │ ├── ComplexIndexRecord.java │ │ │ ├── DividendFile.java │ │ │ ├── MN5Record.java │ │ │ ├── MN30Record.java │ │ │ ├── D1BarRecord.java │ │ │ └── DividendRecord.java │ │ │ ├── dao │ │ │ └── StockNameRepository.java │ │ │ ├── model │ │ │ ├── Stock.java │ │ │ ├── PatternOne.java │ │ │ ├── PatternTwo.java │ │ │ ├── StockName.java │ │ │ ├── StockLimit.java │ │ │ └── TradeDay.java │ │ │ ├── indicator │ │ │ └── Boll.java │ │ │ ├── ConnUtils.java │ │ │ ├── SeriesLimit.java │ │ │ ├── HistoryToFile.java │ │ │ ├── Simulate5.java │ │ │ ├── HistoryLimit.java │ │ │ ├── HistorySuccessiveLimit.java │ │ │ ├── UniqueDay.java │ │ │ ├── SuccessiveLimit.java │ │ │ ├── AddD1Future.java │ │ │ ├── HistoryNotLimit.java │ │ │ ├── Yesterday.java │ │ │ ├── AddFiveMinute.java │ │ │ ├── Simulate.java │ │ │ ├── SevenMatch.java │ │ │ ├── AddD1Bar.java │ │ │ ├── StockBoard.java │ │ │ ├── HistoryLine.java │ │ │ ├── History.java │ │ │ ├── Name.java │ │ │ ├── Day.java │ │ │ ├── AddDividend.java │ │ │ ├── Capital.java │ │ │ ├── NSHistory.java │ │ │ ├── HalfHour.java │ │ │ ├── SevenGold.java │ │ │ ├── DayLimit.java │ │ │ ├── AddStock.java │ │ │ ├── LimitNotify.java │ │ │ ├── DayFuture.java │ │ │ ├── BoardLine.java │ │ │ ├── Analyzer2.java │ │ │ └── Analyzer.java │ └── test │ │ └── java │ │ └── stock │ │ └── AppTest.java └── pom.xml ├── .gitattributes └── .gitignore /README: -------------------------------------------------------------------------------- 1 | 存放我自己编写的股票相关代码 -------------------------------------------------------------------------------- /robot/robot.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stockcode/stock/HEAD/robot/robot.res -------------------------------------------------------------------------------- /robot/u_main.dcu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stockcode/stock/HEAD/robot/u_main.dcu -------------------------------------------------------------------------------- /robot/u_main.ddp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stockcode/stock/HEAD/robot/u_main.ddp -------------------------------------------------------------------------------- /robot/u_main.pas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stockcode/stock/HEAD/robot/u_main.pas -------------------------------------------------------------------------------- /seven/seven.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stockcode/stock/HEAD/seven/seven.res -------------------------------------------------------------------------------- /seven/u_main.dcu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stockcode/stock/HEAD/seven/u_main.dcu -------------------------------------------------------------------------------- /seven/u_main.ddp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stockcode/stock/HEAD/seven/u_main.ddp -------------------------------------------------------------------------------- /seven/u_main.pas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stockcode/stock/HEAD/seven/u_main.pas -------------------------------------------------------------------------------- /analyzer/src/main/resources/db.properties: -------------------------------------------------------------------------------- 1 | url=jdbc:mysql://115.28.160.121/stock?useUnicode=true&characterEncoding=UTF-8&mysqlEncoding=UTF-8 2 | driver=com.mysql.jdbc.Driver 3 | user=stock 4 | passwd=stock 5 | 6 | mongodbIP=115.28.225.164 7 | mongodb=stock -------------------------------------------------------------------------------- /seven/seven.dpr: -------------------------------------------------------------------------------- 1 | program seven; 2 | 3 | uses 4 | Forms, 5 | u_main in 'u_main.pas' {Form1}; 6 | 7 | {$R *.res} 8 | 9 | begin 10 | Application.Initialize; 11 | Application.CreateForm(TForm1, Form1); 12 | Application.Run; 13 | end. 14 | -------------------------------------------------------------------------------- /robot/robot.dpr: -------------------------------------------------------------------------------- 1 | program robot; 2 | 3 | uses 4 | Forms, 5 | u_main in 'u_main.pas' {frmMain}; 6 | 7 | {$R *.res} 8 | 9 | begin 10 | Application.Initialize; 11 | Application.CreateForm(TfrmMain, frmMain); 12 | Application.Run; 13 | end. 14 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/hexin/ComplexIndexType.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock.hexin; 2 | 3 | 4 | public class ComplexIndexType 5 | { 6 | 7 | public ComplexIndexType() 8 | { 9 | S = 16; 10 | H = 80; 11 | B = 74; 12 | } 13 | 14 | public int S; 15 | public int H; 16 | public int B; 17 | } 18 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/dao/StockNameRepository.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock.dao; 2 | 3 | import cn.nit.stock.model.StockName; 4 | import org.springframework.data.mongodb.repository.MongoRepository; 5 | 6 | /** 7 | * Created by vicky on 2014/10/23. 8 | */ 9 | public interface StockNameRepository extends MongoRepository { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /robot/robot.cfg: -------------------------------------------------------------------------------- 1 | -$A8 2 | -$B- 3 | -$C+ 4 | -$D+ 5 | -$E- 6 | -$F- 7 | -$G+ 8 | -$H+ 9 | -$I+ 10 | -$J- 11 | -$K- 12 | -$L+ 13 | -$M- 14 | -$N+ 15 | -$O+ 16 | -$P+ 17 | -$Q- 18 | -$R- 19 | -$S- 20 | -$T- 21 | -$U- 22 | -$V+ 23 | -$W- 24 | -$X+ 25 | -$YD 26 | -$Z1 27 | -cg 28 | -AWinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE; 29 | -H+ 30 | -W+ 31 | -M 32 | -$M16384,1048576 33 | -K$00400000 34 | -LE"c:\program files\borland\delphi7\Projects\Bpl" 35 | -LN"c:\program files\borland\delphi7\Projects\Bpl" 36 | -w-UNSAFE_TYPE 37 | -w-UNSAFE_CODE 38 | -w-UNSAFE_CAST 39 | -------------------------------------------------------------------------------- /seven/seven.cfg: -------------------------------------------------------------------------------- 1 | -$A8 2 | -$B- 3 | -$C+ 4 | -$D+ 5 | -$E- 6 | -$F- 7 | -$G+ 8 | -$H+ 9 | -$I+ 10 | -$J- 11 | -$K- 12 | -$L+ 13 | -$M- 14 | -$N+ 15 | -$O+ 16 | -$P+ 17 | -$Q- 18 | -$R- 19 | -$S- 20 | -$T- 21 | -$U- 22 | -$V+ 23 | -$W- 24 | -$X+ 25 | -$YD 26 | -$Z1 27 | -cg 28 | -AWinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE; 29 | -H+ 30 | -W+ 31 | -M 32 | -$M16384,1048576 33 | -K$00400000 34 | -LE"c:\program files\borland\delphi7\Projects\Bpl" 35 | -LN"c:\program files\borland\delphi7\Projects\Bpl" 36 | -w-UNSAFE_TYPE 37 | -w-UNSAFE_CODE 38 | -w-UNSAFE_CAST 39 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/model/Stock.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock.model; 2 | 3 | public class Stock { 4 | public String stockCode, tradedate, status; 5 | public Double costPrice, costMoney; 6 | public Integer amount ,index ; 7 | 8 | @Override 9 | public String toString() { 10 | java.text.DecimalFormat df=new java.text.DecimalFormat( "#.## "); 11 | return "Stock [amount=" + amount + ", costMoney=" + df.format(costMoney) 12 | + ", costPrice=" + df.format(costPrice) + ", stockCode=" + stockCode 13 | + ", tradedate=" + tradedate + "]"; 14 | } 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/model/PatternOne.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock.model; 2 | 3 | //模型1,特指第一天涨停回落,第二天封住涨停的形态 4 | public class PatternOne { 5 | TradeDay first, second; 6 | 7 | public PatternOne(TradeDay first, TradeDay second) { 8 | super(); 9 | this.first = first; 10 | this.second = second; 11 | } 12 | 13 | 14 | public Boolean isMatch() { 15 | return first.isHighestLimt() && second.isHighLimit(); 16 | } 17 | 18 | 19 | @Override 20 | public String toString() { 21 | StringBuilder builder = new StringBuilder(); 22 | builder.append("PatternOne [first="); 23 | builder.append(first); 24 | builder.append(", second="); 25 | builder.append(second); 26 | builder.append("]"); 27 | return builder.toString(); 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /analyzer/src/test/java/stock/AppTest.java: -------------------------------------------------------------------------------- 1 | package stock; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/model/PatternTwo.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock.model; 2 | 3 | //模型1,特指第一天涨停回落,第二天封住涨停的形态 4 | public class PatternTwo { 5 | TradeDay first, second, third; 6 | 7 | public PatternTwo(TradeDay first, TradeDay second, TradeDay third) { 8 | super(); 9 | this.first = first; 10 | this.second = second; 11 | this.third = third; 12 | } 13 | 14 | 15 | public Boolean isMatch() { 16 | return first.isHighLimit() && third.isHighLimit(); 17 | } 18 | 19 | 20 | @Override 21 | public String toString() { 22 | StringBuilder builder = new StringBuilder(); 23 | builder.append("PatternTwo [first="); 24 | builder.append(first); 25 | builder.append(", second="); 26 | builder.append(second); 27 | builder.append(", third="); 28 | builder.append(third); 29 | builder.append("]"); 30 | return builder.toString(); 31 | } 32 | 33 | 34 | 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/model/StockName.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock.model; 2 | 3 | import com.mongodb.DBObject; 4 | import org.bson.types.ObjectId; 5 | import org.mongodb.morphia.annotations.Entity; 6 | import org.mongodb.morphia.annotations.Id; 7 | 8 | /** 9 | * Created by vicky on 2014/10/22. 10 | */ 11 | @Entity 12 | public class StockName { 13 | 14 | @Id 15 | private ObjectId id; 16 | 17 | private String name,code; 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public void setName(String name) { 24 | this.name = name; 25 | } 26 | 27 | public String getCode() { 28 | return code; 29 | } 30 | 31 | public void setCode(String code) { 32 | this.code = code; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return "StockName{" + 38 | "name='" + name + '\'' + 39 | ", code='" + code + '\'' + 40 | '}'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/hexin/ColumnHeader.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock.hexin; 2 | 3 | import java.io.IOException; 4 | import java.io.RandomAccessFile; 5 | 6 | public class ColumnHeader 7 | { 8 | 9 | public ColumnHeader() 10 | { 11 | } 12 | 13 | public static Boolean Read(ColumnHeader header, RandomAccessFile file) 14 | { 15 | if(file == null) 16 | return Boolean.valueOf(false); 17 | try 18 | { 19 | header.w1 = file.readByte(); 20 | header.type = file.readByte(); 21 | header.w2 = file.readByte(); 22 | header.size = file.readByte(); 23 | } 24 | catch(IOException e) 25 | { 26 | e.printStackTrace(); 27 | } 28 | return Boolean.valueOf(true); 29 | } 30 | 31 | 32 | 33 | @Override 34 | public String toString() { 35 | return "ColumnHeader [w1=" + w1 + ", type=" + type + ", w2=" + w2 36 | + ", size=" + size + "]"; 37 | } 38 | 39 | 40 | 41 | private byte w1; 42 | private byte type; 43 | private byte w2; 44 | private byte size; 45 | public static int LENGTH = 4; 46 | 47 | } -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/hexin/ComplexIndexBlock.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock.hexin; 2 | 3 | import java.io.IOException; 4 | import java.io.RandomAccessFile; 5 | 6 | public class ComplexIndexBlock 7 | { 8 | 9 | public ComplexIndexBlock() 10 | { 11 | } 12 | 13 | public static Boolean Read(ComplexIndexBlock block, RandomAccessFile file) 14 | throws IOException 15 | { 16 | if(file == null) 17 | return Boolean.valueOf(false); 18 | long FPosition = file.getFilePointer(); 19 | block.BlockSize = IntUtils.readInt16(file); 20 | block.IndexCount = IntUtils.readInt16(file); 21 | int FRecordLength = (block.BlockSize - 4) / block.IndexCount; 22 | block.RecordList = new ComplexIndexRecord[block.IndexCount]; 23 | FPosition += 4L; 24 | for(int dwI = 0; dwI < block.IndexCount; dwI++) 25 | { 26 | block.RecordList[dwI] = new ComplexIndexRecord(); 27 | file.seek(FPosition + (long)(dwI * FRecordLength)); 28 | ComplexIndexRecord.Read(block.RecordList[dwI], file); 29 | } 30 | 31 | return Boolean.valueOf(true); 32 | } 33 | 34 | public int BlockSize; 35 | public int IndexCount; 36 | public ComplexIndexRecord RecordList[]; 37 | } 38 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/hexin/IntUtils.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock.hexin; 2 | 3 | import java.io.IOException; 4 | import java.io.RandomAccessFile; 5 | 6 | public class IntUtils 7 | { 8 | 9 | public IntUtils() 10 | { 11 | } 12 | 13 | public static int toInt(byte bRefArr[]) 14 | { 15 | int iOutcome = 0; 16 | for(int i = 0; i < bRefArr.length; i++) 17 | { 18 | byte bLoop = bRefArr[i]; 19 | iOutcome += (bLoop & 0xff) << 8 * i; 20 | } 21 | 22 | return iOutcome; 23 | } 24 | 25 | public static int readInt32(RandomAccessFile file) 26 | throws IOException 27 | { 28 | byte buff[] = new byte[4]; 29 | file.read(buff); 30 | return toInt(buff); 31 | } 32 | 33 | public static int readInt16(RandomAccessFile file) 34 | throws IOException 35 | { 36 | byte buff[] = new byte[2]; 37 | file.read(buff); 38 | return toInt(buff); 39 | } 40 | 41 | public static double readDouble(RandomAccessFile file) 42 | throws IOException 43 | { 44 | byte inData[] = new byte[8]; 45 | file.read(inData); 46 | int j = 0; 47 | int upper = ((inData[j + 7] & 0xff) << 24) + ((inData[j + 6] & 0xff) << 16) + ((inData[j + 5] & 0xff) << 8) + ((inData[j + 4] & 0xff) << 0); 48 | int lower = ((inData[j + 3] & 0xff) << 24) + ((inData[j + 2] & 0xff) << 16) + ((inData[j + 1] & 0xff) << 8) + ((inData[j] & 0xff) << 0); 49 | return Double.longBitsToDouble(((long)upper << 32) + ((long)lower & 0xffffffffL)); 50 | } 51 | } -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/indicator/Boll.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock.indicator; 2 | 3 | 4 | public class Boll 5 | { 6 | 7 | public Boll(Double data[]) 8 | { 9 | boll = 0.0D; 10 | ub = 0.0D; 11 | lb = 0.0D; 12 | Double adouble[]; 13 | int k = (adouble = data).length; 14 | for(int j = 0; j < k; j++) 15 | { 16 | Double d = adouble[j]; 17 | boll += d.doubleValue(); 18 | } 19 | 20 | boll /= data.length; 21 | Double sqrt = Double.valueOf(0.0D); 22 | for(int i = 0; i < data.length; i++) 23 | sqrt = Double.valueOf(sqrt.doubleValue() + Math.pow(Math.abs(data[i].doubleValue() - boll), 2D)); 24 | 25 | sqrt = Double.valueOf(sqrt.doubleValue() / (double)(data.length - 1)); 26 | sqrt = Double.valueOf(Math.pow(sqrt.doubleValue(), 0.5D)); 27 | ub = boll + sqrt.doubleValue() * 2D; 28 | lb = boll - sqrt.doubleValue() * 2D; 29 | } 30 | 31 | public double getBoll() 32 | { 33 | return boll; 34 | } 35 | 36 | public void setBoll(double boll) 37 | { 38 | this.boll = boll; 39 | } 40 | 41 | public double getUb() 42 | { 43 | return ub; 44 | } 45 | 46 | public void setUb(double ub) 47 | { 48 | this.ub = ub; 49 | } 50 | 51 | public double getLb() 52 | { 53 | return lb; 54 | } 55 | 56 | public void setLb(double lb) 57 | { 58 | this.lb = lb; 59 | } 60 | 61 | public String toString() 62 | { 63 | return (new StringBuilder("Boll [boll=")).append(boll).append(", ub=").append(ub).append(", lb=").append(lb).append("]").toString(); 64 | } 65 | 66 | private double boll; 67 | private double ub; 68 | private double lb; 69 | } 70 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/hexin/MN5File.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock.hexin; 2 | 3 | import java.io.IOException; 4 | import java.io.RandomAccessFile; 5 | 6 | public class MN5File 7 | { 8 | 9 | public MN5File() 10 | { 11 | header = new FileHeader(); 12 | } 13 | 14 | public static Boolean Read(MN5File mn5File, RandomAccessFile file) 15 | { 16 | if(file == null) 17 | return Boolean.valueOf(false); 18 | try 19 | { 20 | file.seek(0L); 21 | FileHeader.Read(mn5File.header, file); 22 | int FPosition = FileHeader.LENGTH; 23 | mn5File.columnList = new ColumnHeader[mn5File.header.getFieldCount()]; 24 | for(int dwI = 0; dwI < mn5File.header.getFieldCount(); dwI++) 25 | { 26 | mn5File.columnList[dwI] = new ColumnHeader(); 27 | file.seek(FPosition + ColumnHeader.LENGTH * dwI); 28 | ColumnHeader.Read(mn5File.columnList[dwI], file); 29 | } 30 | 31 | FPosition = mn5File.header.getHeaderLength(); 32 | file.seek(FPosition); 33 | mn5File.recordList = new MN5Record[mn5File.header.getRecordCount()]; 34 | for(int dwI = 0; dwI < mn5File.header.getRecordCount(); dwI++) 35 | { 36 | mn5File.recordList[dwI] = new MN5Record(); 37 | file.seek(FPosition + dwI * mn5File.header.getRecordLength()); 38 | MN5Record.Read(mn5File.recordList[dwI], file); 39 | } 40 | 41 | } 42 | catch(IOException e) 43 | { 44 | e.printStackTrace(); 45 | } 46 | return Boolean.valueOf(true); 47 | } 48 | 49 | public FileHeader header; 50 | public ColumnHeader columnList[]; 51 | public MN5Record recordList[]; 52 | public static int LENGTH = 4; 53 | 54 | } 55 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/hexin/MN30File.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock.hexin; 2 | 3 | import java.io.IOException; 4 | import java.io.RandomAccessFile; 5 | 6 | public class MN30File 7 | { 8 | 9 | public MN30File() 10 | { 11 | header = new FileHeader(); 12 | } 13 | 14 | public static Boolean Read(MN30File mn5File, RandomAccessFile file) 15 | { 16 | if(file == null) 17 | return Boolean.valueOf(false); 18 | try 19 | { 20 | file.seek(0L); 21 | FileHeader.Read(mn5File.header, file); 22 | int FPosition = FileHeader.LENGTH; 23 | mn5File.columnList = new ColumnHeader[mn5File.header.getFieldCount()]; 24 | for(int dwI = 0; dwI < mn5File.header.getFieldCount(); dwI++) 25 | { 26 | mn5File.columnList[dwI] = new ColumnHeader(); 27 | file.seek(FPosition + ColumnHeader.LENGTH * dwI); 28 | ColumnHeader.Read(mn5File.columnList[dwI], file); 29 | } 30 | 31 | FPosition = mn5File.header.getHeaderLength(); 32 | file.seek(FPosition); 33 | mn5File.recordList = new MN30Record[mn5File.header.getRecordCount()]; 34 | for(int dwI = 0; dwI < mn5File.header.getRecordCount(); dwI++) 35 | { 36 | mn5File.recordList[dwI] = new MN30Record(); 37 | file.seek(FPosition + dwI * mn5File.header.getRecordLength()); 38 | MN30Record.Read(mn5File.recordList[dwI], file); 39 | } 40 | 41 | } 42 | catch(IOException e) 43 | { 44 | e.printStackTrace(); 45 | } 46 | return Boolean.valueOf(true); 47 | } 48 | 49 | public FileHeader header; 50 | public ColumnHeader columnList[]; 51 | public MN30Record recordList[]; 52 | public static int LENGTH = 4; 53 | 54 | } 55 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/ConnUtils.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | 4 | import cn.nit.stock.model.StockName; 5 | import com.mongodb.Mongo; 6 | import com.mongodb.MongoClient; 7 | import org.mongodb.morphia.Datastore; 8 | import org.mongodb.morphia.Morphia; 9 | 10 | import java.net.UnknownHostException; 11 | import java.sql.*; 12 | import java.util.ResourceBundle; 13 | 14 | public class ConnUtils 15 | { 16 | 17 | public ConnUtils() 18 | { 19 | } 20 | 21 | public static Connection getConn() 22 | throws ClassNotFoundException, SQLException 23 | { 24 | ResourceBundle bundle = ResourceBundle.getBundle("db"); 25 | String url = bundle.getString("url"); 26 | String driver = bundle.getString("driver"); 27 | Class.forName(driver); 28 | Connection conn = DriverManager.getConnection(url, bundle.getString("user"), bundle.getString("passwd")); 29 | return conn; 30 | } 31 | 32 | public static Connection getConn(String dbName) 33 | throws ClassNotFoundException, SQLException 34 | { 35 | Connection conn = getConn(); 36 | PreparedStatement statement = conn.prepareStatement((new StringBuilder("use ")).append(dbName).toString()); 37 | statement.execute(); 38 | return conn; 39 | } 40 | 41 | public static Datastore getDatastore() throws UnknownHostException { 42 | ResourceBundle bundle = ResourceBundle.getBundle("db"); 43 | String url = bundle.getString("mongodbIP"); 44 | MongoClient mongoClient = new MongoClient(url); 45 | 46 | Morphia morphia = new Morphia(); 47 | morphia.map(StockName.class); 48 | return morphia.createDatastore(mongoClient, "stock"); 49 | } 50 | 51 | public static MongoClient getMongo() throws UnknownHostException { 52 | ResourceBundle bundle = ResourceBundle.getBundle("db"); 53 | String url = bundle.getString("mongodbIP"); 54 | return new MongoClient(url); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/hexin/D1BarFile.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock.hexin; 2 | 3 | import java.io.IOException; 4 | import java.io.RandomAccessFile; 5 | 6 | public class D1BarFile 7 | { 8 | 9 | public FileHeader header; 10 | public ColumnHeader columnList[]; 11 | public D1BarRecord recordList[]; 12 | public static int LENGTH = 4; 13 | 14 | 15 | public D1BarFile() 16 | { 17 | header = new FileHeader(); 18 | } 19 | 20 | public static Boolean Read(D1BarFile d1BarFile, RandomAccessFile file) 21 | { 22 | if(file == null) 23 | return Boolean.valueOf(false); 24 | try 25 | { 26 | file.seek(0L); 27 | FileHeader.Read(d1BarFile.header, file); 28 | int FPosition = FileHeader.LENGTH; 29 | d1BarFile.columnList = new ColumnHeader[d1BarFile.header.getFieldCount()]; 30 | for(int dwI = 0; dwI < d1BarFile.header.getFieldCount(); dwI++) 31 | { 32 | d1BarFile.columnList[dwI] = new ColumnHeader(); 33 | file.seek(FPosition + ColumnHeader.LENGTH * dwI); 34 | ColumnHeader.Read(d1BarFile.columnList[dwI], file); 35 | } 36 | 37 | FPosition = d1BarFile.header.getHeaderLength(); 38 | file.seek(FPosition); 39 | d1BarFile.recordList = new D1BarRecord[d1BarFile.header.getRecordCount()]; 40 | for(int dwI = 0; dwI < d1BarFile.header.getRecordCount(); dwI++) 41 | { 42 | d1BarFile.recordList[dwI] = new D1BarRecord(); 43 | file.seek(FPosition + dwI * d1BarFile.header.getRecordLength()); 44 | D1BarRecord.Read(d1BarFile.recordList[dwI], file); 45 | } 46 | 47 | } 48 | catch(IOException e) 49 | { 50 | e.printStackTrace(); 51 | } 52 | return Boolean.valueOf(true); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/SeriesLimit.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; 4 | import org.apache.commons.httpclient.HttpClient; 5 | import org.apache.commons.httpclient.HttpException; 6 | import org.apache.commons.httpclient.HttpStatus; 7 | import org.apache.commons.httpclient.methods.GetMethod; 8 | import org.apache.commons.httpclient.params.HttpMethodParams; 9 | import org.apache.commons.io.FileUtils; 10 | 11 | import java.io.*; 12 | import java.sql.DriverManager; 13 | import java.sql.ResultSet; 14 | import java.sql.Statement; 15 | import java.text.DateFormat; 16 | import java.text.SimpleDateFormat; 17 | import java.util.ArrayList; 18 | import java.util.Iterator; 19 | import java.util.List; 20 | 21 | /** 22 | * Hello world! 23 | * 24 | */ 25 | public class SeriesLimit { 26 | 27 | public static void main(String[] args) throws Exception { 28 | 29 | DateFormat dataFormat = new SimpleDateFormat("yyyy-MM-dd"); 30 | 31 | List tradeDates = new ArrayList(); 32 | 33 | tradeDates.add("2011-04-01"); 34 | 35 | 36 | Iterator iter = FileUtils.iterateFiles(new File("c:\\stockdata"), new String[]{"csv"}, true); 37 | 38 | while (iter.hasNext()) { 39 | File stockFile = iter.next(); 40 | 41 | List lines = FileUtils.readLines(stockFile); 42 | 43 | 44 | for(int i = lines.size() - 1 ; i > 0; i --) { 45 | String[] results = lines.get(i).split(","); 46 | 47 | String tradedate = results[0]; 48 | 49 | //if (!tradeDates.contains(tradedate)) continue; 50 | 51 | String openprice = results[1]; 52 | String highprice = results[2]; 53 | String lowprice = results[3]; 54 | String closeprice = results[4]; 55 | String volume = results[5]; 56 | 57 | Double closePrice = Double.parseDouble(closeprice); 58 | 59 | 60 | } 61 | 62 | 63 | 64 | } 65 | 66 | 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/HistoryToFile.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; 4 | import org.apache.commons.httpclient.HttpClient; 5 | import org.apache.commons.httpclient.HttpException; 6 | import org.apache.commons.httpclient.HttpStatus; 7 | import org.apache.commons.httpclient.methods.GetMethod; 8 | import org.apache.commons.httpclient.params.HttpMethodParams; 9 | import org.apache.commons.io.FileUtils; 10 | 11 | import java.io.*; 12 | import java.net.URL; 13 | import java.sql.Connection; 14 | import java.sql.DriverManager; 15 | import java.sql.ResultSet; 16 | import java.sql.Statement; 17 | import java.text.DateFormat; 18 | import java.text.SimpleDateFormat; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | /** 23 | * Hello world! 24 | * 25 | */ 26 | public class HistoryToFile { 27 | 28 | public static void main(String[] args) throws Exception { 29 | 30 | Connection conn = ConnUtils.getConn("stock"); 31 | 32 | // Create an instance of HttpClient. 33 | HttpClient client = new HttpClient(); 34 | // client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, 35 | // "GBK"); 36 | 37 | Statement st = conn.createStatement(); 38 | Statement updateStatement = conn.createStatement(); 39 | 40 | String sql = "select * from stock"; 41 | 42 | ResultSet resultSet = st.executeQuery(sql); 43 | while (resultSet.next()) { 44 | String pkid = resultSet.getString("pkid"); 45 | String stockcode = resultSet.getString("code"); 46 | String stocktype = "sz"; 47 | if (stockcode.startsWith("6")) { 48 | stocktype = "ss"; 49 | } 50 | 51 | 52 | System.err.println("stockcode=" + stockcode); 53 | 54 | URL url = new URL("http://table.finance.yahoo.com/table.csv?s=" + stockcode + "." + stocktype); 55 | 56 | File stockFile = new File("c:\\stockdata\\" + stockcode + ".csv"); 57 | 58 | if (stockFile.exists()) continue; 59 | 60 | try { 61 | FileUtils.copyURLToFile(url, new File("c:\\stockdata\\" + stockcode + ".csv")); 62 | } catch (Exception e) { 63 | System.err.println(e.toString()); 64 | } 65 | Thread.sleep(1000); 66 | } 67 | st.close(); 68 | conn.close(); 69 | 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/Simulate5.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import java.sql.DriverManager; 4 | import java.sql.ResultSet; 5 | import java.sql.Statement; 6 | import java.text.DateFormat; 7 | import java.text.SimpleDateFormat; 8 | 9 | import org.apache.commons.httpclient.HttpClient; 10 | 11 | /** 12 | * Hello world! 13 | * 14 | */ 15 | public class Simulate5 { 16 | public static void main(String[] args) throws Exception { 17 | DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); 18 | 19 | // Create an instance of HttpClient. 20 | HttpClient client = new HttpClient(); 21 | // client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, 22 | // "GBK"); 23 | 24 | String url = "jdbc:jtds:sqlserver://218.28.139.40:4433/stock"; 25 | String driver = "net.sourceforge.jtds.jdbc.Driver"; 26 | java.sql.Connection conn; 27 | 28 | Class.forName(driver); 29 | conn = DriverManager.getConnection(url, "sa", "chrdw,hdhxt."); 30 | Statement stStock = conn.createStatement(); 31 | Statement stBoard = conn.createStatement(); 32 | Statement stDay = conn.createStatement(); 33 | Statement updateStatement = conn.createStatement(); 34 | 35 | String tradeSql = "select tradedate from day where stockcode='1a0001' and tradedate>'2010-01-01' order by tradedate desc"; 36 | 37 | ResultSet rsDay = stDay.executeQuery(tradeSql); 38 | while (rsDay.next()) { 39 | 40 | String tradeDate = df.format(rsDay.getDate("tradedate")); 41 | System.err.println("交易日:" + tradeDate); 42 | 43 | String ssql = "select * from day where tradedate='" + tradeDate + "'"; 44 | 45 | ResultSet rsStock = stBoard.executeQuery(ssql); 46 | while (rsStock.next()) { 47 | String stockCode = rsStock.getString("stockcode"); 48 | Double yesterdayPrice = rsStock.getDouble("yesterdayprice"); 49 | Double openPriceD = rsStock.getDouble("openprice"); 50 | String openPrice = rsStock.getString("openprice"); 51 | String lowPrice = rsStock.getString("lowPrice"); 52 | Double closePrice = rsStock.getDouble("closeprice"); 53 | Double highPrice = rsStock.getDouble("highprice"); 54 | 55 | if ( 56 | openPriceD > yesterdayPrice //跳空高开 57 | && openPrice.equals(lowPrice) //光脚 58 | && (closePrice-yesterdayPrice)/yesterdayPrice > 0.095 //大阳 59 | ) { 60 | 61 | System.err.println(stockCode); 62 | } 63 | } 64 | 65 | } 66 | 67 | conn.close(); 68 | 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/HistoryLimit.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import cn.nit.stock.model.StockLimit; 4 | import cn.nit.stock.model.StockName; 5 | import cn.nit.stock.model.TradeDay; 6 | import com.mongodb.MongoClient; 7 | import org.mongodb.morphia.Datastore; 8 | import org.springframework.data.mongodb.core.MongoOperations; 9 | import org.springframework.data.mongodb.core.MongoTemplate; 10 | 11 | import java.sql.Connection; 12 | import java.sql.PreparedStatement; 13 | import java.sql.ResultSet; 14 | import java.sql.Statement; 15 | import java.util.Date; 16 | import java.util.List; 17 | 18 | 19 | /** 20 | * Hello world! 21 | * 22 | */ 23 | public class HistoryLimit 24 | { 25 | private static Datastore ds; 26 | 27 | private static MongoClient mongoClient; 28 | 29 | private static MongoOperations mongoOps; 30 | 31 | public static void main( String[] args ) throws Exception 32 | { 33 | ds = ConnUtils.getDatastore(); 34 | mongoClient = ConnUtils.getMongo(); 35 | mongoOps = new MongoTemplate(mongoClient, "stock"); 36 | 37 | for (StockName stockName : ds.find(StockName.class).asList()) { 38 | 39 | 40 | String stockcode = stockName.getCode(); 41 | System.err.println(stockName); 42 | 43 | 44 | 45 | List list = mongoOps.findAll(TradeDay.class, stockcode); 46 | 47 | for(TradeDay tradeDay : list) { 48 | 49 | 50 | if (tradeDay.getYesterdayPrice() * 1.1 - tradeDay.getClosePrice() < 0.01) { 51 | 52 | System.err.println("代码:" + stockcode + ",名称:" + stockName.getName() + ",涨停日期:" + tradeDay.getTradeDate()); 53 | 54 | StockLimit stockLimit = new StockLimit(); 55 | 56 | stockLimit.setStockName(stockName.getName()); 57 | stockLimit.setStockCode(stockcode); 58 | stockLimit.setYesterdayPrice(tradeDay.getYesterdayPrice()); 59 | stockLimit.setClosePrice(tradeDay.getClosePrice()); 60 | stockLimit.setOpenPrice(tradeDay.getOpenPrice()); 61 | stockLimit.setLowPrice(tradeDay.getLowPrice()); 62 | stockLimit.setHighPrice(tradeDay.getHighPrice()); 63 | stockLimit.setLimitDate(tradeDay.getTradeDate()); 64 | 65 | mongoOps.save(stockLimit); 66 | } 67 | 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/HistorySuccessiveLimit.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import cn.nit.stock.model.StockName; 4 | import cn.nit.stock.model.TradeDay; 5 | import com.mongodb.MongoClient; 6 | import org.apache.commons.io.FileUtils; 7 | import org.mongodb.morphia.Datastore; 8 | import org.springframework.data.domain.Sort; 9 | import org.springframework.data.mongodb.core.MongoOperations; 10 | import org.springframework.data.mongodb.core.MongoTemplate; 11 | import org.springframework.data.mongodb.core.query.Criteria; 12 | import org.springframework.data.mongodb.core.query.Query; 13 | 14 | import java.io.File; 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | /** 19 | * Created by gengke on 2014/10/23. 20 | */ 21 | public class HistorySuccessiveLimit { 22 | 23 | private static Datastore ds; 24 | 25 | private static MongoClient mongoClient; 26 | 27 | private static MongoOperations mongoOps; 28 | 29 | public static void main( String[] args ) throws Exception { 30 | ds = ConnUtils.getDatastore(); 31 | mongoClient = ConnUtils.getMongo(); 32 | mongoOps = new MongoTemplate(mongoClient, "stock"); 33 | 34 | List limit = new ArrayList(); 35 | 36 | for (StockName stockName : ds.find(StockName.class).asList()) { 37 | System.err.println(stockName); 38 | 39 | String stockcode = stockName.getCode(); 40 | 41 | List list = mongoOps.find(new Query(Criteria.where("closePrice").gt(0)).with(new Sort(Sort.Direction.ASC, "tradeDate")),TradeDay.class, stockName.getCode()); 42 | 43 | for(int i = 0 ; i < list.size(); i++) { 44 | if ( i + 2 >= list.size()) continue; 45 | 46 | TradeDay day1 = list.get(i); 47 | TradeDay day2 = list.get(i+1); 48 | TradeDay day3 = list.get(i+2); 49 | 50 | if (day1.isOpenLimit() && day2.isOpenLimit() && day3.isOpenLimit()) { 51 | String str = "0" + stockcode; 52 | 53 | if (stockcode.startsWith("6")) 54 | str = "1" + stockcode; 55 | 56 | if (!limit.contains(str)) limit.add(str); 57 | } 58 | 59 | } 60 | } 61 | 62 | StringBuilder sb = new StringBuilder(); 63 | for (String code : limit) { 64 | sb.append(code + "\r\n"); 65 | } 66 | FileUtils.writeStringToFile(new File("C:\\new_gxzq_v6\\T0002\\blocknew\\NG.blk"), sb.toString()); 67 | System.err.println(limit.toString()); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /robot/robot.dof: -------------------------------------------------------------------------------- 1 | [FileVersion] 2 | Version=7.0 3 | [Compiler] 4 | A=8 5 | B=0 6 | C=1 7 | D=1 8 | E=0 9 | F=0 10 | G=1 11 | H=1 12 | I=1 13 | J=0 14 | K=0 15 | L=1 16 | M=0 17 | N=1 18 | O=1 19 | P=1 20 | Q=0 21 | R=0 22 | S=0 23 | T=0 24 | U=0 25 | V=1 26 | W=0 27 | X=1 28 | Y=1 29 | Z=1 30 | ShowHints=1 31 | ShowWarnings=1 32 | UnitAliases=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE; 33 | NamespacePrefix= 34 | SymbolDeprecated=1 35 | SymbolLibrary=1 36 | SymbolPlatform=1 37 | UnitLibrary=1 38 | UnitPlatform=1 39 | UnitDeprecated=1 40 | HResultCompat=1 41 | HidingMember=1 42 | HiddenVirtual=1 43 | Garbage=1 44 | BoundsError=1 45 | ZeroNilCompat=1 46 | StringConstTruncated=1 47 | ForLoopVarVarPar=1 48 | TypedConstVarPar=1 49 | AsgToTypedConst=1 50 | CaseLabelRange=1 51 | ForVariable=1 52 | ConstructingAbstract=1 53 | ComparisonFalse=1 54 | ComparisonTrue=1 55 | ComparingSignedUnsigned=1 56 | CombiningSignedUnsigned=1 57 | UnsupportedConstruct=1 58 | FileOpen=1 59 | FileOpenUnitSrc=1 60 | BadGlobalSymbol=1 61 | DuplicateConstructorDestructor=1 62 | InvalidDirective=1 63 | PackageNoLink=1 64 | PackageThreadVar=1 65 | ImplicitImport=1 66 | HPPEMITIgnored=1 67 | NoRetVal=1 68 | UseBeforeDef=1 69 | ForLoopVarUndef=1 70 | UnitNameMismatch=1 71 | NoCFGFileFound=1 72 | MessageDirective=1 73 | ImplicitVariants=1 74 | UnicodeToLocale=1 75 | LocaleToUnicode=1 76 | ImagebaseMultiple=1 77 | SuspiciousTypecast=1 78 | PrivatePropAccessor=1 79 | UnsafeType=0 80 | UnsafeCode=0 81 | UnsafeCast=0 82 | [Linker] 83 | MapFile=0 84 | OutputObjs=0 85 | ConsoleApp=1 86 | DebugInfo=0 87 | RemoteSymbols=0 88 | MinStackSize=16384 89 | MaxStackSize=1048576 90 | ImageBase=4194304 91 | ExeDescription= 92 | [Directories] 93 | OutputDir= 94 | UnitOutputDir= 95 | PackageDLLOutputDir= 96 | PackageDCPOutputDir= 97 | SearchPath= 98 | Packages= 99 | Conditionals= 100 | DebugSourceDirs= 101 | UsePackages=0 102 | [Parameters] 103 | RunParams= 104 | HostApplication= 105 | Launcher= 106 | UseLauncher=0 107 | DebugCWD= 108 | [Language] 109 | ActiveLang= 110 | ProjectLang= 111 | RootDir= 112 | [Version Info] 113 | IncludeVerInfo=0 114 | AutoIncBuild=0 115 | MajorVer=1 116 | MinorVer=0 117 | Release=0 118 | Build=0 119 | Debug=0 120 | PreRelease=0 121 | Special=0 122 | Private=0 123 | DLL=0 124 | Locale=2052 125 | CodePage=936 126 | [Version Info Keys] 127 | CompanyName= 128 | FileDescription= 129 | FileVersion=1.0.0.0 130 | InternalName= 131 | LegalCopyright= 132 | LegalTrademarks= 133 | OriginalFilename= 134 | ProductName= 135 | ProductVersion=1.0.0.0 136 | Comments= 137 | -------------------------------------------------------------------------------- /seven/seven.dof: -------------------------------------------------------------------------------- 1 | [FileVersion] 2 | Version=7.0 3 | [Compiler] 4 | A=8 5 | B=0 6 | C=1 7 | D=1 8 | E=0 9 | F=0 10 | G=1 11 | H=1 12 | I=1 13 | J=0 14 | K=0 15 | L=1 16 | M=0 17 | N=1 18 | O=1 19 | P=1 20 | Q=0 21 | R=0 22 | S=0 23 | T=0 24 | U=0 25 | V=1 26 | W=0 27 | X=1 28 | Y=1 29 | Z=1 30 | ShowHints=1 31 | ShowWarnings=1 32 | UnitAliases=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE; 33 | NamespacePrefix= 34 | SymbolDeprecated=1 35 | SymbolLibrary=1 36 | SymbolPlatform=1 37 | UnitLibrary=1 38 | UnitPlatform=1 39 | UnitDeprecated=1 40 | HResultCompat=1 41 | HidingMember=1 42 | HiddenVirtual=1 43 | Garbage=1 44 | BoundsError=1 45 | ZeroNilCompat=1 46 | StringConstTruncated=1 47 | ForLoopVarVarPar=1 48 | TypedConstVarPar=1 49 | AsgToTypedConst=1 50 | CaseLabelRange=1 51 | ForVariable=1 52 | ConstructingAbstract=1 53 | ComparisonFalse=1 54 | ComparisonTrue=1 55 | ComparingSignedUnsigned=1 56 | CombiningSignedUnsigned=1 57 | UnsupportedConstruct=1 58 | FileOpen=1 59 | FileOpenUnitSrc=1 60 | BadGlobalSymbol=1 61 | DuplicateConstructorDestructor=1 62 | InvalidDirective=1 63 | PackageNoLink=1 64 | PackageThreadVar=1 65 | ImplicitImport=1 66 | HPPEMITIgnored=1 67 | NoRetVal=1 68 | UseBeforeDef=1 69 | ForLoopVarUndef=1 70 | UnitNameMismatch=1 71 | NoCFGFileFound=1 72 | MessageDirective=1 73 | ImplicitVariants=1 74 | UnicodeToLocale=1 75 | LocaleToUnicode=1 76 | ImagebaseMultiple=1 77 | SuspiciousTypecast=1 78 | PrivatePropAccessor=1 79 | UnsafeType=0 80 | UnsafeCode=0 81 | UnsafeCast=0 82 | [Linker] 83 | MapFile=0 84 | OutputObjs=0 85 | ConsoleApp=1 86 | DebugInfo=0 87 | RemoteSymbols=0 88 | MinStackSize=16384 89 | MaxStackSize=1048576 90 | ImageBase=4194304 91 | ExeDescription= 92 | [Directories] 93 | OutputDir= 94 | UnitOutputDir= 95 | PackageDLLOutputDir= 96 | PackageDCPOutputDir= 97 | SearchPath= 98 | Packages= 99 | Conditionals= 100 | DebugSourceDirs= 101 | UsePackages=0 102 | [Parameters] 103 | RunParams= 104 | HostApplication= 105 | Launcher= 106 | UseLauncher=0 107 | DebugCWD= 108 | [Language] 109 | ActiveLang= 110 | ProjectLang= 111 | RootDir= 112 | [Version Info] 113 | IncludeVerInfo=0 114 | AutoIncBuild=0 115 | MajorVer=1 116 | MinorVer=0 117 | Release=0 118 | Build=0 119 | Debug=0 120 | PreRelease=0 121 | Special=0 122 | Private=0 123 | DLL=0 124 | Locale=2052 125 | CodePage=936 126 | [Version Info Keys] 127 | CompanyName= 128 | FileDescription= 129 | FileVersion=1.0.0.0 130 | InternalName= 131 | LegalCopyright= 132 | LegalTrademarks= 133 | OriginalFilename= 134 | ProductName= 135 | ProductVersion=1.0.0.0 136 | Comments= 137 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/UniqueDay.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.InputStreamReader; 7 | import java.sql.Connection; 8 | import java.sql.DriverManager; 9 | import java.sql.ResultSet; 10 | import java.sql.Statement; 11 | import java.util.ArrayList; 12 | import java.util.HashMap; 13 | import java.util.List; 14 | import java.util.Map; 15 | import java.util.Date; 16 | import java.util.Calendar; 17 | import java.util.Map.Entry; 18 | import java.text.SimpleDateFormat; 19 | 20 | import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; 21 | import org.apache.commons.httpclient.HttpClient; 22 | import org.apache.commons.httpclient.HttpException; 23 | import org.apache.commons.httpclient.HttpStatus; 24 | import org.apache.commons.httpclient.methods.GetMethod; 25 | import org.apache.commons.httpclient.params.HttpMethodParams; 26 | 27 | /** 28 | * Hello world! 29 | * 30 | */ 31 | public class UniqueDay { 32 | public static void main(String[] args) throws Exception { 33 | List tradeDates = new ArrayList(); 34 | tradeDates.add("2011-04-29"); 35 | 36 | String url = "jdbc:jtds:sqlserver://218.28.139.40:4433/stock"; 37 | String driver = "net.sourceforge.jtds.jdbc.Driver"; 38 | java.sql.Connection conn; 39 | 40 | Class.forName(driver); 41 | conn = DriverManager.getConnection(url, "sa", "chrdw,hdhxt."); 42 | Connection conn1 = DriverManager.getConnection(url, "sa", 43 | "chrdw,hdhxt."); 44 | Connection conn2 = DriverManager.getConnection(url, "sa", 45 | "chrdw,hdhxt."); 46 | Statement st = conn.createStatement(); 47 | Statement updateStatement = conn2.createStatement(); 48 | Statement selectStatement = conn1.createStatement(); 49 | 50 | Map map = new HashMap(); 51 | 52 | for (String tradeDate : tradeDates) { 53 | 54 | String sql = "select * from day where tradedate='" + tradeDate + "'"; 55 | 56 | ResultSet resultSet = st.executeQuery(sql); 57 | 58 | while (resultSet.next()) { 59 | String pkid = resultSet.getString("pkid"); 60 | String stockcode = resultSet.getString("stockcode"); 61 | 62 | if (!map.containsKey(stockcode)) { 63 | map.put(stockcode, pkid); 64 | } 65 | 66 | } 67 | 68 | for (Entry entry : map.entrySet()) { 69 | sql = "delete day where pkid=" + entry.getValue(); 70 | System.err.println(sql); 71 | int nresult = updateStatement.executeUpdate(sql); 72 | } 73 | } 74 | 75 | st.close(); 76 | selectStatement.close(); 77 | conn.close(); 78 | conn1.close(); 79 | conn2.close(); 80 | 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/SuccessiveLimit.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import cn.nit.stock.model.StockLimit; 4 | import cn.nit.stock.model.StockName; 5 | import cn.nit.stock.model.TradeDay; 6 | import com.mongodb.MongoClient; 7 | import org.apache.commons.io.FileUtils; 8 | import org.mongodb.morphia.Datastore; 9 | import org.springframework.data.domain.Sort; 10 | import org.springframework.data.mongodb.core.MongoOperations; 11 | import org.springframework.data.mongodb.core.MongoTemplate; 12 | import org.springframework.data.mongodb.core.query.Criteria; 13 | import org.springframework.data.mongodb.core.query.Query; 14 | import org.springframework.util.CollectionUtils; 15 | 16 | import java.io.File; 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | 20 | /** 21 | * Created by gengke on 2014/10/23. 22 | */ 23 | public class SuccessiveLimit { 24 | 25 | private static Datastore ds; 26 | 27 | private static MongoClient mongoClient; 28 | 29 | private static MongoOperations mongoOps; 30 | 31 | public static void main( String[] args ) throws Exception { 32 | ds = ConnUtils.getDatastore(); 33 | mongoClient = ConnUtils.getMongo(); 34 | mongoOps = new MongoTemplate(mongoClient, "stock"); 35 | 36 | List limit = new ArrayList(); 37 | 38 | for (StockName stockName : ds.find(StockName.class).asList()) { 39 | System.err.println(stockName); 40 | 41 | String stockcode = stockName.getCode(); 42 | 43 | List list = mongoOps.find(new Query(Criteria.where("closePrice").gt(0)).with(new Sort(Sort.Direction.DESC, "tradeDate")).limit(3),TradeDay.class, stockName.getCode()); 44 | 45 | if (list.size() < 3) continue; 46 | 47 | TradeDay day1 = list.get(0); 48 | TradeDay day2 = list.get(1); 49 | TradeDay day3 = list.get(2); 50 | 51 | if (!day1.isTodayLimit()) continue; 52 | 53 | if (day1.isOpenLimit() && day2.isOpenLimit() && day3.isOpenLimit()) { 54 | String str = "0" + stockcode; 55 | 56 | if (stockcode.startsWith("6")) 57 | str = "1" + stockcode; 58 | 59 | if (!limit.contains(str)) limit.add(str); 60 | } 61 | 62 | 63 | } 64 | 65 | if (limit.size() == 0) return; 66 | 67 | 68 | File zxgFile = new File("C:\\new_gxzq_v6\\T0002\\blocknew\\ZXG.blk"); 69 | StringBuilder sb = new StringBuilder(); 70 | 71 | sb.append(FileUtils.readFileToString(zxgFile)); 72 | 73 | for (String code : limit) { 74 | sb.append(code + "\r\n"); 75 | } 76 | FileUtils.writeStringToFile(zxgFile, sb.toString()); 77 | System.err.println(limit.toString()); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/hexin/FileHeader.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock.hexin; 2 | 3 | import java.io.IOException; 4 | import java.io.RandomAccessFile; 5 | 6 | 7 | public class FileHeader 8 | { 9 | 10 | private int sign; 11 | private int w1; 12 | private int recordCount; 13 | private int headerLength; 14 | private int recordLength; 15 | private int fieldCount; 16 | public static int LENGTH = 16; 17 | 18 | 19 | public FileHeader() 20 | { 21 | } 22 | 23 | public static Boolean Read(FileHeader header, RandomAccessFile file) 24 | { 25 | if(file == null) 26 | return Boolean.valueOf(false); 27 | try 28 | { 29 | header.sign = IntUtils.readInt32(file); 30 | header.w1 = IntUtils.readInt16(file); 31 | header.recordCount = IntUtils.readInt32(file) & 0xffffff; 32 | header.headerLength = IntUtils.readInt16(file); 33 | header.recordLength = IntUtils.readInt16(file); 34 | header.fieldCount = IntUtils.readInt16(file); 35 | } 36 | catch(IOException e) 37 | { 38 | e.printStackTrace(); 39 | } 40 | return Boolean.valueOf(true); 41 | } 42 | 43 | 44 | 45 | @Override 46 | public String toString() { 47 | return "FileHeader [sign=" + sign + ", w1=" + w1 + ", recordCount=" 48 | + recordCount + ", headerLength=" + headerLength 49 | + ", recordLength=" + recordLength + ", fieldCount=" 50 | + fieldCount + "]"; 51 | } 52 | 53 | public int getSign() 54 | { 55 | return sign; 56 | } 57 | 58 | public void setSign(int sign) 59 | { 60 | this.sign = sign; 61 | } 62 | 63 | public int getW1() 64 | { 65 | return w1; 66 | } 67 | 68 | public void setW1(int w1) 69 | { 70 | this.w1 = w1; 71 | } 72 | 73 | public int getRecordCount() 74 | { 75 | return recordCount; 76 | } 77 | 78 | public void setRecordCount(int recordCount) 79 | { 80 | this.recordCount = recordCount; 81 | } 82 | 83 | public int getHeaderLength() 84 | { 85 | return headerLength; 86 | } 87 | 88 | public void setHeaderLength(int headerLength) 89 | { 90 | this.headerLength = headerLength; 91 | } 92 | 93 | public int getRecordLength() 94 | { 95 | return recordLength; 96 | } 97 | 98 | public void setRecordLength(int recordLength) 99 | { 100 | this.recordLength = recordLength; 101 | } 102 | 103 | public int getFieldCount() 104 | { 105 | return fieldCount; 106 | } 107 | 108 | public void setFieldCount(int fieldCount) 109 | { 110 | this.fieldCount = fieldCount; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | [Dd]ebug/ 46 | [Rr]elease/ 47 | *_i.c 48 | *_p.c 49 | *.ilk 50 | *.meta 51 | *.obj 52 | *.pch 53 | *.pdb 54 | *.pgc 55 | *.pgd 56 | *.rsp 57 | *.sbr 58 | *.tlb 59 | *.tli 60 | *.tlh 61 | *.tmp 62 | *.vspscc 63 | .builds 64 | *.dotCover 65 | 66 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 67 | #packages/ 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | 76 | # Visual Studio profiler 77 | *.psess 78 | *.vsp 79 | 80 | # ReSharper is a .NET coding add-in 81 | _ReSharper* 82 | 83 | # Installshield output folder 84 | [Ee]xpress 85 | 86 | # DocProject is a documentation generator add-in 87 | DocProject/buildhelp/ 88 | DocProject/Help/*.HxT 89 | DocProject/Help/*.HxC 90 | DocProject/Help/*.hhc 91 | DocProject/Help/*.hhk 92 | DocProject/Help/*.hhp 93 | DocProject/Help/Html2 94 | DocProject/Help/html 95 | 96 | # Click-Once directory 97 | publish 98 | 99 | # Others 100 | [Bb]in 101 | [Oo]bj 102 | sql 103 | TestResults 104 | *.Cache 105 | ClientBin 106 | stylecop.* 107 | ~$* 108 | *.dbmdl 109 | Generated_Code #added for RIA/Silverlight projects 110 | 111 | # Backup & report files from converting an old project file to a newer 112 | # Visual Studio version. Backup files are not needed, because we have git ;-) 113 | _UpgradeReport_Files/ 114 | Backup*/ 115 | UpgradeLog*.XML 116 | 117 | 118 | 119 | ############ 120 | ## Windows 121 | ############ 122 | 123 | # Windows image file caches 124 | Thumbs.db 125 | 126 | # Folder config file 127 | Desktop.ini 128 | 129 | 130 | ############# 131 | ## Python 132 | ############# 133 | 134 | *.py[co] 135 | 136 | # Packages 137 | *.egg 138 | *.egg-info 139 | dist 140 | build 141 | eggs 142 | parts 143 | bin 144 | var 145 | sdist 146 | develop-eggs 147 | .installed.cfg 148 | 149 | # Installer logs 150 | pip-log.txt 151 | 152 | # Unit test / coverage reports 153 | .coverage 154 | .tox 155 | 156 | #Translations 157 | *.mo 158 | 159 | #Mr Developer 160 | .mr.developer.cfg 161 | 162 | # Mac crap 163 | .DS_Store 164 | *.exe 165 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/AddD1Future.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import cn.nit.stock.hexin.D1BarFile; 4 | import cn.nit.stock.hexin.D1BarRecord; 5 | import com.mongodb.DB; 6 | import com.mongodb.DBCollection; 7 | import com.mongodb.Mongo; 8 | import com.mongodb.MongoClient; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.data.mongodb.core.MongoOperations; 11 | import org.springframework.data.mongodb.core.MongoTemplate; 12 | import org.springframework.data.mongodb.core.query.Criteria; 13 | import org.springframework.data.mongodb.core.query.Query; 14 | 15 | import java.io.File; 16 | import java.io.FileNotFoundException; 17 | import java.io.RandomAccessFile; 18 | import java.net.UnknownHostException; 19 | import java.sql.*; 20 | 21 | // Referenced classes of package cn.nit.stock: 22 | // ConnUtils, AddStock 23 | 24 | public class AddD1Future 25 | { 26 | 27 | 28 | public AddD1Future() 29 | { 30 | } 31 | 32 | public static void main(String args[]) 33 | throws Exception 34 | { 35 | String[] ins = new String[]{ 36 | "IF1407"}; 37 | 38 | for(String code:ins) { 39 | getData(code); 40 | } 41 | } 42 | 43 | private static void getData(String stockcode) 44 | throws ClassNotFoundException, SQLException, FileNotFoundException, UnknownHostException { 45 | 46 | System.err.println(stockcode); 47 | 48 | 49 | MongoClient mongoClient = new MongoClient( "115.28.160.121" ); 50 | DB db = mongoClient.getDB("future"); 51 | DBCollection coll = db.getCollection(stockcode); 52 | 53 | MongoOperations mongoOps = new MongoTemplate(mongoClient, "future"); 54 | 55 | 56 | 57 | //log.info(mongoOps.findOne(new Query(where("name").is("Joe")), Person.class)); 58 | RandomAccessFile file = new RandomAccessFile(new File((new StringBuilder("C:\\同花顺软件\\同花顺\\history\\cffex\\day\\").append(stockcode).append(".day")).toString()), "r"); 59 | D1BarFile d1barFile = new D1BarFile(); 60 | D1BarFile.Read(d1barFile, file); 61 | D1BarRecord ad1barrecord[]; 62 | int j = (ad1barrecord = d1barFile.recordList).length; 63 | for(int i = 0; i < j; i++) 64 | { 65 | D1BarRecord record = ad1barrecord[i]; 66 | if(record.getDate() != null && record.getOpen() > 10) 67 | { 68 | System.err.println(record); 69 | 70 | Query searchUserQuery = new Query(Criteria.where("date").is(record.getDate())); 71 | if (!mongoOps.exists(searchUserQuery, D1BarRecord.class)) { 72 | mongoOps.insert(record, stockcode); 73 | } 74 | } 75 | } 76 | 77 | } 78 | } 79 | 80 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/hexin/ComplexIndexRecord.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock.hexin; 2 | 3 | import java.io.IOException; 4 | import java.io.RandomAccessFile; 5 | 6 | public class ComplexIndexRecord 7 | { 8 | 9 | public ComplexIndexRecord() 10 | { 11 | } 12 | 13 | public String getSymbol() 14 | { 15 | return symbol; 16 | } 17 | 18 | public void setSymbol(String symbol) 19 | { 20 | this.symbol = symbol; 21 | } 22 | 23 | public int getFreeNumber() 24 | { 25 | return freeNumber; 26 | } 27 | 28 | public void setFreeNumber(int freeNumber) 29 | { 30 | this.freeNumber = freeNumber; 31 | } 32 | 33 | public int getPosition() 34 | { 35 | return position; 36 | } 37 | 38 | public void setPosition(int position) 39 | { 40 | this.position = position; 41 | } 42 | 43 | public int getRecordNumber() 44 | { 45 | return recordNumber; 46 | } 47 | 48 | public void setRecordNumber(int recordNumber) 49 | { 50 | this.recordNumber = recordNumber; 51 | } 52 | 53 | public int getMarket() 54 | { 55 | return market; 56 | } 57 | 58 | public void setMarket(int market) 59 | { 60 | this.market = market; 61 | } 62 | 63 | public static Boolean Read(ComplexIndexRecord record, RandomAccessFile file) throws IOException 64 | { 65 | if(file == null) 66 | return Boolean.valueOf(false); 67 | byte FValue; 68 | FValue = file.readByte(); 69 | if(FValue == 0) 70 | return Boolean.valueOf(false); 71 | try 72 | { 73 | record.market = FValue; 74 | byte FBuffer[] = new byte[9]; 75 | file.read(FBuffer); 76 | int FIndex; 77 | for(FIndex = 0; FIndex < FBuffer.length; FIndex++) 78 | if(FBuffer[FIndex] == 0) 79 | break; 80 | 81 | record.symbol = new String(FBuffer, 0, FIndex, "GB2312"); 82 | record.freeNumber = IntUtils.readInt16(file); 83 | record.position = IntUtils.readInt32(file); 84 | record.recordNumber = IntUtils.readInt16(file); 85 | return Boolean.valueOf(true); 86 | } 87 | catch(IOException e) 88 | { 89 | e.printStackTrace(); 90 | } 91 | return Boolean.valueOf(true); 92 | } 93 | 94 | @Override 95 | public String toString() { 96 | return "ComplexIndexRecord [market=" + market + ", symbol=" + symbol 97 | + ", freeNumber=" + freeNumber + ", position=" + position 98 | + ", recordNumber=" + recordNumber + "]"; 99 | } 100 | 101 | 102 | 103 | 104 | private int market; 105 | private String symbol; 106 | private int freeNumber; 107 | private int position; 108 | private int recordNumber; 109 | } -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/model/StockLimit.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock.model; 2 | 3 | import org.bson.types.ObjectId; 4 | import org.mongodb.morphia.annotations.Id; 5 | import org.springframework.data.mongodb.core.mapping.Document; 6 | 7 | @Document 8 | public class StockLimit { 9 | 10 | @Id 11 | private ObjectId id; 12 | 13 | Double yesterdayPrice, openPrice, closePrice, highPrice, lowPrice; 14 | String stockCode, stockName; 15 | String limitDate; 16 | 17 | public Boolean isOpenLimit() { 18 | return highPrice - openPrice < 0.01; 19 | } 20 | 21 | 22 | public Double getYesterdayPrice() { 23 | return yesterdayPrice; 24 | } 25 | 26 | public void setYesterdayPrice(Double yesterdayPrice) { 27 | this.yesterdayPrice = yesterdayPrice; 28 | } 29 | 30 | public Double getOpenPrice() { 31 | return openPrice; 32 | } 33 | 34 | public void setOpenPrice(Double openPrice) { 35 | this.openPrice = openPrice; 36 | } 37 | 38 | public Double getClosePrice() { 39 | return closePrice; 40 | } 41 | 42 | public void setClosePrice(Double closePrice) { 43 | this.closePrice = closePrice; 44 | } 45 | 46 | public Double getHighPrice() { 47 | return highPrice; 48 | } 49 | 50 | public void setHighPrice(Double highPrice) { 51 | this.highPrice = highPrice; 52 | } 53 | 54 | public Double getLowPrice() { 55 | return lowPrice; 56 | } 57 | 58 | public void setLowPrice(Double lowPrice) { 59 | this.lowPrice = lowPrice; 60 | } 61 | 62 | public String getStockCode() { 63 | return stockCode; 64 | } 65 | 66 | public void setStockCode(String stockCode) { 67 | this.stockCode = stockCode; 68 | } 69 | 70 | public String getStockName() { 71 | return stockName; 72 | } 73 | 74 | public void setStockName(String stockName) { 75 | this.stockName = stockName; 76 | } 77 | 78 | public String getLimitDate() { 79 | return limitDate; 80 | } 81 | 82 | public void setLimitDate(String limitDate) { 83 | this.limitDate = limitDate; 84 | } 85 | 86 | @Override 87 | public String toString() { 88 | final StringBuilder sb = new StringBuilder("StockLimit{"); 89 | sb.append("id=").append(id); 90 | sb.append(", yesterdayPrice=").append(yesterdayPrice); 91 | sb.append(", openPrice=").append(openPrice); 92 | sb.append(", closePrice=").append(closePrice); 93 | sb.append(", highPrice=").append(highPrice); 94 | sb.append(", lowPrice=").append(lowPrice); 95 | sb.append(", stockCode='").append(stockCode).append('\''); 96 | sb.append(", stockName='").append(stockName).append('\''); 97 | sb.append(", limitDate='").append(limitDate).append('\''); 98 | sb.append('}'); 99 | return sb.toString(); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/HistoryNotLimit.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import java.sql.DriverManager; 4 | import java.sql.ResultSet; 5 | import java.sql.Statement; 6 | import java.util.Date; 7 | 8 | import org.apache.commons.httpclient.HttpClient; 9 | 10 | 11 | /** 12 | * Hello world! 13 | * 14 | */ 15 | public class HistoryNotLimit 16 | { 17 | public static void main( String[] args ) throws Exception 18 | { 19 | // Create an instance of HttpClient. 20 | HttpClient client = new HttpClient(); 21 | //client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "GBK"); 22 | 23 | 24 | String url = "jdbc:jtds:sqlserver://218.28.139.40:4433/stock"; 25 | String driver= "net.sourceforge.jtds.jdbc.Driver"; 26 | java.sql.Connection conn; 27 | 28 | Class.forName(driver); 29 | conn = DriverManager.getConnection(url, "sa", "chrdw,hdhxt."); 30 | Statement st = conn.createStatement(); 31 | Statement st1 = conn.createStatement(); 32 | Statement updateStatement = conn.createStatement(); 33 | 34 | String sql = "select * from stock"; 35 | 36 | Integer index = 1; 37 | ResultSet resultSet = st.executeQuery(sql); 38 | while (resultSet.next()) { 39 | String pkid = resultSet.getString("pkid"); 40 | String stockcode = resultSet.getString("code"); 41 | String name = resultSet.getString("name"); 42 | 43 | sql = "select * from day where stockcode='" + stockcode + "' order by tradedate desc"; 44 | ResultSet rSet = st1.executeQuery(sql); 45 | 46 | while (rSet.next()) { 47 | Double yprice = rSet.getDouble("yesterdayprice"); 48 | if (yprice.intValue() == 0) continue; 49 | 50 | Double closePrice = rSet.getDouble("closeprice"); 51 | Double openPrice = rSet.getDouble("openprice"); 52 | Double lowPrice = rSet.getDouble("lowprice"); 53 | Double highPrice =rSet.getDouble("highprice"); 54 | 55 | Date tradedate = rSet.getDate("tradedate"); 56 | 57 | 58 | if ((yprice + yprice*0.1 - highPrice < 0.01) && (highPrice -closePrice > 0.01)) { 59 | System.err.println("代码:" + stockcode + ",名称:" + name + ",涨停日期:" + tradedate); 60 | StringBuilder sb = new StringBuilder(); 61 | sb.append("insert into stocknotlimit(stockname, stockcode, yesterdayprice, openprice, lowprice, highprice, closeprice, limitdate) values('"+name); 62 | sb.append("','" + stockcode); 63 | sb.append("'," + yprice); 64 | sb.append("," + openPrice); 65 | sb.append("," + lowPrice); 66 | sb.append("," + highPrice); 67 | sb.append("," + closePrice); 68 | sb.append(",'" + tradedate + "')"); 69 | 70 | sql = sb.toString(); 71 | System.err.println(sql); 72 | updateStatement.execute(sql); 73 | } 74 | 75 | } 76 | } 77 | st.close(); 78 | st1.close(); 79 | conn.close(); 80 | 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /robot/u_main.dfm: -------------------------------------------------------------------------------- 1 | object frmMain: TfrmMain 2 | Left = 522 3 | Top = 358 4 | Width = 388 5 | Height = 551 6 | Caption = #33258#21160#20132#26131#31995#32479 7 | Color = clBtnFace 8 | Font.Charset = DEFAULT_CHARSET 9 | Font.Color = clWindowText 10 | Font.Height = -11 11 | Font.Name = 'MS Sans Serif' 12 | Font.Style = [] 13 | OldCreateOrder = False 14 | PixelsPerInch = 96 15 | TextHeight = 13 16 | object Memo1: TMemo 17 | Left = 16 18 | Top = 88 19 | Width = 345 20 | Height = 417 21 | TabOrder = 0 22 | end 23 | object btnHistory: TButton 24 | Left = 96 25 | Top = 48 26 | Width = 129 27 | Height = 25 28 | Caption = #36873#25321#21382#21490#20132#26131#25991#20214 29 | TabOrder = 1 30 | OnClick = btnHistoryClick 31 | end 32 | object btnStop: TButton 33 | Left = 112 34 | Top = 16 35 | Width = 113 36 | Height = 25 37 | Caption = #20572#27490#33258#21160#36816#34892 38 | TabOrder = 2 39 | OnClick = btnStopClick 40 | end 41 | object btnAccount: TButton 42 | Left = 232 43 | Top = 48 44 | Width = 129 45 | Height = 25 46 | Caption = #36873#25321#36164#37329#32929#20221#25991#20214 47 | TabOrder = 3 48 | OnClick = btnAccountClick 49 | end 50 | object dt: TDateTimePicker 51 | Left = 272 52 | Top = 16 53 | Width = 90 54 | Height = 21 55 | Date = 40690.668876678240000000 56 | Time = 40690.668876678240000000 57 | TabOrder = 4 58 | end 59 | object ADOConnection1: TADOConnection 60 | ConnectionString = 'Provider=MSDASQL.1;Persist Security Info=False;Data Source=stock' 61 | LoginPrompt = False 62 | Provider = 'MSDASQL.1' 63 | Left = 80 64 | Top = 16 65 | end 66 | object ds: TADODataSet 67 | Connection = ADOConnection1 68 | Parameters = <> 69 | Left = 48 70 | Top = 16 71 | end 72 | object IdSMTP: TIdSMTP 73 | MaxLineAction = maException 74 | ReadTimeout = 0 75 | Host = 'smtp.139.com' 76 | Port = 25 77 | AuthenticationType = atLogin 78 | Password = 'gk790624' 79 | Username = '13613803575' 80 | Left = 16 81 | Top = 48 82 | end 83 | object IdMessage: TIdMessage 84 | AttachmentEncoding = 'MIME' 85 | BccList = <> 86 | CCList = <> 87 | Encoding = meMIME 88 | From.Address = '13613803575@139.com' 89 | From.Text = '13613803575@139.com' 90 | Recipients = < 91 | item 92 | Address = '13613803575@139.com' 93 | Text = '13613803575@139.com' 94 | end> 95 | ReplyTo = < 96 | item 97 | Address = '13613803575@139.com' 98 | Text = '13613803575@139.com' 99 | end> 100 | Left = 56 101 | Top = 48 102 | end 103 | object tmrOperate: TTimer 104 | OnTimer = tmrOperateTimer 105 | Left = 16 106 | Top = 16 107 | end 108 | object ADOQuery: TADOQuery 109 | Connection = ADOConnection1 110 | Parameters = <> 111 | Left = 128 112 | Top = 48 113 | end 114 | object dlgOpen: TOpenDialog 115 | Left = 96 116 | Top = 48 117 | end 118 | object ds1: TADODataSet 119 | Connection = ADOConnection1 120 | Parameters = <> 121 | Left = 48 122 | Top = 16 123 | end 124 | end 125 | -------------------------------------------------------------------------------- /analyzer/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | cn.nit 5 | analyzer 6 | jar 7 | 0.0.1-SNAPSHOT 8 | analyzer 9 | http://maven.apache.org 10 | 11 | 12 | UTF-8 13 | UTF-8 14 | 15 | 1.6 16 | 1.6 17 | 18 | 19 | 20 | 21 | 22 | maven-assembly-plugin 23 | 2.3 24 | 25 | 26 | jar-with-dependencies 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | junit 37 | junit 38 | 3.8.1 39 | test 40 | 41 | 42 | net.sourceforge.jtds 43 | jtds 44 | 1.2.4 45 | 46 | 47 | commons-httpclient 48 | commons-httpclient 49 | 3.1 50 | 51 | 52 | org.apache.commons 53 | commons-lang3 54 | 3.1 55 | 56 | 57 | javax.mail 58 | mail 59 | 1.4.1 60 | 61 | 62 | commons-io 63 | commons-io 64 | 2.4 65 | 66 | 67 | org.jsoup 68 | jsoup 69 | 1.7.1 70 | 71 | 72 | 73 | 74 | mysql 75 | mysql-connector-java 76 | 5.1.6 77 | 78 | 79 | org.mongodb 80 | mongo-java-driver 81 | 2.12.2 82 | 83 | 84 | org.springframework.data 85 | spring-data-mongodb 86 | 1.6.0.RELEASE 87 | 88 | 89 | org.mongodb.morphia 90 | morphia 91 | 0.108 92 | 93 | 94 | org.springframework.boot 95 | spring-boot-starter 96 | 1.1.8.RELEASE 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/hexin/DividendFile.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock.hexin; 2 | 3 | import java.io.IOException; 4 | import java.io.RandomAccessFile; 5 | 6 | public class DividendFile 7 | { 8 | 9 | public DividendFile() 10 | { 11 | header = new FileHeader(); 12 | block = new ComplexIndexBlock(); 13 | } 14 | 15 | public static Boolean Read(DividendFile dividend, RandomAccessFile file) throws IOException 16 | { 17 | if(file == null) 18 | return Boolean.valueOf(false); 19 | file.seek(0L); 20 | if(!FileHeader.Read(dividend.header, file).booleanValue()) 21 | return Boolean.valueOf(false); 22 | int FPosition = FileHeader.LENGTH; 23 | dividend.columnList = new ColumnHeader[dividend.header.getFieldCount()]; 24 | for(int dwI = 0; dwI < dividend.header.getFieldCount(); dwI++) 25 | { 26 | dividend.columnList[dwI] = new ColumnHeader(); 27 | file.seek(FPosition + ColumnHeader.LENGTH * dwI); 28 | ColumnHeader.Read(dividend.columnList[dwI], file); 29 | } 30 | 31 | FPosition = FileHeader.LENGTH + ColumnHeader.LENGTH * dividend.header.getFieldCount(); 32 | file.seek(FPosition); 33 | byte b[] = new byte[dividend.header.getFieldCount() * 2]; 34 | file.read(b); 35 | dividend.w1 = b; 36 | FPosition += dividend.header.getFieldCount() * 2; 37 | file.seek(FPosition); 38 | if(!ComplexIndexBlock.Read(dividend.block, file).booleanValue()) 39 | return Boolean.valueOf(false); 40 | try 41 | { 42 | FPosition = dividend.header.getHeaderLength(); 43 | file.seek(FPosition); 44 | dividend.recordList = new DividendRecord[dividend.header.getRecordCount()]; 45 | for(int dwI = 0; dwI < dividend.header.getRecordCount(); dwI++) 46 | { 47 | dividend.recordList[dwI] = new DividendRecord(); 48 | file.seek(FPosition + dwI * dividend.header.getRecordLength()); 49 | DividendRecord.Read(dividend.recordList[dwI], file); 50 | } 51 | 52 | } 53 | catch(IOException e) 54 | { 55 | e.printStackTrace(); 56 | } 57 | return Boolean.valueOf(true); 58 | } 59 | 60 | public FileHeader getHeader() 61 | { 62 | return header; 63 | } 64 | 65 | public void setHeader(FileHeader header) 66 | { 67 | this.header = header; 68 | } 69 | 70 | public ColumnHeader[] getColumnList() 71 | { 72 | return columnList; 73 | } 74 | 75 | public void setColumnList(ColumnHeader columnList[]) 76 | { 77 | this.columnList = columnList; 78 | } 79 | 80 | public byte[] getW1() 81 | { 82 | return w1; 83 | } 84 | 85 | public void setW1(byte w1[]) 86 | { 87 | this.w1 = w1; 88 | } 89 | 90 | public ComplexIndexBlock getBlock() 91 | { 92 | return block; 93 | } 94 | 95 | public void setBlock(ComplexIndexBlock block) 96 | { 97 | this.block = block; 98 | } 99 | 100 | public DividendRecord[] getRecordList() 101 | { 102 | return recordList; 103 | } 104 | 105 | public void setRecordList(DividendRecord recordList[]) 106 | { 107 | this.recordList = recordList; 108 | } 109 | 110 | private FileHeader header; 111 | private ColumnHeader columnList[]; 112 | private byte w1[]; 113 | private ComplexIndexBlock block; 114 | private DividendRecord recordList[]; 115 | } 116 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/Yesterday.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.InputStreamReader; 7 | import java.net.UnknownHostException; 8 | import java.sql.Connection; 9 | import java.sql.DriverManager; 10 | import java.sql.PreparedStatement; 11 | import java.sql.ResultSet; 12 | import java.sql.Statement; 13 | import java.util.*; 14 | import java.text.SimpleDateFormat; 15 | 16 | import cn.nit.stock.model.StockName; 17 | import cn.nit.stock.model.TradeDay; 18 | import com.mongodb.MongoClient; 19 | import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; 20 | import org.apache.commons.httpclient.HttpClient; 21 | import org.apache.commons.httpclient.HttpException; 22 | import org.apache.commons.httpclient.HttpStatus; 23 | import org.apache.commons.httpclient.methods.GetMethod; 24 | import org.apache.commons.httpclient.params.HttpMethodParams; 25 | import org.mongodb.morphia.Datastore; 26 | import org.springframework.data.domain.Sort; 27 | import org.springframework.data.mongodb.core.MongoOperations; 28 | import org.springframework.data.mongodb.core.MongoTemplate; 29 | import org.springframework.data.mongodb.core.query.Criteria; 30 | import org.springframework.data.mongodb.core.query.Query; 31 | import org.springframework.data.mongodb.core.query.Update; 32 | 33 | /** 34 | * Hello world! 35 | * 36 | */ 37 | public class Yesterday { 38 | 39 | private static Datastore ds; 40 | 41 | private static MongoClient mongoClient; 42 | 43 | private static MongoOperations mongoOps; 44 | 45 | public static void main(String[] args) throws Exception { 46 | 47 | ds = ConnUtils.getDatastore(); 48 | mongoClient = ConnUtils.getMongo(); 49 | mongoOps = new MongoTemplate(mongoClient, "stock"); 50 | 51 | //ResetYesterdayPrice(); 52 | 53 | //FillYesterdayPrice(); 54 | 55 | RemoveInvalidDay(); 56 | } 57 | 58 | private static void RemoveInvalidDay() { 59 | for (StockName stockName : ds.find(StockName.class).asList()) { 60 | 61 | System.err.println(stockName); 62 | 63 | for(TradeDay tradeDay : mongoOps.findAll(TradeDay.class, stockName.getCode())) { 64 | if (tradeDay.isInvalid()) { 65 | mongoOps.remove(tradeDay, stockName.getCode()); 66 | } 67 | } 68 | 69 | } 70 | } 71 | 72 | private static void ResetYesterdayPrice() { 73 | for (StockName stockName : ds.find(StockName.class).asList()) { 74 | 75 | mongoOps.updateMulti(new Query(Criteria.where("yesterdayPrice").gt(0)), Update.update("yesterdayPrice", 0), TradeDay.class, stockName.getCode()); 76 | } 77 | } 78 | 79 | private static void FillYesterdayPrice() throws UnknownHostException { 80 | 81 | 82 | 83 | for (StockName stockName : ds.find(StockName.class).asList()) { 84 | 85 | 86 | String stockcode = stockName.getCode(); 87 | System.err.println(stockName); 88 | 89 | List list = mongoOps.find(new Query(Criteria.where("yesterdayPrice").lt(0.1)).with(new Sort(Sort.Direction.DESC, "tradeDate")), TradeDay.class, stockcode); 90 | 91 | for(int i = 0; i < list.size()-1; i ++) { 92 | 93 | TradeDay today = list.get(i); 94 | TradeDay yesterday = list.get(i+1); 95 | 96 | today.setYesterdayPrice(yesterday.getClosePrice()); 97 | System.err.println(today +"|||" + yesterday); 98 | mongoOps.save(today, stockcode); 99 | } 100 | 101 | 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/AddFiveMinute.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import cn.nit.stock.hexin.MN5File; 4 | import cn.nit.stock.hexin.MN5Record; 5 | import java.io.*; 6 | import java.sql.*; 7 | 8 | public class AddFiveMinute 9 | { 10 | 11 | public AddFiveMinute() 12 | { 13 | } 14 | 15 | public static void main(String args[]) 16 | throws Exception 17 | { 18 | getData(); 19 | } 20 | 21 | private static void getData() 22 | throws ClassNotFoundException, SQLException 23 | { 24 | Connection conn = ConnUtils.getConn(); 25 | Statement st = conn.createStatement(); 26 | Statement statement = conn.createStatement(); 27 | Statement updateStatement = conn.createStatement(); 28 | String sql = "select * from stock"; 29 | for(ResultSet resultSet = st.executeQuery(sql); resultSet.next();) 30 | { 31 | String stockcode = resultSet.getString("code"); 32 | System.err.println(stockcode); 33 | AddStock.createDatabase(stockcode); 34 | String type = "sznse"; 35 | if(stockcode.startsWith("6")) 36 | type = "shase"; 37 | PreparedStatement pstmt = conn.prepareStatement((new StringBuilder("use A")).append(stockcode).toString()); 38 | pstmt.execute(); 39 | try 40 | { 41 | RandomAccessFile file = new RandomAccessFile(new File((new StringBuilder("C:\\同花顺软件\\同花顺\\history\\")).append(type).append("\\min5\\").append(stockcode).append(".mn5").toString()), "r"); 42 | MN5File mn5File = new MN5File(); 43 | MN5File.Read(mn5File, file); 44 | MN5Record amn5record[]; 45 | int j = (amn5record = mn5File.recordList).length; 46 | for(int i = 0; i < j; i++) 47 | { 48 | MN5Record record = amn5record[i]; 49 | if(record.getDate() != null) 50 | { 51 | sql = (new StringBuilder("select * from MN5 where stockcode='")).append(stockcode).append("' and tradedate='").append(record.getDate()).append("'").toString(); 52 | ResultSet rs = statement.executeQuery(sql); 53 | if(!rs.next()) 54 | { 55 | StringBuilder sb = new StringBuilder(); 56 | sb.append("insert into MN5"); 57 | sb.append("(stockcode, open, low, high, close, amount, volume, tradedate) values("); 58 | sb.append((new StringBuilder("'")).append(stockcode).toString()); 59 | sb.append((new StringBuilder("',")).append(record.getOpen()).toString()); 60 | sb.append((new StringBuilder(",")).append(record.getLow()).toString()); 61 | sb.append((new StringBuilder(",")).append(record.getHigh()).toString()); 62 | sb.append((new StringBuilder(",")).append(record.getClose()).toString()); 63 | sb.append((new StringBuilder(",")).append(record.getAmount()).toString()); 64 | sb.append((new StringBuilder(",")).append(record.getVolume()).toString()); 65 | sb.append((new StringBuilder(",'")).append(record.getDate()).append("')").toString()); 66 | sql = sb.toString(); 67 | updateStatement.execute(sql); 68 | } 69 | } 70 | } 71 | 72 | } 73 | catch(FileNotFoundException e) 74 | { 75 | e.printStackTrace(); 76 | } 77 | } 78 | 79 | st.close(); 80 | conn.close(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/Simulate.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.InputStreamReader; 7 | import java.sql.Connection; 8 | import java.sql.DriverManager; 9 | import java.sql.ResultSet; 10 | import java.sql.Statement; 11 | import java.util.ArrayList; 12 | import java.util.HashMap; 13 | import java.util.List; 14 | import java.util.Map; 15 | import java.util.Date; 16 | import java.util.Calendar; 17 | import java.text.DateFormat; 18 | import java.text.SimpleDateFormat; 19 | 20 | import javax.mail.SendFailedException; 21 | 22 | import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; 23 | import org.apache.commons.httpclient.HttpClient; 24 | import org.apache.commons.httpclient.HttpException; 25 | import org.apache.commons.httpclient.HttpStatus; 26 | import org.apache.commons.httpclient.methods.GetMethod; 27 | import org.apache.commons.httpclient.params.HttpMethodParams; 28 | 29 | import cn.nit.stock.model.PatternOne; 30 | import cn.nit.stock.model.PatternTwo; 31 | import cn.nit.stock.model.TradeDay; 32 | 33 | /** 34 | * Hello world! 35 | * 36 | */ 37 | public class Simulate { 38 | public static void main(String[] args) throws Exception { 39 | java.text.DecimalFormat df = new java.text.DecimalFormat("#.## "); 40 | DateFormat dataFormat = new SimpleDateFormat("yyyy-MM-dd"); 41 | 42 | String url = "jdbc:mysql://127.0.0.1:3306/stock?useUnicode=true&characterEncoding=UTF-8&mysqlEncoding=UTF-8"; 43 | String driver = "com.mysql.jdbc.Driver"; 44 | 45 | java.sql.Connection conn; 46 | 47 | Class.forName(driver); 48 | conn = DriverManager.getConnection(url, "root", "aoxun"); 49 | Connection conn1 = DriverManager.getConnection(url, "root", "aoxun"); 50 | Connection conn2 = DriverManager.getConnection(url, "root", "aoxun"); 51 | Statement st = conn.createStatement(); 52 | Statement stStock = conn.createStatement(); 53 | Statement updateStatement = conn2.createStatement(); 54 | Statement selectStatement = conn1.createStatement(); 55 | 56 | String stockSql = "select * from stock"; 57 | 58 | ResultSet rsStock = stStock.executeQuery(stockSql); 59 | Date startTrade = dataFormat.parse("2010-01-01"); 60 | 61 | while (rsStock.next()) { 62 | String stockCode = rsStock.getString("code"); 63 | // stockCode = "002192"; 64 | System.err.println("分析" + stockCode + ","); 65 | String sql = "select * from day where stockcode='" + stockCode 66 | + "' and tradedate>'2011-1-1' order by tradedate"; 67 | 68 | ResultSet resultSet = st.executeQuery(sql); 69 | 70 | List tradeList = new ArrayList(); 71 | 72 | while (resultSet.next()) { 73 | TradeDay tradeDay = new TradeDay( 74 | resultSet.getDouble("yesterdayprice"), 75 | resultSet.getDouble("openprice"), 76 | resultSet.getDouble("closeprice"), 77 | resultSet.getDouble("highprice"), 78 | resultSet.getDouble("lowprice"), 79 | resultSet.getString("stockcode"), 80 | resultSet.getString("tradedate")); 81 | tradeList.add(tradeDay); 82 | } 83 | for (int i = 0; i < tradeList.size();) { 84 | TradeDay first = tradeList.get(i++); 85 | if (i == tradeList.size()) break; 86 | TradeDay second = tradeList.get(i++); 87 | 88 | if (i == tradeList.size()) break; 89 | TradeDay third = tradeList.get(i++); 90 | 91 | PatternTwo patternTwo = new PatternTwo(first, second, third); 92 | 93 | if (patternTwo.isMatch()) { 94 | System.err.println(patternTwo); 95 | } 96 | } 97 | } 98 | 99 | st.close(); 100 | stStock.close(); 101 | selectStatement.close(); 102 | conn.close(); 103 | conn1.close(); 104 | conn2.close(); 105 | 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/SevenMatch.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import java.sql.DriverManager; 4 | import java.sql.ResultSet; 5 | import java.sql.Statement; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * Hello world! 11 | * 12 | */ 13 | public class SevenMatch { 14 | public static void main(String[] args) throws Exception { 15 | 16 | List tradeDates = new ArrayList(); 17 | //tradeDates.add("2011-02-09"); 18 | 19 | tradeDates.add("2011-01-31"); 20 | tradeDates.add("2011-02-01"); 21 | 22 | String url = "jdbc:jtds:sqlserver://218.28.139.40:4433/stock"; 23 | String driver = "net.sourceforge.jtds.jdbc.Driver"; 24 | java.sql.Connection conn; 25 | 26 | Class.forName(driver); 27 | conn = DriverManager.getConnection(url, "sa", "chrdw,hdhxt."); 28 | Statement st = conn.createStatement(); 29 | Statement updateStatement = conn.createStatement(); 30 | Statement insertStatement = conn.createStatement(); 31 | 32 | for (String tradeDate : tradeDates) { 33 | 34 | String sql = "select * from seven where tradedate='" + tradeDate 35 | + "'"; 36 | 37 | ResultSet resultSet = st.executeQuery(sql); 38 | Integer index = 1; 39 | while (resultSet.next()) { 40 | String pkid = resultSet.getString("pkid"); 41 | String stockcode = resultSet.getString("stockcode"); 42 | String stockName = resultSet.getString("stockname"); 43 | Double sevenPrice = resultSet.getDouble("sevenprice"); 44 | 45 | sql = "select * from day where stockcode='" + stockcode 46 | + "' and tradedate>'" + tradeDate 47 | + "' order by tradedate"; 48 | 49 | ResultSet rs = updateStatement.executeQuery(sql); 50 | 51 | List tradeDateList = new ArrayList(); 52 | List lowPriceList = new ArrayList(); 53 | List highPriceList = new ArrayList(); 54 | 55 | Boolean first = true; 56 | Double closePrice = 0d; 57 | while (rs.next()) { 58 | if (first) { 59 | closePrice = rs.getDouble("closeprice"); 60 | first = false; 61 | } 62 | String tradedate = rs.getString("tradedate"); 63 | tradeDateList.add(tradedate); 64 | lowPriceList.add(rs.getDouble("lowprice")); 65 | highPriceList.add(rs.getDouble("highprice")); 66 | } 67 | 68 | if (tradeDateList.size() == 0) 69 | continue; 70 | 71 | Double lowPrice = 0d; 72 | int lowIndex = 0; 73 | 74 | for (int i = 0; i < lowPriceList.size(); i++) { 75 | Double currentPrice = lowPriceList.get(i); 76 | if (sevenPrice >= currentPrice) { 77 | 78 | sql = "update seven set matchdate='" 79 | + tradeDateList.get(i) + "' where pkid=" + pkid; 80 | System.err.println(sql); 81 | insertStatement.execute(sql); 82 | break; 83 | } 84 | } 85 | 86 | } 87 | } 88 | st.close(); 89 | conn.close(); 90 | 91 | // Properties props = System.getProperties(); 92 | // props.put("mail.smtp.host", "smtp.139.com"); 93 | // 94 | // Session session = Session.getDefaultInstance(props, null); 95 | // MimeMessage message = new MimeMessage(session); 96 | // message.setFrom(new InternetAddress("13613803575@139.com")); 97 | // message.addRecipient(Message.RecipientType.TO, new InternetAddress( 98 | // "13613803575@139.com")); 99 | // 100 | // DateFormat df = new SimpleDateFormat("yyyy年MM月dd日"); 101 | // Date tradedate = new Date(); 102 | // message.setSubject(df.format(tradedate) + " 跳空涨停提醒:"); 103 | // String content = sb.toString(); 104 | // if (StringUtils.isEmpty(content)) { 105 | // content = "今日没有跳空涨停股票。"; 106 | // } 107 | // message.setText(content); 108 | 109 | // Transport transport = session.getTransport( "smtp" );//指定的协议 110 | // transport.connect("smtp.139.com", "13613803575", "gk790624"); 111 | // transport.sendMessage(message,message.getAllRecipients()); 112 | // transport.close(); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/AddD1Bar.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import cn.nit.stock.hexin.D1BarFile; 4 | import cn.nit.stock.hexin.D1BarRecord; 5 | import java.io.*; 6 | import java.sql.*; 7 | 8 | // Referenced classes of package cn.nit.stock: 9 | // ConnUtils, AddStock 10 | 11 | public class AddD1Bar 12 | { 13 | 14 | public AddD1Bar() 15 | { 16 | } 17 | 18 | public static void main(String args[]) 19 | throws Exception 20 | { 21 | getData(); 22 | } 23 | 24 | private static void getData() 25 | throws ClassNotFoundException, SQLException 26 | { 27 | Connection conn = ConnUtils.getConn(); 28 | Statement st = conn.createStatement(); 29 | Statement statement = conn.createStatement(); 30 | Statement updateStatement = conn.createStatement(); 31 | String sql = "select * from stock"; 32 | for(ResultSet resultSet = st.executeQuery(sql); resultSet.next();) 33 | { 34 | String stockcode = resultSet.getString("code"); 35 | System.err.println(stockcode); 36 | AddStock.createDatabase(stockcode); 37 | String type = "sznse"; 38 | if(stockcode.startsWith("6")) 39 | type = "shase"; 40 | PreparedStatement pstmt = conn.prepareStatement((new StringBuilder("use A")).append(stockcode).toString()); 41 | pstmt.execute(); 42 | try 43 | { 44 | RandomAccessFile file = new RandomAccessFile(new File((new StringBuilder("C:\\同花顺软件\\同花顺\\history\\")).append(type).append("\\day\\").append(stockcode).append(".day").toString()), "r"); 45 | D1BarFile d1barFile = new D1BarFile(); 46 | D1BarFile.Read(d1barFile, file); 47 | D1BarRecord ad1barrecord[]; 48 | int j = (ad1barrecord = d1barFile.recordList).length; 49 | for(int i = 0; i < j; i++) 50 | { 51 | D1BarRecord record = ad1barrecord[i]; 52 | if(record.getDate() != null) 53 | { 54 | sql = (new StringBuilder("select * from day where stockcode='")).append(stockcode).append("' and tradedate='").append(record.getDate()).append("'").toString(); 55 | ResultSet rs = statement.executeQuery(sql); 56 | if(!rs.next()) 57 | { 58 | StringBuilder sb = new StringBuilder(); 59 | sb.append("insert into day"); 60 | sb.append("(stockcode, open, low, high, close, amount, volume, tradedate) values("); 61 | sb.append((new StringBuilder("'")).append(stockcode).toString()); 62 | sb.append((new StringBuilder("',")).append(record.getOpen()).toString()); 63 | sb.append((new StringBuilder(",")).append(record.getLow()).toString()); 64 | sb.append((new StringBuilder(",")).append(record.getHigh()).toString()); 65 | sb.append((new StringBuilder(",")).append(record.getClose()).toString()); 66 | sb.append((new StringBuilder(",")).append(record.getAmount()).toString()); 67 | sb.append((new StringBuilder(",")).append(record.getVolume()).toString()); 68 | sb.append((new StringBuilder(",'")).append(record.getDate()).append("')").toString()); 69 | sql = sb.toString(); 70 | System.err.println(sql); 71 | updateStatement.execute(sql); 72 | } 73 | } 74 | } 75 | 76 | } 77 | catch(FileNotFoundException e) 78 | { 79 | e.printStackTrace(); 80 | } 81 | } 82 | 83 | st.close(); 84 | conn.close(); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/model/TradeDay.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock.model; 2 | 3 | import org.bson.types.ObjectId; 4 | import org.mongodb.morphia.annotations.Id; 5 | import org.springframework.data.mongodb.core.mapping.Document; 6 | 7 | import java.text.DateFormat; 8 | import java.text.SimpleDateFormat; 9 | import java.util.Date; 10 | 11 | @Document 12 | public class TradeDay { 13 | 14 | 15 | private static DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); 16 | 17 | @Id 18 | private ObjectId id; 19 | 20 | Double yesterdayPrice, openPrice, closePrice, highPrice, lowPrice; 21 | String stockCode; 22 | String tradeDate; 23 | 24 | public Boolean isInvalid() { 25 | Double delta = Math.abs(yesterdayPrice - highPrice) + Math.abs(yesterdayPrice - lowPrice); 26 | return delta < 0.01; 27 | } 28 | 29 | public Double getYesterdayPrice() { 30 | return yesterdayPrice; 31 | } 32 | 33 | 34 | 35 | public void setYesterdayPrice(Double yesterdayPrice) { 36 | this.yesterdayPrice = yesterdayPrice; 37 | } 38 | 39 | 40 | 41 | public Double getOpenPrice() { 42 | return openPrice; 43 | } 44 | 45 | 46 | 47 | public void setOpenPrice(Double openPrice) { 48 | this.openPrice = openPrice; 49 | } 50 | 51 | 52 | 53 | public Double getClosePrice() { 54 | return closePrice; 55 | } 56 | 57 | 58 | 59 | public void setClosePrice(Double closePrice) { 60 | this.closePrice = closePrice; 61 | } 62 | 63 | 64 | 65 | public Double getHighPrice() { 66 | return highPrice; 67 | } 68 | 69 | 70 | 71 | public void setHighPrice(Double highPrice) { 72 | this.highPrice = highPrice; 73 | } 74 | 75 | 76 | 77 | public Double getLowPrice() { 78 | return lowPrice; 79 | } 80 | 81 | 82 | 83 | public void setLowPrice(Double lowPrice) { 84 | this.lowPrice = lowPrice; 85 | } 86 | 87 | 88 | 89 | 90 | public String getStockCode() { 91 | return stockCode; 92 | } 93 | 94 | 95 | 96 | public void setStockCode(String stockCode) { 97 | this.stockCode = stockCode; 98 | } 99 | 100 | 101 | 102 | public String getTradeDate() { 103 | return tradeDate; 104 | } 105 | 106 | 107 | 108 | public void setTradeDate(String tradeDate) { 109 | this.tradeDate = tradeDate; 110 | } 111 | 112 | 113 | 114 | public Boolean isHighLimit() { 115 | return yesterdayPrice*1.1 - closePrice < 0.01; 116 | } 117 | 118 | public Boolean isHighestLimt() { 119 | return (yesterdayPrice*1.1 - highPrice < 0.01) && !isHighLimit(); 120 | } 121 | 122 | public Boolean isOpenLimit() { 123 | return isHighLimit() && (highPrice - openPrice < 0.01); 124 | } 125 | 126 | public TradeDay(Double yesterdayPrice, Double openPrice, Double closePrice, 127 | Double highPrice, Double lowPrice, String stockCode, String tradeDate) { 128 | super(); 129 | this.yesterdayPrice = yesterdayPrice; 130 | this.openPrice = openPrice; 131 | this.closePrice = closePrice; 132 | this.highPrice = highPrice; 133 | this.lowPrice = lowPrice; 134 | this.stockCode = stockCode; 135 | this.tradeDate = tradeDate; 136 | } 137 | 138 | 139 | 140 | @Override 141 | public String toString() { 142 | StringBuilder builder = new StringBuilder(); 143 | builder.append("TradeDay [yesterdayPrice="); 144 | builder.append(yesterdayPrice); 145 | builder.append(", openPrice="); 146 | builder.append(openPrice); 147 | builder.append(", closePrice="); 148 | builder.append(closePrice); 149 | builder.append(", highPrice="); 150 | builder.append(highPrice); 151 | builder.append(", lowPrice="); 152 | builder.append(lowPrice); 153 | builder.append(", stockCode="); 154 | builder.append(stockCode); 155 | builder.append(", tradeDate="); 156 | builder.append(tradeDate); 157 | builder.append("]"); 158 | return builder.toString(); 159 | } 160 | 161 | 162 | public boolean isTodayLimit() { 163 | Date today = new Date(); 164 | return df.format(today).equals(tradeDate) && isOpenLimit(); 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/StockBoard.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.InputStreamReader; 7 | import java.sql.DriverManager; 8 | import java.sql.ResultSet; 9 | import java.sql.Statement; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; 14 | import org.apache.commons.httpclient.HttpClient; 15 | import org.apache.commons.httpclient.HttpException; 16 | import org.apache.commons.httpclient.HttpStatus; 17 | import org.apache.commons.httpclient.methods.GetMethod; 18 | import org.apache.commons.httpclient.params.HttpMethodParams; 19 | 20 | /** 21 | * Hello world! 22 | * 23 | */ 24 | public class StockBoard { 25 | public static void main(String[] args) throws Exception { 26 | // Create an instance of HttpClient. 27 | HttpClient client = new HttpClient(); 28 | // client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, 29 | // "GBK"); 30 | 31 | String url = "jdbc:jtds:sqlserver://218.28.139.40:4433/stock"; 32 | String driver = "net.sourceforge.jtds.jdbc.Driver"; 33 | java.sql.Connection conn; 34 | 35 | Class.forName(driver); 36 | conn = DriverManager.getConnection(url, "sa", "chrdw,hdhxt."); 37 | Statement stStock = conn.createStatement(); 38 | Statement stBoard = conn.createStatement(); 39 | Statement updateStatement = conn.createStatement(); 40 | 41 | String boardcode="881262"; 42 | String[] stockCodes = new String[] { 43 | "600051", 44 | "600079", 45 | "600119", 46 | "600200", 47 | "600209", 48 | "600256", 49 | "600555", 50 | "600608", 51 | "600620", 52 | "600622", 53 | "600643", 54 | "600647", 55 | "600661", 56 | "600683", 57 | "600687", 58 | "600708", 59 | "600711", 60 | "600730", 61 | "600743", 62 | "600759", 63 | "600770", 64 | "600784", 65 | "600790", 66 | "600805", 67 | "600811", 68 | "600832", 69 | "600846", 70 | "600858", 71 | "600868", 72 | "600872", 73 | "600881", 74 | "600883", 75 | "000005", 76 | "000009", 77 | "000025", 78 | "000034", 79 | "000040", 80 | "000301", 81 | "000503", 82 | "000507", 83 | "000532", 84 | "000551", 85 | "000571", 86 | "000626", 87 | "000632", 88 | "000633", 89 | "000671", 90 | "000803", 91 | "000881", 92 | "000915", 93 | "002077", 94 | "002344", 95 | "300012", 96 | 97 | 98 | }; 99 | 100 | for (String stockCode : stockCodes) { 101 | String sql = "select * from stock where code='" + stockCode + "'"; 102 | 103 | ResultSet resultSet = stStock.executeQuery(sql); 104 | Integer stockID = 0; 105 | while (resultSet.next()) { 106 | stockID = resultSet.getInt("pkid"); 107 | } 108 | 109 | if (stockID == 0) { 110 | String stockType = stockCode.startsWith("0") ? "sz":"sh"; 111 | sql = "insert into stock(code,type) values('" + stockCode + "', '" + stockType + "')"; 112 | System.err.println(sql); 113 | updateStatement.execute(sql); 114 | 115 | sql = "select * from stock where code='" + stockCode + "'"; 116 | 117 | resultSet = stStock.executeQuery(sql); 118 | while (resultSet.next()) { 119 | stockID = resultSet.getInt("pkid"); 120 | } 121 | } 122 | 123 | sql = "select * from stockboard where boardcode='" + boardcode + "'"; 124 | resultSet = stStock.executeQuery(sql); 125 | Integer boardID = 0; 126 | while (resultSet.next()) { 127 | boardID = resultSet.getInt("pkid"); 128 | System.err.println("正在处理" + resultSet.getString("boardname")+"板块"); 129 | } 130 | 131 | sql = "insert into stockinboard(stockid,boardid) values(" + stockID + ", " + boardID + ")"; 132 | 133 | System.err.println(sql); 134 | updateStatement.execute(sql); 135 | 136 | 137 | } 138 | 139 | conn.close(); 140 | 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/HistoryLine.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.InputStreamReader; 7 | import java.sql.DriverManager; 8 | import java.sql.ResultSet; 9 | import java.sql.Statement; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; 14 | import org.apache.commons.httpclient.HttpClient; 15 | import org.apache.commons.httpclient.HttpException; 16 | import org.apache.commons.httpclient.HttpStatus; 17 | import org.apache.commons.httpclient.methods.GetMethod; 18 | import org.apache.commons.httpclient.params.HttpMethodParams; 19 | 20 | /** 21 | * Hello world! 22 | * 23 | */ 24 | public class HistoryLine { 25 | public static void main(String[] args) throws Exception { 26 | // Create an instance of HttpClient. 27 | HttpClient client = new HttpClient(); 28 | // client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, 29 | // "GBK"); 30 | 31 | String url = "jdbc:jtds:sqlserver://218.28.139.40:4433/stock"; 32 | String driver = "net.sourceforge.jtds.jdbc.Driver"; 33 | java.sql.Connection conn; 34 | 35 | Class.forName(driver); 36 | conn = DriverManager.getConnection(url, "sa", "chrdw,hdhxt."); 37 | Statement st = conn.createStatement(); 38 | Statement updateStatement = conn.createStatement(); 39 | 40 | 41 | // Create a method instance. 42 | GetMethod method = new GetMethod( 43 | "http://table.finance.yahoo.com/table.csv?s=000001.ss"); 44 | method.addRequestHeader("Content-type", "text/html; charset=utf-8"); 45 | // Provide custom retry handler is necessary 46 | method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 47 | new DefaultHttpMethodRetryHandler(3, false)); 48 | 49 | try { 50 | // 定义一个输入流 51 | InputStream ins = null; 52 | // 定义文件流 53 | BufferedReader br = null; 54 | 55 | // Execute the method. 56 | int statusCode = client.executeMethod(method); 57 | 58 | if (statusCode != HttpStatus.SC_OK) { 59 | System.err.println("Method failed: " 60 | + method.getStatusLine()); 61 | } 62 | 63 | ins = method.getResponseBodyAsStream(); 64 | 65 | // 按服务器编码字符集构建文件流,这里的CHARSET要根据实际情况设置 66 | Boolean firstLine = true; 67 | br = new BufferedReader(new InputStreamReader(ins, method 68 | .getResponseCharSet())); 69 | String line = null; 70 | while ((line = br.readLine()) != null) { 71 | if (line.contains("Not Found")) break; 72 | 73 | if (firstLine) { 74 | firstLine = false; 75 | continue; 76 | } 77 | 78 | System.err.println(line); 79 | String[] results = line.split(","); 80 | 81 | String tradedate = results[0]; 82 | String openprice = results[1]; 83 | String highprice = results[2]; 84 | String lowprice = results[3]; 85 | String closeprice = results[4]; 86 | String volume = results[5]; 87 | 88 | StringBuilder sb = new StringBuilder(); 89 | sb 90 | .append("insert into day(stockcode, openprice, highprice, lowprice, closeprice, volume, tradedate) values('" 91 | + "1a0001"); 92 | sb.append("'," + openprice); 93 | sb.append("," + highprice); 94 | sb.append("," + lowprice); 95 | sb.append("," + closeprice); 96 | sb.append("," + volume); 97 | sb.append(",'" + tradedate + "')"); 98 | 99 | String sql = sb.toString(); 100 | System.err.println(sql); 101 | updateStatement.execute(sql); 102 | } 103 | 104 | } catch (HttpException e) { 105 | System.err.println("Fatal protocol violation: " 106 | + e.getMessage()); 107 | e.printStackTrace(); 108 | } catch (IOException e) { 109 | System.err.println("Fatal transport error: " + e.getMessage()); 110 | e.printStackTrace(); 111 | } finally { 112 | // Release the connection. 113 | method.releaseConnection(); 114 | } 115 | // break; 116 | 117 | 118 | st.close(); 119 | conn.close(); 120 | 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/hexin/MN5Record.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock.hexin; 2 | 3 | import java.io.IOException; 4 | import java.io.RandomAccessFile; 5 | 6 | public class MN5Record 7 | { 8 | 9 | public MN5Record() 10 | { 11 | } 12 | 13 | public static Boolean Read(MN5Record record, RandomAccessFile file) throws IOException 14 | { 15 | if(file == null) 16 | return Boolean.valueOf(false); 17 | long FValue; 18 | FValue = IntUtils.readInt32(file); 19 | if(FValue == 0L) 20 | return Boolean.valueOf(false); 21 | try 22 | { 23 | String value = toBinary(FValue, 2); 24 | int year = Integer.parseInt(value.substring(0, 7), 2) + 1900; 25 | int month = Integer.parseInt(value.substring(7, 11), 2); 26 | int day = Integer.parseInt(value.substring(11, 16), 2); 27 | int hour = Integer.parseInt(value.substring(16, 21), 2); 28 | int minute = Integer.parseInt(value.substring(21, 27), 2); 29 | record.date = (new StringBuilder(String.valueOf(year))).append("-").append(month).append("-").append(day).append(" ").append(hour).append(":").append(minute).toString(); 30 | record.open = GetValue(IntUtils.readInt32(file)); 31 | record.high = GetValue(IntUtils.readInt32(file)); 32 | record.low = GetValue(IntUtils.readInt32(file)); 33 | record.close = GetValue(IntUtils.readInt32(file)); 34 | record.amount = GetValue(IntUtils.readInt32(file)); 35 | record.volume = GetValue(IntUtils.readInt32(file)); 36 | return Boolean.valueOf(true); 37 | } 38 | catch(IOException e) 39 | { 40 | e.printStackTrace(); 41 | } 42 | return Boolean.valueOf(true); 43 | } 44 | 45 | private static String toBinary(long n, int target) 46 | { 47 | String s = ""; 48 | for(; n != 0L; n /= target) 49 | s = (new StringBuilder(String.valueOf(n % (long)target))).append(s).toString(); 50 | 51 | return s; 52 | } 53 | 54 | public static double GetValue(long value) 55 | { 56 | double FValue = value & 0xfffffffL; 57 | byte FSign = (byte)(int)(value >> 28); 58 | if((FSign & 7) != 0) 59 | { 60 | double FFactor = Math.pow(10D, FSign & 7); 61 | if((FSign & 8) != 0) 62 | FValue /= FFactor; 63 | else 64 | FValue *= FFactor; 65 | } 66 | return FValue; 67 | } 68 | 69 | public String getDate() 70 | { 71 | return date; 72 | } 73 | 74 | public void setDate(String date) 75 | { 76 | this.date = date; 77 | } 78 | 79 | public double getOpen() 80 | { 81 | return open; 82 | } 83 | 84 | public void setOpen(double open) 85 | { 86 | this.open = open; 87 | } 88 | 89 | public double getHigh() 90 | { 91 | return high; 92 | } 93 | 94 | public void setHigh(double high) 95 | { 96 | this.high = high; 97 | } 98 | 99 | public double getLow() 100 | { 101 | return low; 102 | } 103 | 104 | public void setLow(double low) 105 | { 106 | this.low = low; 107 | } 108 | 109 | public double getClose() 110 | { 111 | return close; 112 | } 113 | 114 | public void setClose(double close) 115 | { 116 | this.close = close; 117 | } 118 | 119 | public double getAmount() 120 | { 121 | return amount; 122 | } 123 | 124 | public void setAmount(double amount) 125 | { 126 | this.amount = amount; 127 | } 128 | 129 | public double getVolume() 130 | { 131 | return volume; 132 | } 133 | 134 | public void setVolume(double volume) 135 | { 136 | this.volume = volume; 137 | } 138 | 139 | private String date; 140 | private double open; 141 | private double high; 142 | private double low; 143 | private double close; 144 | private double amount; 145 | private double volume; 146 | public static int LENGTH = 16; 147 | 148 | } 149 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/History.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import cn.nit.stock.dao.StockNameRepository; 4 | import cn.nit.stock.model.StockName; 5 | import cn.nit.stock.model.TradeDay; 6 | import com.mongodb.MongoClient; 7 | import org.apache.commons.httpclient.HttpClient; 8 | import org.apache.commons.io.FileUtils; 9 | import org.mongodb.morphia.Datastore; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.CommandLineRunner; 12 | import org.springframework.boot.SpringApplication; 13 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 14 | import org.springframework.data.mongodb.core.MongoOperations; 15 | import org.springframework.data.mongodb.core.MongoTemplate; 16 | import java.io.File; 17 | import java.io.IOException; 18 | import java.net.URL; 19 | import java.text.DateFormat; 20 | import java.text.SimpleDateFormat; 21 | import java.util.ArrayList; 22 | import java.util.Calendar; 23 | import java.util.Date; 24 | import java.util.List; 25 | 26 | /** 27 | * Hello world! 28 | */ 29 | public class History implements CommandLineRunner { 30 | 31 | public static void main(String[] args) throws Exception { 32 | SpringApplication.run(History.class, args); 33 | } 34 | 35 | @Override 36 | public void run(String... strings) throws Exception { 37 | Boolean firstLine = true; 38 | DateFormat dataFormat = new SimpleDateFormat("yyyy-MM-dd"); 39 | 40 | List tradeDates = new ArrayList(); 41 | 42 | Calendar calendar = Calendar.getInstance(); 43 | calendar.set(2013, 1, 1); 44 | 45 | Date startDate = calendar.getTime(); 46 | 47 | // Create an instance of HttpClient. 48 | HttpClient client = new HttpClient(); 49 | // client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, 50 | // "GBK"); 51 | 52 | Datastore ds = ConnUtils.getDatastore(); 53 | 54 | MongoClient mongoClient = ConnUtils.getMongo(); 55 | 56 | MongoOperations mongoOps = new MongoTemplate(mongoClient, "stock"); 57 | 58 | 59 | for (StockName stockName : ds.find(StockName.class).asList()) { 60 | 61 | String stockcode = stockName.getCode(); 62 | 63 | 64 | if (mongoOps.getCollection(stockcode).count() > 0) continue; 65 | 66 | String stocktype = "sz"; 67 | 68 | if (stockcode.startsWith("6")) 69 | stocktype = "ss"; 70 | 71 | 72 | System.err.println(stockName); 73 | 74 | String url = "http://table.finance.yahoo.com/table.csv?s=" + stockcode + "." + stocktype; 75 | 76 | File tempFile = new File("d:\\future\\data\\" + stockcode + ".csv"); 77 | 78 | try { 79 | FileUtils.copyURLToFile(new URL(url), tempFile, 30000, 30000); 80 | } catch (IOException e) { 81 | System.err.println(e); 82 | continue; 83 | } 84 | 85 | firstLine = true; 86 | 87 | for (String line : FileUtils.readLines(tempFile)) { 88 | 89 | if (firstLine) { 90 | firstLine = false; 91 | continue; 92 | } 93 | 94 | String[] results = line.split(","); 95 | 96 | String tradedate = results[0]; 97 | 98 | Date tDate = dataFormat.parse(tradedate); 99 | 100 | if (tDate.before(startDate)) continue; 101 | 102 | //if (!tradeDates.contains(tradedate)) continue; 103 | 104 | Double openprice = Double.parseDouble(results[1]); 105 | Double highprice = Double.parseDouble(results[2]); 106 | Double lowprice = Double.parseDouble(results[3]); 107 | Double closeprice = Double.parseDouble(results[4]); 108 | //String volume = results[5]; 109 | 110 | 111 | TradeDay tradeDay = new TradeDay(0d, openprice, closeprice, highprice, lowprice, stockcode, tradedate); 112 | 113 | mongoOps.insert(tradeDay, stockcode); 114 | 115 | //System.err.println(tradeDay); 116 | } 117 | 118 | 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/hexin/MN30Record.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock.hexin; 2 | 3 | import java.io.IOException; 4 | import java.io.RandomAccessFile; 5 | 6 | public class MN30Record 7 | { 8 | 9 | public MN30Record() 10 | { 11 | } 12 | 13 | public static Boolean Read(MN30Record record, RandomAccessFile file) throws IOException 14 | { 15 | if(file == null) 16 | return Boolean.valueOf(false); 17 | long FValue; 18 | FValue = IntUtils.readInt32(file); 19 | if(FValue == 0L) 20 | return Boolean.valueOf(false); 21 | try 22 | { 23 | String value = toBinary(FValue, 2); 24 | int year = Integer.parseInt(value.substring(0, 7), 2) + 1900; 25 | int month = Integer.parseInt(value.substring(7, 11), 2); 26 | int day = Integer.parseInt(value.substring(11, 16), 2); 27 | int hour = Integer.parseInt(value.substring(16, 21), 2); 28 | int minute = Integer.parseInt(value.substring(21, 27), 2); 29 | if(minute == 0 || minute == 30) 30 | { 31 | record.date = (new StringBuilder(String.valueOf(year))).append("-").append(month).append("-").append(day).append(" ").append(hour).append(":").append(minute).toString(); 32 | record.open = GetValue(IntUtils.readInt32(file)); 33 | record.high = GetValue(IntUtils.readInt32(file)); 34 | record.low = GetValue(IntUtils.readInt32(file)); 35 | record.close = GetValue(IntUtils.readInt32(file)); 36 | //record.amount = GetValue(IntUtils.readInt32(file)); 37 | //record.volume = GetValue(IntUtils.readInt32(file)); 38 | } 39 | return Boolean.valueOf(true); 40 | } 41 | catch(IOException e) 42 | { 43 | e.printStackTrace(); 44 | } 45 | return Boolean.valueOf(true); 46 | } 47 | 48 | private static String toBinary(long n, int target) 49 | { 50 | String s = ""; 51 | for(; n != 0L; n /= target) 52 | s = (new StringBuilder(String.valueOf(n % (long)target))).append(s).toString(); 53 | 54 | return s; 55 | } 56 | 57 | public static double GetValue(long value) 58 | { 59 | double FValue = value & 0xfffffffL; 60 | byte FSign = (byte)(int)(value >> 28); 61 | if((FSign & 7) != 0) 62 | { 63 | double FFactor = Math.pow(10D, FSign & 7); 64 | if((FSign & 8) != 0) 65 | FValue /= FFactor; 66 | else 67 | FValue *= FFactor; 68 | } 69 | return FValue; 70 | } 71 | 72 | public String getDate() 73 | { 74 | return date; 75 | } 76 | 77 | public void setDate(String date) 78 | { 79 | this.date = date; 80 | } 81 | 82 | public double getOpen() 83 | { 84 | return open; 85 | } 86 | 87 | public void setOpen(double open) 88 | { 89 | this.open = open; 90 | } 91 | 92 | public double getHigh() 93 | { 94 | return high; 95 | } 96 | 97 | public void setHigh(double high) 98 | { 99 | this.high = high; 100 | } 101 | 102 | public double getLow() 103 | { 104 | return low; 105 | } 106 | 107 | public void setLow(double low) 108 | { 109 | this.low = low; 110 | } 111 | 112 | public double getClose() 113 | { 114 | return close; 115 | } 116 | 117 | public void setClose(double close) 118 | { 119 | this.close = close; 120 | } 121 | 122 | public double getAmount() 123 | { 124 | return amount; 125 | } 126 | 127 | public void setAmount(double amount) 128 | { 129 | this.amount = amount; 130 | } 131 | 132 | public double getVolume() 133 | { 134 | return volume; 135 | } 136 | 137 | public void setVolume(double volume) 138 | { 139 | this.volume = volume; 140 | } 141 | 142 | private String date; 143 | private double open; 144 | private double high; 145 | private double low; 146 | private double close; 147 | private double amount = 0d; 148 | private double volume = 0d; 149 | public static int LENGTH = 16; 150 | 151 | } 152 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/Name.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.InputStreamReader; 7 | import java.sql.DriverManager; 8 | import java.sql.ResultSet; 9 | import java.sql.Statement; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; 14 | import org.apache.commons.httpclient.HttpClient; 15 | import org.apache.commons.httpclient.HttpException; 16 | import org.apache.commons.httpclient.HttpStatus; 17 | import org.apache.commons.httpclient.methods.GetMethod; 18 | import org.apache.commons.httpclient.params.HttpMethodParams; 19 | 20 | 21 | /** 22 | * Hello world! 23 | * 24 | */ 25 | public class Name 26 | { 27 | public static void main( String[] args ) throws Exception 28 | { 29 | // Create an instance of HttpClient. 30 | HttpClient client = new HttpClient(); 31 | //client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "GBK"); 32 | 33 | 34 | String url = "jdbc:jtds:sqlserver://218.28.139.40:4433/stock"; 35 | String driver= "net.sourceforge.jtds.jdbc.Driver"; 36 | java.sql.Connection conn; 37 | 38 | Class.forName(driver); 39 | conn = DriverManager.getConnection(url, "sa", "chrdw,hdhxt."); 40 | Statement st = conn.createStatement(); 41 | Statement updateStatement = conn.createStatement(); 42 | 43 | String sql = "select * from stock where name is null"; 44 | 45 | 46 | ResultSet resultSet = st.executeQuery(sql); 47 | while (resultSet.next()) { 48 | String pkid = resultSet.getString("pkid"); 49 | String stockcode = resultSet.getString("code"); 50 | 51 | // Create a method instance. 52 | GetMethod method = new GetMethod("http://hq.sinajs.cn/list=" + resultSet.getString("type") + stockcode); 53 | method.addRequestHeader("Content-type" , "text/html; charset=utf-8"); 54 | // Provide custom retry handler is necessary 55 | method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 56 | new DefaultHttpMethodRetryHandler(3, false)); 57 | 58 | try { 59 | //定义一个输入流 60 | InputStream ins = null; 61 | //定义文件流 62 | BufferedReader br =null; 63 | 64 | // Execute the method. 65 | int statusCode = client.executeMethod(method); 66 | 67 | if (statusCode != HttpStatus.SC_OK) { 68 | System.err.println("Method failed: " + method.getStatusLine()); 69 | } 70 | 71 | ins = method.getResponseBodyAsStream(); 72 | String charset = method.getResponseCharSet(); 73 | if(charset.toUpperCase().equals("ISO-8859-1")){ 74 | charset = "gbk"; 75 | } 76 | //按服务器编码字符集构建文件流,这里的CHARSET要根据实际情况设置 77 | br = new BufferedReader(new InputStreamReader(ins,method.getResponseCharSet())); 78 | StringBuffer sbf = new StringBuffer(); 79 | String line = null; 80 | while ((line = br.readLine()) != null) 81 | { 82 | sbf.append(line); 83 | } 84 | String result = new String(sbf.toString().getBytes(method.getResponseCharSet()),charset); 85 | //输出内容 86 | String[] results = result.split("\""); 87 | results = results[1].split(","); 88 | System.out.println(stockcode + "=" + results[0]); 89 | String name = results[0].trim(); 90 | if (name.equals("")) continue; 91 | 92 | sql = "update stock set name='" + name + "' where pkid=" + pkid; 93 | System.err.println(sql); 94 | updateStatement.execute(sql); 95 | 96 | } catch (HttpException e) { 97 | System.err.println("Fatal protocol violation: " + e.getMessage()); 98 | e.printStackTrace(); 99 | } catch (IOException e) { 100 | System.err.println("Fatal transport error: " + e.getMessage()); 101 | e.printStackTrace(); 102 | } finally { 103 | // Release the connection. 104 | method.releaseConnection(); 105 | } 106 | //break; 107 | 108 | } 109 | st.close(); 110 | conn.close(); 111 | 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/hexin/D1BarRecord.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock.hexin; 2 | 3 | import com.mongodb.DBObject; 4 | import org.springframework.data.annotation.Id; 5 | 6 | import java.io.IOException; 7 | import java.io.RandomAccessFile; 8 | 9 | 10 | public class D1BarRecord 11 | { 12 | 13 | private String id; 14 | 15 | private String date; 16 | private double open; 17 | private double high; 18 | private double low; 19 | private double close; 20 | private double amount; 21 | private double volume; 22 | public static int LENGTH = 16; 23 | 24 | 25 | public D1BarRecord() 26 | { 27 | } 28 | 29 | public static Boolean Read(D1BarRecord record, RandomAccessFile file) throws IOException 30 | { 31 | if(file == null) 32 | return Boolean.valueOf(false); 33 | long FValue; 34 | FValue = IntUtils.readInt32(file); 35 | if(FValue == 0L) 36 | return Boolean.valueOf(false); 37 | try 38 | { 39 | record.date = (new StringBuilder(String.valueOf(FValue))).toString(); 40 | record.open = GetValue(IntUtils.readInt32(file)); 41 | record.high = GetValue(IntUtils.readInt32(file)); 42 | record.low = GetValue(IntUtils.readInt32(file)); 43 | record.close = GetValue(IntUtils.readInt32(file)); 44 | record.amount = GetValue(IntUtils.readInt32(file)); 45 | record.volume = GetValue(IntUtils.readInt32(file)); 46 | return Boolean.valueOf(true); 47 | } 48 | catch(IOException e) 49 | { 50 | e.printStackTrace(); 51 | } 52 | return Boolean.valueOf(true); 53 | } 54 | 55 | private static String toBinary(long n, int target) 56 | { 57 | String s = ""; 58 | for(; n != 0L; n /= target) 59 | s = (new StringBuilder(String.valueOf(n % (long)target))).append(s).toString(); 60 | 61 | return s; 62 | } 63 | 64 | public static double GetValue(long value) 65 | { 66 | double FValue = value & 0xfffffffL; 67 | byte FSign = (byte)(int)(value >> 28); 68 | if((FSign & 7) != 0) 69 | { 70 | double FFactor = Math.pow(10D, FSign & 7); 71 | if((FSign & 8) != 0) 72 | FValue /= FFactor; 73 | else 74 | FValue *= FFactor; 75 | } 76 | return FValue; 77 | } 78 | 79 | public String getDate() 80 | { 81 | return date; 82 | } 83 | 84 | public void setDate(String date) 85 | { 86 | this.date = date; 87 | } 88 | 89 | public double getOpen() 90 | { 91 | return open; 92 | } 93 | 94 | public void setOpen(double open) 95 | { 96 | this.open = open; 97 | } 98 | 99 | public double getHigh() 100 | { 101 | return high; 102 | } 103 | 104 | public void setHigh(double high) 105 | { 106 | this.high = high; 107 | } 108 | 109 | public double getLow() 110 | { 111 | return low; 112 | } 113 | 114 | public void setLow(double low) 115 | { 116 | this.low = low; 117 | } 118 | 119 | public double getClose() 120 | { 121 | return close; 122 | } 123 | 124 | public void setClose(double close) 125 | { 126 | this.close = close; 127 | } 128 | 129 | public double getAmount() 130 | { 131 | return amount; 132 | } 133 | 134 | public void setAmount(double amount) 135 | { 136 | this.amount = amount; 137 | } 138 | 139 | public double getVolume() 140 | { 141 | return volume; 142 | } 143 | 144 | public void setVolume(double volume) 145 | { 146 | this.volume = volume; 147 | } 148 | 149 | public String getId() { 150 | return id; 151 | } 152 | 153 | public void setId(String id) { 154 | this.id = id; 155 | } 156 | 157 | @Override 158 | public String toString() { 159 | final StringBuilder sb = new StringBuilder("D1BarRecord{"); 160 | sb.append("id='").append(id).append('\''); 161 | sb.append(", date='").append(date).append('\''); 162 | sb.append(", open=").append(open); 163 | sb.append(", high=").append(high); 164 | sb.append(", low=").append(low); 165 | sb.append(", close=").append(close); 166 | sb.append(", amount=").append(amount); 167 | sb.append(", volume=").append(volume); 168 | sb.append('}'); 169 | return sb.toString(); 170 | } 171 | } -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/Day.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import java.io.*; 4 | import java.net.URL; 5 | import java.sql.*; 6 | import java.util.*; 7 | 8 | import cn.nit.stock.model.StockLimit; 9 | import cn.nit.stock.model.StockName; 10 | import cn.nit.stock.model.TradeDay; 11 | import com.mongodb.MongoClient; 12 | import org.apache.commons.httpclient.*; 13 | import org.apache.commons.httpclient.methods.GetMethod; 14 | import org.apache.commons.httpclient.params.HttpMethodParams; 15 | import org.apache.commons.io.IOUtils; 16 | import org.mongodb.morphia.Datastore; 17 | import org.springframework.data.mongodb.core.MongoOperations; 18 | import org.springframework.data.mongodb.core.MongoTemplate; 19 | import org.springframework.data.mongodb.core.query.Criteria; 20 | import org.springframework.data.mongodb.core.query.Query; 21 | 22 | public class Day 23 | { 24 | 25 | private static Datastore ds; 26 | 27 | private static MongoClient mongoClient; 28 | 29 | private static MongoOperations mongoOps; 30 | 31 | public static void main( String[] args ) throws Exception { 32 | ds = ConnUtils.getDatastore(); 33 | mongoClient = ConnUtils.getMongo(); 34 | mongoOps = new MongoTemplate(mongoClient, "stock"); 35 | 36 | List limit = new ArrayList(); 37 | 38 | for (StockName stockName : ds.find(StockName.class).asList()) { 39 | System.err.println(stockName); 40 | addD1Bar(stockName); 41 | } 42 | 43 | SuccessiveLimit successiveLimit = new SuccessiveLimit(); 44 | 45 | successiveLimit.main(args); 46 | 47 | } 48 | 49 | private static void addD1Bar(StockName stockName) 50 | throws ClassNotFoundException, SQLException, HttpException, IOException 51 | { 52 | String stockcode = stockName.getCode(); 53 | 54 | String stocktype = "sz"; 55 | if(stockcode.startsWith("6")) 56 | stocktype = "sh"; 57 | 58 | 59 | URL url = new URL(new StringBuilder("http://hq.sinajs.cn/list=").append(stocktype).append(stockcode).toString()); 60 | 61 | String result = IOUtils.toString(url,"GBK"); 62 | String results[] = result.split("\""); 63 | results = results[1].split(","); 64 | System.out.println((new StringBuilder(String.valueOf(stockcode))).append("=").append(results[0]).toString()); 65 | String name = results[0].trim(); 66 | if(name.equals("")) 67 | { 68 | return; 69 | } 70 | String volume; 71 | String amount; 72 | String tradedate; 73 | 74 | volume = results[8]; 75 | amount = results[9]; 76 | tradedate = results[30]; 77 | if(volume.equals("0")) 78 | { 79 | return; 80 | } 81 | if(name.equals("上证指数")) 82 | stockcode = "1A0001"; 83 | 84 | Double openprice = Double.parseDouble(results[1]); 85 | Double yesterdayprice = Double.parseDouble(results[2]); 86 | Double closeprice = Double.parseDouble(results[3]); 87 | Double highprice = Double.parseDouble(results[4]); 88 | Double lowprice = Double.parseDouble(results[5]); 89 | 90 | TradeDay tradeDay = new TradeDay(yesterdayprice, openprice, closeprice, highprice, lowprice, stockcode, tradedate); 91 | 92 | System.err.println(tradeDay); 93 | 94 | if (!mongoOps.exists((new Query(Criteria.where("tradeDate").is(tradedate))), TradeDay.class, stockcode)) { 95 | mongoOps.insert(tradeDay, stockcode); 96 | } else { 97 | System.err.println("已存在"); 98 | } 99 | 100 | if(yesterdayprice * 1.1 - closeprice < 0.01) 101 | { 102 | System.err.println((new StringBuilder("股票代码:")).append(stockcode).append(",名称:").append(name).append(",涨停日期:").append(tradedate).toString()); 103 | 104 | StockLimit stockLimit = new StockLimit(); 105 | 106 | stockLimit.setStockName(stockName.getName()); 107 | stockLimit.setStockCode(stockcode); 108 | stockLimit.setYesterdayPrice(tradeDay.getYesterdayPrice()); 109 | stockLimit.setClosePrice(tradeDay.getClosePrice()); 110 | stockLimit.setOpenPrice(tradeDay.getOpenPrice()); 111 | stockLimit.setLowPrice(tradeDay.getLowPrice()); 112 | stockLimit.setHighPrice(tradeDay.getHighPrice()); 113 | stockLimit.setLimitDate(tradeDay.getTradeDate()); 114 | 115 | if (!mongoOps.exists((new Query(Criteria.where("limitDate").is(tradedate))), StockLimit.class)) { 116 | mongoOps.save(stockLimit); 117 | } 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/AddDividend.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import cn.nit.stock.hexin.ComplexIndexBlock; 4 | import cn.nit.stock.hexin.ComplexIndexRecord; 5 | import cn.nit.stock.hexin.DividendFile; 6 | import cn.nit.stock.hexin.DividendRecord; 7 | import java.io.*; 8 | import java.sql.*; 9 | import org.apache.commons.lang3.StringUtils; 10 | 11 | public class AddDividend 12 | { 13 | 14 | public AddDividend() 15 | { 16 | } 17 | 18 | public static void main(String args[]) 19 | throws Exception 20 | { 21 | Connection conn = ConnUtils.getConn("stock"); 22 | Statement st = conn.createStatement(); 23 | Statement statement = conn.createStatement(); 24 | Statement updateStatement = conn.createStatement(); 25 | RandomAccessFile file = new RandomAccessFile(new File("C:\\同花顺软件\\同花顺\\finance\\权息资料.财经"), "r"); 26 | DividendFile dividendFile = new DividendFile(); 27 | DividendFile.Read(dividendFile, file); 28 | ComplexIndexRecord acomplexindexrecord[]; 29 | int k = (acomplexindexrecord = dividendFile.getBlock().RecordList).length; 30 | for(int j = 0; j < k; j++) 31 | { 32 | ComplexIndexRecord record = acomplexindexrecord[j]; 33 | int recordNumber = -1; 34 | String stockcode = record.getSymbol(); 35 | String sql = (new StringBuilder("select * from dividendindex where symbol='")).append(stockcode).append("'").toString(); 36 | ResultSet rs = st.executeQuery(sql); 37 | if(rs.next()) 38 | recordNumber = rs.getInt("recordNumber"); 39 | if(recordNumber != record.getRecordNumber()) 40 | { 41 | sql = (new StringBuilder("delete from dividendindex where symbol='")).append(stockcode).append("'").toString(); 42 | st.execute(sql); 43 | StringBuilder sb = new StringBuilder(); 44 | sb.append("insert into dividendindex"); 45 | sb.append("(market, symbol, freeNumber, position, recordNumber) values("); 46 | sb.append(record.getMarket()); 47 | sb.append((new StringBuilder(",'")).append(record.getSymbol()).toString()); 48 | sb.append((new StringBuilder("',")).append(record.getFreeNumber()).toString()); 49 | sb.append((new StringBuilder(",")).append(record.getPosition()).toString()); 50 | sb.append((new StringBuilder(",")).append(record.getRecordNumber()).append(")").toString()); 51 | sql = sb.toString(); 52 | System.err.println(sql); 53 | st.execute(sql); 54 | for(int i = 0; i < record.getRecordNumber(); i++) 55 | { 56 | DividendRecord dividendRecord = dividendFile.getRecordList()[record.getPosition() + i]; 57 | if(!StringUtils.isEmpty(dividendRecord.getDate())) 58 | { 59 | sb = new StringBuilder(); 60 | sb.append("insert into dividend"); 61 | sb.append("(stockcode, date, w1, exdividendDate, cash, split, bonus, dispatch, price, registerDate, listingDate, description) values('"); 62 | sb.append(stockcode); 63 | sb.append((new StringBuilder("','")).append(dividendRecord.getDate()).toString()); 64 | sb.append((new StringBuilder("',")).append(dividendRecord.getM_W1()).toString()); 65 | sb.append((new StringBuilder(",'")).append(dividendRecord.getExdividendDate()).toString()); 66 | sb.append((new StringBuilder("',")).append(dividendRecord.getCash()).toString()); 67 | sb.append((new StringBuilder(",")).append(dividendRecord.getSplit()).toString()); 68 | sb.append((new StringBuilder(",")).append(dividendRecord.getBonus()).toString()); 69 | sb.append((new StringBuilder(",")).append(dividendRecord.getDispatch()).toString()); 70 | sb.append((new StringBuilder(",")).append(dividendRecord.getPrice()).toString()); 71 | sb.append((new StringBuilder(",'")).append(dividendRecord.getRegisterDate()).toString()); 72 | sb.append((new StringBuilder("','")).append(dividendRecord.getListingDate()).toString()); 73 | sb.append((new StringBuilder("','")).append(dividendRecord.getDescription()).append("')").toString()); 74 | sql = sb.toString(); 75 | System.err.println(sql); 76 | st.execute(sql); 77 | } 78 | } 79 | 80 | } 81 | } 82 | 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/Capital.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.InputStreamReader; 7 | import java.sql.DriverManager; 8 | import java.sql.ResultSet; 9 | import java.sql.Statement; 10 | import java.text.DateFormat; 11 | import java.text.SimpleDateFormat; 12 | 13 | import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; 14 | import org.apache.commons.httpclient.HttpClient; 15 | import org.apache.commons.httpclient.HttpException; 16 | import org.apache.commons.httpclient.HttpStatus; 17 | import org.apache.commons.httpclient.methods.GetMethod; 18 | import org.apache.commons.httpclient.params.HttpMethodParams; 19 | import org.apache.commons.lang3.StringUtils; 20 | 21 | /** 22 | * Hello world! 23 | * 24 | */ 25 | public class Capital { 26 | public static void main(String[] args) throws Exception { 27 | 28 | DateFormat dataFormat = new SimpleDateFormat("yyyy-MM-dd"); 29 | 30 | 31 | // Create an instance of HttpClient. 32 | HttpClient client = new HttpClient(); 33 | client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"GBK"); 34 | 35 | String url = "jdbc:jtds:sqlserver://218.28.139.40:4433/stock"; 36 | String driver = "net.sourceforge.jtds.jdbc.Driver"; 37 | java.sql.Connection conn; 38 | 39 | Class.forName(driver); 40 | conn = DriverManager.getConnection(url, "sa", "chrdw,hdhxt."); 41 | Statement st = conn.createStatement(); 42 | Statement updateStatement = conn.createStatement(); 43 | 44 | String sql = "select * from stock where totalcapital is null"; 45 | 46 | ResultSet resultSet = st.executeQuery(sql); 47 | while (resultSet.next()) { 48 | String pkid = resultSet.getString("pkid"); 49 | String stockcode = resultSet.getString("code"); 50 | String stocktype = resultSet.getString("type").toLowerCase(); 51 | 52 | System.err.println("stockcode=" + stockcode); 53 | // Create a method instance. 54 | GetMethod method = new GetMethod( 55 | "http://finance.sina.com.cn/realstock/company/" + stocktype + stockcode + "/nc.shtml"); 56 | 57 | method.addRequestHeader("Content-type", "text/html; charset=utf-8"); 58 | // Provide custom retry handler is necessary 59 | method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 60 | new DefaultHttpMethodRetryHandler(3, false)); 61 | 62 | try { 63 | // 定义一个输入流 64 | InputStream ins = null; 65 | // 定义文件流 66 | BufferedReader br = null; 67 | 68 | // Execute the method. 69 | int statusCode = client.executeMethod(method); 70 | 71 | if (statusCode != HttpStatus.SC_OK) { 72 | System.err.println("Method failed: " 73 | + method.getStatusLine()); 74 | } 75 | 76 | ins = method.getResponseBodyAsStream(); 77 | 78 | // 按服务器编码字符集构建文件流,这里的CHARSET要根据实际情况设置 79 | Boolean firstLine = true; 80 | br = new BufferedReader(new InputStreamReader(ins, method 81 | .getResponseCharSet())); 82 | String line = null; 83 | String totalCapital = "", currentCapital = "", profit = ""; 84 | while ((line = br.readLine()) != null) { 85 | 86 | if (line.contains("var totalcapital")) { 87 | totalCapital = line.substring(line.indexOf("=")+2, line.indexOf(";")); 88 | } 89 | 90 | if (line.contains("var currcapital")) { 91 | currentCapital = line.substring(line.indexOf("=")+2, line.indexOf(";")); 92 | } 93 | 94 | if (line.contains("var curracapital") && currentCapital.equals("0")) { 95 | currentCapital = line.substring(line.indexOf("=")+2, line.indexOf(";")); 96 | } 97 | 98 | if (line.contains("每股收益")) { 99 | line = br.readLine(); 100 | profit = line.substring(line.indexOf("")+4, line.indexOf("元")); 101 | if (StringUtils.isEmpty(profit)) { 102 | line = line.substring(line.indexOf(""), line.length()); 103 | profit = line.substring(line.indexOf("")+4, line.indexOf("元")); 104 | } 105 | } 106 | } 107 | 108 | StringBuilder sb = new StringBuilder(); 109 | 110 | sb.append("update stock set "); 111 | sb.append("totalcapital=" + totalCapital); 112 | sb.append(", currentcapital=" + currentCapital); 113 | sb.append(", profit=" + profit); 114 | sb.append(" where code='" + stockcode + "'"); 115 | sql = sb.toString(); 116 | System.err.println(sql); 117 | updateStatement.execute(sql); 118 | 119 | } catch (HttpException e) { 120 | System.err.println("Fatal protocol violation: " 121 | + e.getMessage()); 122 | e.printStackTrace(); 123 | } catch (IOException e) { 124 | System.err.println("Fatal transport error: " + e.getMessage()); 125 | e.printStackTrace(); 126 | } finally { 127 | // Release the connection. 128 | method.releaseConnection(); 129 | } 130 | } 131 | st.close(); 132 | conn.close(); 133 | 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/NSHistory.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.InputStreamReader; 7 | import java.sql.DriverManager; 8 | import java.sql.ResultSet; 9 | import java.sql.Statement; 10 | import java.text.DateFormat; 11 | import java.text.SimpleDateFormat; 12 | import java.util.ArrayList; 13 | import java.util.Date; 14 | import java.util.HashMap; 15 | import java.util.List; 16 | import java.util.Map; 17 | 18 | import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; 19 | import org.apache.commons.httpclient.HttpClient; 20 | import org.apache.commons.httpclient.HttpException; 21 | import org.apache.commons.httpclient.HttpStatus; 22 | import org.apache.commons.httpclient.methods.GetMethod; 23 | import org.apache.commons.httpclient.params.HttpMethodParams; 24 | 25 | /** 26 | * Hello world! 27 | * 28 | */ 29 | public class NSHistory { 30 | public static void main(String[] args) throws Exception { 31 | 32 | // Create an instance of HttpClient. 33 | HttpClient client = new HttpClient(); 34 | // client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, 35 | // "GBK"); 36 | 37 | String url = "jdbc:jtds:sqlserver://218.28.139.40:4433/stock"; 38 | String driver = "net.sourceforge.jtds.jdbc.Driver"; 39 | java.sql.Connection conn; 40 | 41 | Class.forName(driver); 42 | conn = DriverManager.getConnection(url, "sa", "chrdw,hdhxt."); 43 | Statement st = conn.createStatement(); 44 | Statement stQuery = conn.createStatement(); 45 | Statement updateStatement = conn.createStatement(); 46 | 47 | String sql = "select * from stock"; 48 | 49 | ResultSet resultSet = st.executeQuery(sql); 50 | while (resultSet.next()) { 51 | String pkid = resultSet.getString("pkid"); 52 | String stockcode = resultSet.getString("code"); 53 | String stocktype = resultSet.getString("type").toLowerCase(); 54 | if (stocktype.equals("sh")) { 55 | stocktype = "ss"; 56 | } 57 | 58 | System.err.println("stockcode=" + stockcode); 59 | 60 | 61 | sql = "select top 1 * from day where STOCKCODE='" + stockcode + "'"; 62 | 63 | ResultSet rs = stQuery.executeQuery(sql); 64 | 65 | if (rs.next()) { 66 | continue; 67 | } 68 | 69 | // Create a method instance. 70 | GetMethod method = new GetMethod( 71 | "http://table.finance.yahoo.com/table.csv?s=" + stockcode 72 | + "." + stocktype); 73 | method.addRequestHeader("Content-type", "text/html; charset=utf-8"); 74 | // Provide custom retry handler is necessary 75 | method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 76 | new DefaultHttpMethodRetryHandler(3, false)); 77 | 78 | try { 79 | // 定义一个输入流 80 | InputStream ins = null; 81 | // 定义文件流 82 | BufferedReader br = null; 83 | 84 | // Execute the method. 85 | int statusCode = client.executeMethod(method); 86 | 87 | if (statusCode != HttpStatus.SC_OK) { 88 | System.err.println("Method failed: " 89 | + method.getStatusLine()); 90 | } 91 | 92 | ins = method.getResponseBodyAsStream(); 93 | 94 | // 按服务器编码字符集构建文件流,这里的CHARSET要根据实际情况设置 95 | Boolean firstLine = true; 96 | br = new BufferedReader(new InputStreamReader(ins, method 97 | .getResponseCharSet())); 98 | String line = null; 99 | while ((line = br.readLine()) != null) { 100 | if (line.contains("Not Found")) break; 101 | 102 | if (firstLine) { 103 | firstLine = false; 104 | continue; 105 | } 106 | 107 | 108 | String[] results = line.split(","); 109 | 110 | String tradedate = results[0]; 111 | 112 | 113 | String openprice = results[1]; 114 | String highprice = results[2]; 115 | String lowprice = results[3]; 116 | String closeprice = results[4]; 117 | String volume = results[5]; 118 | 119 | StringBuilder sb = new StringBuilder(); 120 | sb 121 | .append("insert into day(stockcode, openprice, highprice, lowprice, closeprice, volume, tradedate) values('" 122 | + stockcode); 123 | sb.append("'," + openprice); 124 | sb.append("," + highprice); 125 | sb.append("," + lowprice); 126 | sb.append("," + closeprice); 127 | sb.append("," + volume); 128 | sb.append(",'" + tradedate + "')"); 129 | 130 | sql = sb.toString(); 131 | System.err.println(sql); 132 | updateStatement.execute(sql); 133 | } 134 | 135 | } catch (HttpException e) { 136 | System.err.println("Fatal protocol violation: " 137 | + e.getMessage()); 138 | e.printStackTrace(); 139 | } catch (IOException e) { 140 | System.err.println("Fatal transport error: " + e.getMessage()); 141 | e.printStackTrace(); 142 | } finally { 143 | // Release the connection. 144 | method.releaseConnection(); 145 | } 146 | 147 | } 148 | st.close(); 149 | stQuery.close(); 150 | conn.close(); 151 | 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/HalfHour.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import cn.nit.stock.hexin.MN30File; 4 | import cn.nit.stock.hexin.MN30Record; 5 | import cn.nit.stock.indicator.Boll; 6 | import java.io.*; 7 | import java.sql.*; 8 | 9 | public class HalfHour { 10 | private static String loginid = "sunsulian"; 11 | 12 | public HalfHour() { 13 | } 14 | 15 | public static void main(String args[]) throws Exception { 16 | getData(); 17 | addBoll(); 18 | } 19 | 20 | private static void getData() throws ClassNotFoundException, SQLException, 21 | FileNotFoundException { 22 | Connection conn = ConnUtils.getConn(); 23 | Statement st = conn.createStatement(); 24 | Statement statement = conn.createStatement(); 25 | Statement updateStatement = conn.createStatement(); 26 | String sql = "select tradedate from stockaccount where loginid='" 27 | + loginid + "' order by tradedate desc limit 0,1"; 28 | ResultSet resultSet = st.executeQuery(sql); 29 | resultSet.next(); 30 | String chooseDate = resultSet.getString("tradedate"); 31 | resultSet.close(); 32 | sql = "select * from stockaccount where loginid='" + loginid 33 | + "' and tradedate='" + chooseDate + "'"; 34 | 35 | for (resultSet = st.executeQuery(sql); resultSet.next();) { 36 | String stockcode = resultSet.getString("stockcode"); 37 | String type = "sznse"; 38 | if(stockcode.startsWith("6")) 39 | type = "shase"; 40 | RandomAccessFile file = new RandomAccessFile( 41 | new File((new StringBuilder( 42 | "C:\\同花顺软件\\同花顺\\history\\"+ type + "\\min5\\")) 43 | .append(stockcode).append(".mn5").toString()), "r"); 44 | MN30File mn5File = new MN30File(); 45 | MN30File.Read(mn5File, file); 46 | MN30Record amn30record[]; 47 | int j = (amn30record = mn5File.recordList).length; 48 | for (int i = 0; i < j; i++) { 49 | MN30Record record = amn30record[i]; 50 | if (record.getDate() != null) { 51 | sql = (new StringBuilder( 52 | "select * from MN5 where stockcode='")) 53 | .append(stockcode).append("' and tradedate='") 54 | .append(record.getDate()).append("'").toString(); 55 | ResultSet rs = statement.executeQuery(sql); 56 | if (!rs.next()) { 57 | StringBuilder sb = new StringBuilder(); 58 | sb.append("insert into MN5"); 59 | sb.append("(stockcode, open, low, high, close, amount, volume, tradedate) values("); 60 | sb.append((new StringBuilder("'")).append(stockcode) 61 | .toString()); 62 | sb.append((new StringBuilder("',")).append( 63 | record.getOpen()).toString()); 64 | sb.append((new StringBuilder(",")).append( 65 | record.getLow()).toString()); 66 | sb.append((new StringBuilder(",")).append( 67 | record.getHigh()).toString()); 68 | sb.append((new StringBuilder(",")).append( 69 | record.getClose()).toString()); 70 | sb.append((new StringBuilder(",")).append( 71 | record.getAmount()).toString()); 72 | sb.append((new StringBuilder(",")).append( 73 | record.getVolume()).toString()); 74 | sb.append((new StringBuilder(",'")) 75 | .append(record.getDate()).append("')") 76 | .toString()); 77 | sql = sb.toString(); 78 | System.err.println(sql); 79 | updateStatement.execute(sql); 80 | } 81 | } 82 | } 83 | 84 | } 85 | 86 | st.close(); 87 | conn.close(); 88 | } 89 | 90 | private static void addBoll() throws ClassNotFoundException, SQLException { 91 | Connection selectConn = ConnUtils.getConn(); 92 | Statement selectStatement = selectConn.createStatement(); 93 | Statement lineStatement = selectConn.createStatement(); 94 | Statement insertStatement = selectConn.createStatement(); 95 | String sql = "select * from mn5 where boll is null order by tradedate desc"; 96 | for (ResultSet resultSet = selectStatement.executeQuery(sql); resultSet 97 | .next();) { 98 | String stockCode = resultSet.getString("stockcode"); 99 | Double currentPrice = Double.valueOf(resultSet.getDouble("close")); 100 | String tradedate = resultSet.getString("tradedate"); 101 | Double cls[] = new Double[20]; 102 | String ssql = (new StringBuilder( 103 | "select close from mn5 where stockcode='")) 104 | .append(stockCode).append("' and tradedate<='") 105 | .append(tradedate) 106 | .append("' order by tradedate desc limit 20").toString(); 107 | ResultSet rs = lineStatement.executeQuery(ssql); 108 | int i; 109 | for (i = 0; rs.next(); i++) 110 | cls[i] = Double.valueOf(rs.getDouble("close")); 111 | 112 | if (i >= 20) { 113 | Boll boll = new Boll(cls); 114 | System.err 115 | .println((new StringBuilder(String.valueOf(tradedate))) 116 | .append("=").append(boll).toString()); 117 | StringBuilder sb = new StringBuilder(); 118 | sb.append("update mn5 set "); 119 | sb.append((new StringBuilder(" boll=")).append(boll.getBoll()) 120 | .toString()); 121 | sb.append((new StringBuilder(", ub=")).append(boll.getUb()) 122 | .toString()); 123 | sb.append((new StringBuilder(", lb=")).append(boll.getLb()) 124 | .toString()); 125 | sb.append(" where stockcode='").append(stockCode).append("'"); 126 | sb.append(" and tradedate='").append(tradedate).append("'"); 127 | sql = sb.toString(); 128 | insertStatement.execute(sql); 129 | } 130 | } 131 | 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/hexin/DividendRecord.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock.hexin; 2 | 3 | import java.io.IOException; 4 | import java.io.RandomAccessFile; 5 | 6 | public class DividendRecord 7 | { 8 | 9 | public DividendRecord() 10 | { 11 | } 12 | 13 | public static Boolean Read(DividendRecord record, RandomAccessFile file) throws IOException 14 | { 15 | if(file == null) 16 | return Boolean.valueOf(false); 17 | int FValue; 18 | FValue = IntUtils.readInt32(file); 19 | if(FValue == 0) 20 | return Boolean.valueOf(false); 21 | try 22 | { 23 | record.date = (new StringBuilder(String.valueOf(FValue))).toString(); 24 | record.m_W1 = IntUtils.readInt32(file); 25 | FValue = IntUtils.readInt32(file); 26 | if(FValue < 0) 27 | record.exdividendDate = "19010101"; 28 | else 29 | record.exdividendDate = (new StringBuilder(String.valueOf(FValue))).toString(); 30 | record.cash = Double.valueOf(IntUtils.readDouble(file)); 31 | record.split = Double.valueOf(IntUtils.readDouble(file)); 32 | record.bonus = Double.valueOf(IntUtils.readDouble(file)); 33 | record.dispatch = Double.valueOf(IntUtils.readDouble(file)); 34 | record.price = Double.valueOf(IntUtils.readDouble(file)); 35 | FValue = IntUtils.readInt32(file); 36 | if(FValue < 0) 37 | record.registerDate = "19010101"; 38 | else 39 | record.registerDate = (new StringBuilder(String.valueOf(FValue))).toString(); 40 | FValue = IntUtils.readInt32(file); 41 | if(FValue < 0) 42 | record.listingDate = "19010101"; 43 | else 44 | record.listingDate = (new StringBuilder(String.valueOf(FValue))).toString(); 45 | byte FBuffer[] = new byte[242]; 46 | file.read(FBuffer); 47 | int FIndex; 48 | for(FIndex = 0; FIndex < FBuffer.length; FIndex++) 49 | if(FBuffer[FIndex] == 0) 50 | break; 51 | 52 | record.description = new String(FBuffer, 0, FIndex, "GB2312"); 53 | } 54 | catch(IOException e) 55 | { 56 | e.printStackTrace(); 57 | } 58 | return Boolean.valueOf(true); 59 | } 60 | 61 | public static double GetValue(long value) 62 | { 63 | double FValue = value & 0xfffffffL; 64 | byte FSign = (byte)(int)(value >> 28); 65 | if((FSign & 7) != 0) 66 | { 67 | double FFactor = Math.pow(10D, FSign & 7); 68 | if((FSign & 8) != 0) 69 | FValue /= FFactor; 70 | else 71 | FValue *= FFactor; 72 | } 73 | return FValue; 74 | } 75 | 76 | public int getM_W1() 77 | { 78 | return m_W1; 79 | } 80 | 81 | public void setM_W1(int m_W1) 82 | { 83 | this.m_W1 = m_W1; 84 | } 85 | 86 | public Double getCash() 87 | { 88 | return cash; 89 | } 90 | 91 | public void setCash(Double cash) 92 | { 93 | this.cash = cash; 94 | } 95 | 96 | public Double getSplit() 97 | { 98 | return split; 99 | } 100 | 101 | public void setSplit(Double split) 102 | { 103 | this.split = split; 104 | } 105 | 106 | public Double getBonus() 107 | { 108 | return bonus; 109 | } 110 | 111 | public void setBonus(Double bonus) 112 | { 113 | this.bonus = bonus; 114 | } 115 | 116 | public Double getDispatch() 117 | { 118 | return dispatch; 119 | } 120 | 121 | public void setDispatch(Double dispatch) 122 | { 123 | this.dispatch = dispatch; 124 | } 125 | 126 | public Double getPrice() 127 | { 128 | return price; 129 | } 130 | 131 | public void setPrice(Double price) 132 | { 133 | this.price = price; 134 | } 135 | 136 | public String getDescription() 137 | { 138 | return description; 139 | } 140 | 141 | public void setDescription(String description) 142 | { 143 | this.description = description; 144 | } 145 | 146 | public String getDate() 147 | { 148 | return date; 149 | } 150 | 151 | public void setDate(String date) 152 | { 153 | this.date = date; 154 | } 155 | 156 | public String getExdividendDate() 157 | { 158 | return exdividendDate; 159 | } 160 | 161 | public void setExdividendDate(String exdividendDate) 162 | { 163 | this.exdividendDate = exdividendDate; 164 | } 165 | 166 | public String getRegisterDate() 167 | { 168 | return registerDate; 169 | } 170 | 171 | public void setRegisterDate(String registerDate) 172 | { 173 | this.registerDate = registerDate; 174 | } 175 | 176 | public String getListingDate() 177 | { 178 | return listingDate; 179 | } 180 | 181 | public void setListingDate(String listingDate) 182 | { 183 | this.listingDate = listingDate; 184 | } 185 | 186 | public String toString() 187 | { 188 | return (new StringBuilder("DividendRecord [date=")).append(date).append(", m_W1=").append(m_W1).append(", exdividendDate=").append(exdividendDate).append(", cash=").append(cash).append(", split=").append(split).append(", bonus=").append(bonus).append(", dispatch=").append(dispatch).append(", price=").append(price).append(", registerDate=").append(registerDate).append(", listingDate=").append(listingDate).append(", description=").append(description).append("]").toString(); 189 | } 190 | 191 | private String date; 192 | private int m_W1; 193 | private String exdividendDate; 194 | private Double cash; 195 | private Double split; 196 | private Double bonus; 197 | private Double dispatch; 198 | private Double price; 199 | private String registerDate; 200 | private String listingDate; 201 | private String description; 202 | } 203 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/SevenGold.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import java.sql.DriverManager; 4 | import java.sql.ResultSet; 5 | import java.sql.Statement; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import org.apache.commons.lang3.StringUtils; 10 | 11 | /** 12 | * Hello world! 13 | * 14 | */ 15 | public class SevenGold { 16 | public static void main(String[] args) throws Exception { 17 | 18 | List tradeDates = new ArrayList(); 19 | tradeDates.add("2011-01-04"); 20 | tradeDates.add("2011-01-05"); 21 | tradeDates.add("2011-01-06"); 22 | tradeDates.add("2011-01-07"); 23 | 24 | String url = "jdbc:jtds:sqlserver://218.28.139.40:4433/stock"; 25 | String driver = "net.sourceforge.jtds.jdbc.Driver"; 26 | java.sql.Connection conn; 27 | 28 | Class.forName(driver); 29 | conn = DriverManager.getConnection(url, "sa", "chrdw,hdhxt."); 30 | Statement st = conn.createStatement(); 31 | Statement updateStatement = conn.createStatement(); 32 | Statement insertStatement = conn.createStatement(); 33 | 34 | for (String tradeDate : tradeDates) { 35 | 36 | String sql = "select * from stock where profit>0 and currentcapital<=100000"; 37 | 38 | ResultSet resultSet = st.executeQuery(sql); 39 | Integer index = 1; 40 | while (resultSet.next()) { 41 | String pkid = resultSet.getString("pkid"); 42 | String stockcode = resultSet.getString("code"); 43 | String stockName = resultSet.getString("name"); 44 | if (!StringUtils.isEmpty(stockName)) { 45 | if (stockName.toUpperCase().contains("ST")) 46 | continue; 47 | } 48 | 49 | sql = "select top 60 * from day where stockcode='" + stockcode 50 | + "' and tradedate<='" + tradeDate 51 | + "' order by tradedate desc"; 52 | 53 | ResultSet rs = updateStatement.executeQuery(sql); 54 | 55 | List tradeDateList = new ArrayList(); 56 | List lowPriceList = new ArrayList(); 57 | List highPriceList = new ArrayList(); 58 | 59 | Boolean first = true; 60 | Double closePrice = 0d; 61 | while (rs.next()) { 62 | if (first) { 63 | closePrice = rs.getDouble("closeprice"); 64 | first = false; 65 | } 66 | String tradedate = rs.getString("tradedate"); 67 | tradeDateList.add(tradedate); 68 | lowPriceList.add(rs.getDouble("lowprice")); 69 | highPriceList.add(rs.getDouble("highprice")); 70 | } 71 | 72 | if (tradeDateList.size() == 0) 73 | continue; 74 | 75 | Double maxPrice = 0d; 76 | for (Double price : highPriceList) { 77 | if (maxPrice < price) 78 | maxPrice = price; 79 | } 80 | 81 | Double highPrice = 0d; 82 | int highIndex = 0; 83 | 84 | for (int i = 0; i < highPriceList.size(); i++) { 85 | Double currentPrice = highPriceList.get(i); 86 | Boolean flag = true; 87 | try { 88 | for (int j = 1; j <= 5; j++) { 89 | if (currentPrice < highPriceList.get(i + j)) { 90 | flag = false; 91 | break; 92 | } 93 | } 94 | } catch (Exception e) { 95 | flag = false; 96 | } 97 | 98 | if (flag) { 99 | highIndex = i; 100 | highPrice = currentPrice; 101 | break; 102 | } 103 | } 104 | 105 | Double lowPrice = 0d; 106 | int lowIndex = 0; 107 | 108 | for (int i = highIndex; i < lowPriceList.size(); i++) { 109 | Double currentPrice = lowPriceList.get(i); 110 | Boolean flag = true; 111 | try { 112 | for (int j = 1; j <= 5; j++) { 113 | if (currentPrice > lowPriceList.get(i + j)) { 114 | flag = false; 115 | break; 116 | } 117 | } 118 | } catch (Exception e) { 119 | flag = false; 120 | } 121 | 122 | if (flag) { 123 | lowIndex = i; 124 | lowPrice = currentPrice; 125 | break; 126 | } 127 | } 128 | 129 | Double goldPrice = highPrice - (highPrice - lowPrice) * 0.712; 130 | 131 | Double percent = (highPrice - lowPrice) / lowPrice * 100; 132 | 133 | if (highPrice >= maxPrice && closePrice > goldPrice 134 | && closePrice * 0.9 <= goldPrice 135 | && goldPrice > lowPrice && percent > 10) { 136 | 137 | System.err.println("股票代码:" + stockcode + ",交易日:" 138 | + tradeDate); 139 | System.err.println("最高价:" + highPrice); 140 | System.err.println("最低价:" + lowPrice); 141 | System.err.println("收盘价:" + closePrice); 142 | System.err.println("上涨幅度: " + percent + ", 7寸价:" 143 | + goldPrice); 144 | index++; 145 | 146 | StringBuilder sb = new StringBuilder(); 147 | sb 148 | .append("insert into seven(stockcode, stockname, highprice, lowprice, plpercent, sevenprice, matchpercent, tradedate) values('" 149 | + stockcode); 150 | sb.append("','" + stockName); 151 | sb.append("'," + highPrice); 152 | sb.append("," + lowPrice); 153 | sb.append("," + percent); 154 | sb.append("," + goldPrice); 155 | sb 156 | .append("," + (closePrice - goldPrice) / closePrice 157 | * 100); 158 | sb.append(",'" + tradeDateList.get(0) + "')"); 159 | 160 | sql = sb.toString(); 161 | System.err.println(sql); 162 | insertStatement.execute(sql); 163 | } 164 | } 165 | 166 | } 167 | st.close(); 168 | conn.close(); 169 | 170 | //System.err.println("共" + index + "只股票符合七寸战法"); 171 | // Properties props = System.getProperties(); 172 | // props.put("mail.smtp.host", "smtp.139.com"); 173 | // 174 | // Session session = Session.getDefaultInstance(props, null); 175 | // MimeMessage message = new MimeMessage(session); 176 | // message.setFrom(new InternetAddress("13613803575@139.com")); 177 | // message.addRecipient(Message.RecipientType.TO, new InternetAddress( 178 | // "13613803575@139.com")); 179 | // 180 | // DateFormat df = new SimpleDateFormat("yyyy年MM月dd日"); 181 | // Date tradedate = new Date(); 182 | // message.setSubject(df.format(tradedate) + " 跳空涨停提醒:"); 183 | // String content = sb.toString(); 184 | // if (StringUtils.isEmpty(content)) { 185 | // content = "今日没有跳空涨停股票。"; 186 | // } 187 | // message.setText(content); 188 | 189 | // Transport transport = session.getTransport( "smtp" );//指定的协议 190 | // transport.connect("smtp.139.com", "13613803575", "gk790624"); 191 | // transport.sendMessage(message,message.getAllRecipients()); 192 | // transport.close(); 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/DayLimit.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.InputStreamReader; 7 | import java.sql.DriverManager; 8 | import java.sql.ResultSet; 9 | import java.sql.Statement; 10 | import java.text.DateFormat; 11 | import java.text.DecimalFormat; 12 | import java.text.NumberFormat; 13 | import java.text.SimpleDateFormat; 14 | import java.util.Date; 15 | import java.util.Properties; 16 | 17 | import javax.mail.Message; 18 | import javax.mail.Session; 19 | import javax.mail.Transport; 20 | import javax.mail.internet.InternetAddress; 21 | import javax.mail.internet.MimeMessage; 22 | 23 | import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; 24 | import org.apache.commons.httpclient.HttpClient; 25 | import org.apache.commons.httpclient.HttpException; 26 | import org.apache.commons.httpclient.HttpStatus; 27 | import org.apache.commons.httpclient.methods.GetMethod; 28 | import org.apache.commons.httpclient.params.HttpMethodParams; 29 | import org.apache.commons.lang3.StringUtils; 30 | 31 | 32 | /** 33 | * Hello world! 34 | * 35 | */ 36 | public class DayLimit 37 | { 38 | public static void main( String[] args ) throws Exception 39 | { 40 | // Create an instance of HttpClient. 41 | HttpClient client = new HttpClient(); 42 | //client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "GBK"); 43 | 44 | NumberFormat format = new DecimalFormat("#0.00"); 45 | 46 | String url = "jdbc:jtds:sqlserver://218.28.139.40:4433/stock"; 47 | String driver= "net.sourceforge.jtds.jdbc.Driver"; 48 | java.sql.Connection conn; 49 | 50 | Class.forName(driver); 51 | conn = DriverManager.getConnection(url, "sa", "chrdw,hdhxt."); 52 | Statement st = conn.createStatement(); 53 | Statement updateStatement = conn.createStatement(); 54 | 55 | String sql = "select * from stocklimit where statusid='402881e42ee70575012ee7129faf0002'"; 56 | 57 | StringBuilder sb = new StringBuilder(); 58 | Integer index = 1; 59 | ResultSet resultSet = st.executeQuery(sql); 60 | while (resultSet.next()) { 61 | String pkid = resultSet.getString("pkid"); 62 | String stockcode = resultSet.getString("stockcode"); 63 | String stockType = "sh"; 64 | 65 | if (stockcode.startsWith("0")) stockType = "sz"; 66 | // Create a method instance. 67 | GetMethod method = new GetMethod("http://hq.sinajs.cn/list=" + stockType + stockcode); 68 | method.addRequestHeader("Content-type" , "text/html; charset=utf-8"); 69 | // Provide custom retry handler is necessary 70 | method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 71 | new DefaultHttpMethodRetryHandler(3, false)); 72 | 73 | try { 74 | //定义一个输入流 75 | InputStream ins = null; 76 | //定义文件流 77 | BufferedReader br =null; 78 | 79 | // Execute the method. 80 | int statusCode = client.executeMethod(method); 81 | 82 | if (statusCode != HttpStatus.SC_OK) { 83 | System.err.println("Method failed: " + method.getStatusLine()); 84 | } 85 | 86 | ins = method.getResponseBodyAsStream(); 87 | String charset = method.getResponseCharSet(); 88 | if(charset.toUpperCase().equals("ISO-8859-1")){ 89 | charset = "gbk"; 90 | } 91 | //按服务器编码字符集构建文件流,这里的CHARSET要根据实际情况设置 92 | br = new BufferedReader(new InputStreamReader(ins,method.getResponseCharSet())); 93 | StringBuffer sbf = new StringBuffer(); 94 | String line = null; 95 | while ((line = br.readLine()) != null) 96 | { 97 | sbf.append(line); 98 | } 99 | String result = new String(sbf.toString().getBytes(method.getResponseCharSet()),charset); 100 | //输出内容 101 | String[] results = result.split("\""); 102 | results = results[1].split(","); 103 | //System.out.println(stockcode + "=" + results[0]); 104 | String name = results[0].trim(); 105 | if (name.equals("")) continue; 106 | 107 | String openprice = results[1]; 108 | String yesterdayprice = results[2]; 109 | String closeprice = results[3]; 110 | String highprice = results[4]; 111 | String lowprice = results[5]; 112 | String volume = results[8]; 113 | String amount = results[9]; 114 | String tradedate = results[30]; 115 | 116 | if (volume.equals("0")) continue; 117 | 118 | Double yprice = Double.parseDouble(yesterdayprice); 119 | 120 | Double oprice = Double.parseDouble(openprice); 121 | Double percent = (oprice - yprice)/yprice * 100; 122 | 123 | if (percent > 1) { 124 | sb.append(index + ". 代码:" + stockcode + ",名称:" + name + ",高开比例:" + format.format(percent) + "%\r\n"); 125 | } 126 | 127 | } catch (HttpException e) { 128 | System.err.println("Fatal protocol violation: " + e.getMessage()); 129 | e.printStackTrace(); 130 | } catch (IOException e) { 131 | System.err.println("Fatal transport error: " + e.getMessage()); 132 | e.printStackTrace(); 133 | } finally { 134 | // Release the connection. 135 | method.releaseConnection(); 136 | } 137 | //break; 138 | 139 | } 140 | st.close(); 141 | conn.close(); 142 | 143 | Properties props = System.getProperties(); 144 | props.put( "mail.smtp.host" , "smtp.139.com"); 145 | props.put("mail.smtp.auth", "true"); 146 | 147 | Session session = Session.getDefaultInstance(props,null); 148 | MimeMessage message = new MimeMessage(session); 149 | message.setFrom(new InternetAddress("13613803575@139.com")); 150 | message.addRecipient(Message.RecipientType.TO,new InternetAddress("13613803575@139.com")); 151 | 152 | DateFormat df = new SimpleDateFormat("yyyy年MM月dd日"); 153 | Date tradedate = new Date(); 154 | message.setSubject(df.format(tradedate) + " 跳空高开提醒:"); 155 | String content = sb.toString(); 156 | if (StringUtils.isEmpty(content)) { 157 | content = "今日没有跳空涨停股票。"; 158 | } 159 | message.setText(content); 160 | 161 | Transport transport = session.getTransport( "smtp" );//指定的协议 162 | transport.connect("smtp.139.com", "13613803575", "gk790624"); 163 | transport.sendMessage(message,message.getAllRecipients()); 164 | transport.close(); 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/AddStock.java: -------------------------------------------------------------------------------- 1 | // Decompiled by DJ v3.11.11.95 Copyright 2009 Atanas Neshkov Date: 2012/10/24 13:54:58 2 | // Home Page: http://members.fortunecity.com/neshkov/dj.html http://www.neshkov.com/dj.html - Check often for new version! 3 | // Decompiler options: packimports(3) 4 | // Source File Name: AddStock.java 5 | 6 | package cn.nit.stock; 7 | 8 | import java.io.*; 9 | import java.sql.*; 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | import cn.nit.stock.hexin.D1BarRecord; 14 | import cn.nit.stock.model.StockName; 15 | import com.mongodb.DB; 16 | import com.mongodb.DBCollection; 17 | import com.mongodb.MongoClient; 18 | import org.apache.commons.httpclient.*; 19 | import org.apache.commons.httpclient.methods.GetMethod; 20 | import org.apache.commons.httpclient.params.HttpClientParams; 21 | import org.apache.commons.httpclient.params.HttpMethodParams; 22 | import org.mongodb.morphia.Datastore; 23 | import org.springframework.data.mongodb.core.MongoOperations; 24 | import org.springframework.data.mongodb.core.MongoTemplate; 25 | import org.springframework.data.mongodb.core.query.Criteria; 26 | import org.springframework.data.mongodb.core.query.Query; 27 | 28 | // Referenced classes of package cn.nit.stock: 29 | // ConnUtils 30 | 31 | public class AddStock { 32 | 33 | public AddStock() { 34 | } 35 | 36 | public static void main(String args[]) throws Exception { 37 | 38 | Datastore ds = ConnUtils.getDatastore(); 39 | 40 | HttpClient client; 41 | GetMethod method; 42 | 43 | client = new HttpClient(); 44 | client.getParams().setParameter("http.protocol.content-charset", "GBK"); 45 | method = new GetMethod("http://quote.eastmoney.com/stocklist.html"); 46 | method.addRequestHeader("Content-type", "text/html; charset=utf-8"); 47 | method.getParams().setParameter("http.method.retry-handler", 48 | new DefaultHttpMethodRetryHandler(3, false)); 49 | InputStream ins = null; 50 | BufferedReader br = null; 51 | int statusCode = client.executeMethod(method); 52 | if (statusCode != 200) 53 | System.err.println((new StringBuilder("Method failed: ")).append( 54 | method.getStatusLine()).toString()); 55 | ins = method.getResponseBodyAsStream(); 56 | Boolean firstLine = Boolean.valueOf(true); 57 | br = new BufferedReader(new InputStreamReader(ins, 58 | method.getResponseCharSet())); 59 | String line = null; 60 | String totalCapital = ""; 61 | String currentCapital = ""; 62 | String profit = ""; 63 | while ((line = br.readLine()) != null) 64 | if (line.contains("\u4E0A\u6D77\u80A1\u7968")) 65 | break; 66 | br.readLine(); 67 | br.readLine(); 68 | br.readLine(); 69 | while ((line = br.readLine()) != null) { 70 | String words[] = line.split(">"); 71 | if (words.length > 2) { 72 | words = words[2].substring(0, words[2].length() - 3).split( 73 | "\\("); 74 | StockName stockName = new StockName(); 75 | 76 | stockName.setName(words[0]); 77 | stockName.setCode(words[1].substring(0, words[1].length() - 1)); 78 | 79 | 80 | 81 | if (ds.find(StockName.class).field("code").equal(stockName.getCode()).get() == null 82 | && !stockName.getName().toUpperCase().contains("ST") 83 | && !stockName.getCode().startsWith("2") 84 | && !stockName.getCode().startsWith("5") && !stockName.getCode().startsWith("9") 85 | && !stockName.getCode().startsWith("1")) { 86 | 87 | ds.save(stockName); 88 | 89 | System.err.println(stockName); 90 | } 91 | } 92 | br.readLine(); 93 | } 94 | method.releaseConnection(); 95 | 96 | return; 97 | } 98 | 99 | public static void createDatabase(String code) 100 | throws ClassNotFoundException, SQLException { 101 | Connection conn = ConnUtils.getConn(); 102 | String sql = (new StringBuilder("CREATE DATABASE IF NOT EXISTS A")) 103 | .append(code) 104 | .append(" default charset utf8 COLLATE utf8_general_ci") 105 | .toString(); 106 | PreparedStatement pstmt = conn.prepareStatement(sql); 107 | pstmt.execute(); 108 | pstmt = conn.prepareStatement((new StringBuilder("use A")).append(code) 109 | .toString()); 110 | pstmt.execute(); 111 | StringBuilder sb = new StringBuilder(); 112 | sb.append("CREATE TABLE IF NOT EXISTS mn5 ("); 113 | sb.append("PKID int(11) NOT NULL AUTO_INCREMENT,"); 114 | sb.append("STOCKCODE varchar(50) DEFAULT NULL,"); 115 | sb.append("OPEN decimal(10,2) DEFAULT NULL,"); 116 | sb.append("LOW decimal(10,2) DEFAULT NULL,"); 117 | sb.append("HIGH decimal(10,2) DEFAULT NULL,"); 118 | sb.append("CLOSE decimal(10,2) DEFAULT NULL,"); 119 | sb.append("AMOUNT decimal(20,2) DEFAULT NULL,"); 120 | sb.append("VOLUME decimal(20,2) DEFAULT NULL,"); 121 | sb.append("TRADEDATE datetime DEFAULT NULL,"); 122 | sb.append("PRIMARY KEY (PKID)"); 123 | sb.append(") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;"); 124 | sql = sb.toString(); 125 | pstmt = conn.prepareStatement(sql); 126 | pstmt.execute(); 127 | try { 128 | sql = "create index IDX_CODE on MN5 (STOCKCODE);"; 129 | pstmt = conn.prepareStatement(sql); 130 | pstmt.execute(); 131 | sql = "create index IDX_TRADEDATE on MN5 (TRADEDATE);"; 132 | pstmt = conn.prepareStatement(sql); 133 | pstmt.execute(); 134 | } catch (Exception e) { 135 | System.err.println("mn5表已存在"); 136 | } 137 | sb = new StringBuilder(); 138 | sb.append("CREATE TABLE IF NOT EXISTS day ("); 139 | sb.append("PKID int(11) NOT NULL AUTO_INCREMENT,"); 140 | sb.append("STOCKCODE varchar(50) DEFAULT NULL,"); 141 | sb.append("YESTERDAY decimal(10,2) DEFAULT NULL,"); 142 | sb.append("OPEN decimal(10,2) DEFAULT NULL,"); 143 | sb.append("LOW decimal(10,2) DEFAULT NULL,"); 144 | sb.append("HIGH decimal(10,2) DEFAULT NULL,"); 145 | sb.append("CLOSE decimal(10,2) DEFAULT NULL,"); 146 | sb.append("AMOUNT decimal(20,2) DEFAULT NULL,"); 147 | sb.append("VOLUME decimal(20,2) DEFAULT NULL,"); 148 | sb.append("TRADEDATE date DEFAULT NULL,"); 149 | sb.append("PRIMARY KEY (PKID)"); 150 | sb.append(") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;"); 151 | sql = sb.toString(); 152 | pstmt = conn.prepareStatement(sql); 153 | pstmt.execute(); 154 | try { 155 | sql = "create index IDX_CODE on day (STOCKCODE);"; 156 | pstmt = conn.prepareStatement(sql); 157 | pstmt.execute(); 158 | sql = "create index IDX_TRADEDATE on day (TRADEDATE);"; 159 | pstmt = conn.prepareStatement(sql); 160 | pstmt.execute(); 161 | } catch (Exception e) { 162 | System.err.println((new StringBuilder(String.valueOf(code))) 163 | .append("day表已存在").toString()); 164 | } 165 | conn.close(); 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/LimitNotify.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; 4 | import org.apache.commons.httpclient.HttpClient; 5 | import org.apache.commons.httpclient.HttpException; 6 | import org.apache.commons.httpclient.NameValuePair; 7 | import org.apache.commons.httpclient.methods.GetMethod; 8 | import org.apache.commons.io.FileUtils; 9 | 10 | import java.io.*; 11 | import java.sql.Connection; 12 | import java.sql.ResultSet; 13 | import java.sql.SQLException; 14 | import java.sql.Statement; 15 | import java.util.ArrayList; 16 | import java.util.HashMap; 17 | import java.util.List; 18 | import java.util.Map; 19 | 20 | public class LimitNotify 21 | { 22 | 23 | public LimitNotify() 24 | { 25 | } 26 | 27 | private static void buildStockList() 28 | throws ClassNotFoundException, SQLException 29 | { 30 | Connection conn = ConnUtils.getConn("stock"); 31 | Statement st = conn.createStatement(); 32 | String sql = "select * from stock"; 33 | for(ResultSet rs = st.executeQuery(sql); rs.next(); stockList.add(rs.getString("code"))); 34 | sql = "select distinct limitdate from stocklimit order by limitdate desc limit 0, 3"; 35 | 36 | String limitdate = ""; 37 | for(ResultSet rs = st.executeQuery(sql); rs.next(); limitdate = rs.getString("limitdate")); 38 | 39 | sql = "select stockcode, highprice from stocklimit where limitdate >= '" + limitdate + "' order by limitdate desc"; 40 | 41 | for(ResultSet rs = st.executeQuery(sql); rs.next(); limitList.put(rs.getString("stockcode"), rs.getDouble("highprice"))); 42 | st.close(); 43 | conn.close(); 44 | } 45 | 46 | public static void main(String args[]) 47 | throws Exception 48 | { 49 | buildStockList(); 50 | stockConn = ConnUtils.getConn("stock"); 51 | 52 | for (String stockcode : stockList) { 53 | addD1Bar(stockcode); 54 | } 55 | 56 | 57 | FileUtils.writeStringToFile(new File("c:\\new_jyplug\\T0002\\blocknew\\ZTB.blk"), limit.toString()); 58 | System.err.println(limit.toString()); 59 | } 60 | 61 | private static void addD1Bar(String stockcode) 62 | throws ClassNotFoundException, SQLException, HttpException, IOException 63 | { 64 | Connection conn; 65 | HttpClient client; 66 | GetMethod method; 67 | //conn = ConnUtils.getConn((new StringBuilder("a")).append(stockcode).toString()); 68 | client = new HttpClient(); 69 | String stocktype = "sz"; 70 | if(stockcode.startsWith("6")) 71 | stocktype = "sh"; 72 | method = new GetMethod((new StringBuilder("http://hq.sinajs.cn/list=")).append(stocktype).append(stockcode).toString()); 73 | method.addRequestHeader("Content-type", "text/html; charset=utf-8"); 74 | method.getParams().setParameter("http.method.retry-handler", new DefaultHttpMethodRetryHandler(3, false)); 75 | String results[]; 76 | String name; 77 | InputStream ins = null; 78 | BufferedReader br = null; 79 | int statusCode = client.executeMethod(method); 80 | if(statusCode != 200) 81 | System.err.println((new StringBuilder("Method failed: ")).append(method.getStatusLine()).toString()); 82 | ins = method.getResponseBodyAsStream(); 83 | String charset = method.getResponseCharSet(); 84 | if(charset.toUpperCase().equals("ISO-8859-1")) 85 | charset = "gbk"; 86 | br = new BufferedReader(new InputStreamReader(ins, method.getResponseCharSet())); 87 | StringBuffer sbf = new StringBuffer(); 88 | for(String line = null; (line = br.readLine()) != null;) 89 | sbf.append(line); 90 | 91 | String result = new String(sbf.toString().getBytes(method.getResponseCharSet()), charset); 92 | results = result.split("\""); 93 | results = results[1].split(","); 94 | System.out.println((new StringBuilder(String.valueOf(stockcode))).append("=").append(results[0]).toString()); 95 | name = results[0].trim(); 96 | if(name.equals("") || results.length < 2) 97 | { 98 | method.releaseConnection(); 99 | return; 100 | } 101 | String openprice; 102 | String yesterdayprice; 103 | String closeprice; 104 | String highprice; 105 | String lowprice; 106 | String volume; 107 | String amount; 108 | String tradedate; 109 | openprice = results[1]; 110 | yesterdayprice = results[2]; 111 | closeprice = results[3]; 112 | highprice = results[4]; 113 | lowprice = results[5]; 114 | volume = results[8]; 115 | amount = results[9]; 116 | tradedate = results[30]; 117 | if(volume.equals("0")) 118 | { 119 | method.releaseConnection(); 120 | return; 121 | } 122 | 123 | Double yprice = Double.valueOf(Double.parseDouble(yesterdayprice)); 124 | Double closePrice = Double.valueOf(Double.parseDouble(closeprice)); 125 | Double highPrice = Double.valueOf(Double.parseDouble(highprice)); 126 | Double lowPrice = Double.parseDouble(lowprice); 127 | 128 | if(yprice * 1.1 - highPrice < 0.01) 129 | { 130 | Statement limitSt = stockConn.createStatement(); 131 | 132 | String sql = "select * from stocklimit where stockcode='" + stockcode + "' and limitdate='" + tradedate + "'"; 133 | ResultSet rs = limitSt.executeQuery(sql); 134 | 135 | System.err.println((new StringBuilder("股票代码:")).append(stockcode).append(",名称:").append(name).append(",涨停日期:").append(tradedate).toString()); 136 | if (rs.next()) { 137 | System.err.println("已存在"); 138 | } else { 139 | 140 | StringBuilder sb = new StringBuilder(); 141 | sb.append("insert into stocklimit "); 142 | 143 | 144 | sb.append((new StringBuilder("(stockname, stockcode, yesterdayprice, openprice, lowprice, highprice, closeprice, limitdate) values('")).append(name).toString()); 145 | sb.append((new StringBuilder("','")).append(stockcode).toString()); 146 | sb.append((new StringBuilder("',")).append(yprice).toString()); 147 | sb.append((new StringBuilder(",")).append(openprice).toString()); 148 | sb.append((new StringBuilder(",")).append(lowprice).toString()); 149 | sb.append((new StringBuilder(",")).append(highprice).toString()); 150 | sb.append((new StringBuilder(",")).append(closePrice).toString()); 151 | sb.append((new StringBuilder(",'")).append(tradedate).append("')").toString()); 152 | 153 | sql = sb.toString(); 154 | limitSt.execute(sql); 155 | } 156 | } 157 | 158 | if (limitList.containsKey(stockcode)) { 159 | Double yHighPrice = limitList.get(stockcode); 160 | if (yHighPrice * 0.95 - lowPrice > 0.01) { 161 | if (stockcode.startsWith("6")) 162 | limit.append("1" + stockcode + "\r\n"); 163 | else 164 | limit.append("0" + stockcode + "\r\n"); 165 | } 166 | } 167 | } 168 | 169 | private static List stockList = new ArrayList(); 170 | private static Map limitList = new HashMap(); 171 | private static Connection stockConn; 172 | private static StringBuilder limit = new StringBuilder(); 173 | } 174 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/DayFuture.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import cn.nit.stock.hexin.D1BarRecord; 4 | import com.mongodb.DBCollection; 5 | import com.mongodb.DBCursor; 6 | import com.mongodb.DBObject; 7 | import com.mongodb.MongoClient; 8 | import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; 9 | import org.apache.commons.httpclient.HttpClient; 10 | import org.apache.commons.httpclient.HttpException; 11 | import org.apache.commons.httpclient.methods.GetMethod; 12 | import org.apache.commons.lang3.StringUtils; 13 | import org.springframework.data.mongodb.core.MongoOperations; 14 | import org.springframework.data.mongodb.core.MongoTemplate; 15 | import org.springframework.data.mongodb.core.query.Criteria; 16 | import org.springframework.data.mongodb.core.query.Query; 17 | 18 | import java.io.BufferedReader; 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | import java.io.InputStreamReader; 22 | import java.sql.Connection; 23 | import java.sql.ResultSet; 24 | import java.sql.SQLException; 25 | import java.sql.Statement; 26 | import java.util.ArrayList; 27 | import java.util.List; 28 | 29 | public class DayFuture 30 | { 31 | 32 | public DayFuture() 33 | { 34 | } 35 | 36 | public static void main(String args[]) 37 | throws Exception 38 | { 39 | mongoClient = new MongoClient( "115.28.160.121" ); 40 | mongoOps = new MongoTemplate(mongoClient, "future"); 41 | 42 | DBCollection collection = mongoOps.getCollection("Instrument"); 43 | 44 | DBCursor cursor = collection.find(); 45 | try { 46 | while(cursor.hasNext()) { 47 | DBObject object = cursor.next(); 48 | D1BarRecord record = null; 49 | 50 | String instrumentID = object.get("InstrumentID").toString(); 51 | 52 | String code = instrumentID; 53 | 54 | if (!StringUtils.isNumeric(instrumentID.substring(instrumentID.length()-4))) 55 | { 56 | code = instrumentID.substring(0, instrumentID.length() - 3) + "1" + instrumentID.substring(instrumentID.length() - 3); 57 | } 58 | 59 | if (instrumentID.startsWith("IF")) { 60 | code = "CFF_RE_" + instrumentID; 61 | record = addIFD1Bar(code.toUpperCase()); 62 | } 63 | else { 64 | record = addD1Bar(code.toUpperCase()); 65 | } 66 | 67 | if (record == null) continue; 68 | 69 | object.put("Volume", record.getVolume()); 70 | 71 | collection.save(object); 72 | 73 | Query searchUserQuery = new Query(Criteria.where("date").is(record.getDate())); 74 | if (!mongoOps.exists(searchUserQuery, D1BarRecord.class, instrumentID)) { 75 | mongoOps.insert(record, instrumentID); 76 | } else { 77 | System.err.println("已存在"); 78 | } 79 | 80 | 81 | } 82 | } finally { 83 | cursor.close(); 84 | } 85 | } 86 | 87 | private static D1BarRecord addIFD1Bar(String code) 88 | throws ClassNotFoundException, HttpException, IOException 89 | { 90 | Connection conn; 91 | HttpClient client; 92 | GetMethod method; 93 | //conn = ConnUtils.getConn((new StringBuilder("a")).append(stockcode).toString()); 94 | client = new HttpClient(); 95 | String stocktype = "sz"; 96 | method = new GetMethod((new StringBuilder("http://hq.sinajs.cn/list=")).append(code).toString()); 97 | 98 | method.addRequestHeader("Content-type", "text/html; charset=utf-8"); 99 | method.getParams().setParameter("http.method.retry-handler", new DefaultHttpMethodRetryHandler(3, false)); 100 | String results[]; 101 | String name; 102 | InputStream ins = null; 103 | BufferedReader br = null; 104 | int statusCode = client.executeMethod(method); 105 | if(statusCode != 200) 106 | System.err.println((new StringBuilder("Method failed: ")).append(method.getStatusLine()).toString()); 107 | ins = method.getResponseBodyAsStream(); 108 | String charset = method.getResponseCharSet(); 109 | if(charset.toUpperCase().equals("ISO-8859-1")) 110 | charset = "gbk"; 111 | br = new BufferedReader(new InputStreamReader(ins, method.getResponseCharSet())); 112 | StringBuffer sbf = new StringBuffer(); 113 | for(String line = null; (line = br.readLine()) != null;) 114 | sbf.append(line); 115 | 116 | String result = new String(sbf.toString().getBytes(method.getResponseCharSet()), charset); 117 | results = result.split("\""); 118 | results = results[1].split(","); 119 | System.out.println((new StringBuilder(String.valueOf(code))).append("=").append(results[0]).toString()); 120 | name = results[0].trim(); 121 | 122 | 123 | D1BarRecord record = new D1BarRecord(); 124 | 125 | record.setOpen(Double.parseDouble(results[0])); 126 | record.setHigh(Double.parseDouble(results[1])); 127 | record.setLow(Double.parseDouble(results[2])); 128 | record.setClose(Double.parseDouble(results[3])); 129 | record.setVolume(Integer.parseInt(results[4])); 130 | record.setAmount(Double.parseDouble(results[5])); 131 | record.setDate(results[36].replaceAll("-", "")); 132 | 133 | System.err.println(code + ":" +record); 134 | 135 | return record; 136 | } 137 | 138 | private static D1BarRecord addD1Bar(String code) 139 | throws ClassNotFoundException, HttpException, IOException 140 | { 141 | 142 | 143 | Connection conn; 144 | HttpClient client; 145 | GetMethod method; 146 | //conn = ConnUtils.getConn((new StringBuilder("a")).append(stockcode).toString()); 147 | client = new HttpClient(); 148 | 149 | 150 | 151 | 152 | method = new GetMethod((new StringBuilder("http://hq.sinajs.cn/list=")).append(code).toString()); 153 | 154 | method.addRequestHeader("Content-type", "text/html; charset=utf-8"); 155 | method.getParams().setParameter("http.method.retry-handler", new DefaultHttpMethodRetryHandler(3, false)); 156 | String results[]; 157 | String name; 158 | InputStream ins = null; 159 | BufferedReader br = null; 160 | int statusCode = client.executeMethod(method); 161 | if(statusCode != 200) 162 | System.err.println((new StringBuilder("Method failed: ")).append(method.getStatusLine()).toString()); 163 | ins = method.getResponseBodyAsStream(); 164 | String charset = method.getResponseCharSet(); 165 | if(charset.toUpperCase().equals("ISO-8859-1")) 166 | charset = "gbk"; 167 | br = new BufferedReader(new InputStreamReader(ins, method.getResponseCharSet())); 168 | StringBuffer sbf = new StringBuffer(); 169 | for(String line = null; (line = br.readLine()) != null;) 170 | sbf.append(line); 171 | 172 | String result = new String(sbf.toString().getBytes(method.getResponseCharSet()), charset); 173 | results = result.split("\""); 174 | results = results[1].split(","); 175 | System.out.println((new StringBuilder(String.valueOf(code))).append("=").append(results[0]).toString()); 176 | name = results[0].trim(); 177 | if(name.equals("")) 178 | { 179 | System.err.println(code + "不存在"); 180 | method.releaseConnection(); 181 | return null; 182 | } 183 | 184 | D1BarRecord record = new D1BarRecord(); 185 | 186 | record.setOpen(Double.parseDouble(results[2])); 187 | record.setHigh(Double.parseDouble(results[3])); 188 | record.setLow(Double.parseDouble(results[4])); 189 | record.setClose(Double.parseDouble(results[8])); 190 | record.setAmount(Double.parseDouble(results[13])); 191 | record.setVolume(Integer.parseInt(results[14])); 192 | record.setDate(results[17].replaceAll("-", "")); 193 | 194 | System.err.println(code + ":" +record); 195 | 196 | 197 | return record; 198 | } 199 | 200 | private static MongoClient mongoClient ; 201 | private static MongoOperations mongoOps; 202 | 203 | } 204 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/BoardLine.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStream; 5 | import java.io.InputStreamReader; 6 | import java.sql.DriverManager; 7 | import java.sql.ResultSet; 8 | import java.sql.Statement; 9 | import java.text.DateFormat; 10 | import java.text.SimpleDateFormat; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; 15 | import org.apache.commons.httpclient.HttpClient; 16 | import org.apache.commons.httpclient.HttpStatus; 17 | import org.apache.commons.httpclient.methods.GetMethod; 18 | import org.apache.commons.httpclient.params.HttpMethodParams; 19 | import org.apache.commons.lang3.StringUtils; 20 | 21 | /** 22 | * Hello world! 23 | * 24 | */ 25 | public class BoardLine { 26 | public static void main(String[] args) throws Exception { 27 | DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); 28 | 29 | // Create an instance of HttpClient. 30 | HttpClient client = new HttpClient(); 31 | // client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, 32 | // "GBK"); 33 | 34 | String url = "jdbc:jtds:sqlserver://218.28.139.40:4433/stock"; 35 | String driver = "net.sourceforge.jtds.jdbc.Driver"; 36 | java.sql.Connection conn; 37 | 38 | Class.forName(driver); 39 | conn = DriverManager.getConnection(url, "sa", "chrdw,hdhxt."); 40 | Statement stStock = conn.createStatement(); 41 | Statement stBoard = conn.createStatement(); 42 | Statement stDay = conn.createStatement(); 43 | Statement updateStatement = conn.createStatement(); 44 | 45 | String tradeSql = "select tradedate from day where stockcode='1a0001' and tradedate>'2010-01-01' order by tradedate desc"; 46 | 47 | ResultSet rsDay = stDay.executeQuery(tradeSql); 48 | while (rsDay.next()) { 49 | 50 | String tradeDate = df.format(rsDay.getDate("tradedate")); 51 | System.err.println("交易日:" + tradeDate); 52 | String boardURL = "http://vis.10jqka.com.cn/topwin/select/?account=geng_ke&passwd=790624&date=" 53 | + tradeDate; 54 | 55 | Map boardMap = new HashMap(); 56 | String sql = "select * from stockboard"; 57 | 58 | ResultSet resultSet = stBoard.executeQuery(sql); 59 | 60 | while (resultSet.next()) { 61 | Integer boardID = resultSet.getInt("pkid"); 62 | String boardName = resultSet.getString("boardname"); 63 | String boardCode = resultSet.getString("boardcode"); 64 | boardMap.put(boardCode, boardID); 65 | } 66 | 67 | GetMethod method = new GetMethod(boardURL); 68 | method.addRequestHeader("Content-type", "text/html; charset=utf-8"); 69 | // Provide custom retry handler is necessary 70 | method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 71 | new DefaultHttpMethodRetryHandler(3, false)); 72 | 73 | // 定义一个输入流 74 | InputStream ins = null; 75 | // 定义文件流 76 | BufferedReader br = null; 77 | 78 | // Execute the method. 79 | int statusCode = client.executeMethod(method); 80 | 81 | if (statusCode != HttpStatus.SC_OK) { 82 | System.err.println("Method failed: " + method.getStatusLine()); 83 | } 84 | 85 | ins = method.getResponseBodyAsStream(); 86 | String charset = method.getResponseCharSet(); 87 | if (charset.toUpperCase().equals("ISO-8859-1")) { 88 | charset = "gbk"; 89 | } 90 | // 按服务器编码字符集构建文件流,这里的CHARSET要根据实际情况设置 91 | br = new BufferedReader(new InputStreamReader(ins, method 92 | .getResponseCharSet())); 93 | StringBuffer sbf = new StringBuffer(); 94 | String line = null; 95 | while ((line = br.readLine()) != null) { 96 | sbf.append(line); 97 | } 98 | String result = new String(sbf.toString().getBytes( 99 | method.getResponseCharSet()), charset); 100 | // 输出内容 101 | 102 | result = result.substring(result.indexOf("[{")); 103 | result = result.substring(0, result.indexOf("}]")); 104 | String[] boards = result.split("}"); 105 | for (String board : boards) { 106 | board = StringUtils.removeStart(board, ","); 107 | String[] boardfields = board.split(","); 108 | 109 | String bCode = StringUtils.remove(boardfields[0].split(":")[1], 110 | '"'); 111 | // System.err.println(bCode); 112 | 113 | String zjlx = StringUtils.remove(boardfields[2].split(":")[1], 114 | '"'); 115 | // System.err.println(zjlx); 116 | 117 | String jgdlpm1 = StringUtils.remove( 118 | boardfields[3].split(":")[1], '"'); 119 | // System.err.println(jgdlpm1); 120 | String jgdlpm3 = StringUtils.remove( 121 | boardfields[4].split(":")[1], '"'); 122 | // System.err.println(jgdlpm3); 123 | String jgdlpm5 = StringUtils.remove( 124 | boardfields[5].split(":")[1], '"'); 125 | // System.err.println(jgdlpm5); 126 | String jgdlpm10 = StringUtils.remove( 127 | boardfields[6].split(":")[1], '"'); 128 | // System.err.println(jgdlpm10); 129 | 130 | String jgbyb1 = StringUtils.remove( 131 | boardfields[7].split(":")[1], '"'); 132 | // System.err.println(jgbyb1); 133 | String jgbyb3 = StringUtils.remove( 134 | boardfields[8].split(":")[1], '"'); 135 | // System.err.println(jgbyb3); 136 | String jgbyb5 = StringUtils.remove( 137 | boardfields[9].split(":")[1], '"'); 138 | // System.err.println(jgbyb5); 139 | String jgbyb10 = StringUtils.remove( 140 | boardfields[10].split(":")[1], '"'); 141 | // System.err.println(jgbyb10); 142 | 143 | String jjchl1 = StringUtils.remove( 144 | boardfields[11].split(":")[1], '"'); 145 | // System.err.println(jjchl1); 146 | String jjchl3 = StringUtils.remove( 147 | boardfields[12].split(":")[1], '"'); 148 | // System.err.println(jjchl3); 149 | String jjchl5 = StringUtils.remove( 150 | boardfields[13].split(":")[1], '"'); 151 | // System.err.println(jjchl5); 152 | String jjchl10 = StringUtils.remove( 153 | boardfields[14].split(":")[1], '"'); 154 | // System.err.println(jjchl10); 155 | 156 | String ddzpb1 = StringUtils.remove( 157 | boardfields[15].split(":")[1], '"'); 158 | // System.err.println(ddzpb1); 159 | String ddzpb3 = StringUtils.remove( 160 | boardfields[16].split(":")[1], '"'); 161 | // System.err.println(ddzpb3); 162 | String ddzpb5 = StringUtils.remove( 163 | boardfields[17].split(":")[1], '"'); 164 | // System.err.println(ddzpb5); 165 | String ddzpb10 = StringUtils.remove( 166 | boardfields[18].split(":")[1], '"'); 167 | // System.err.println(ddzpb10); 168 | 169 | String pmaqxs = StringUtils.remove( 170 | boardfields[19].split(":")[1], '"'); 171 | // System.err.println(pmaqxs); 172 | 173 | String pmylxs = StringUtils.remove( 174 | boardfields[20].split(":")[1], '"'); 175 | // System.err.println(pmylxs); 176 | 177 | String gjzf1 = StringUtils.remove( 178 | boardfields[21].split(":")[1], '"'); 179 | // System.err.println(gjzf1); 180 | String gjzf3 = StringUtils.remove( 181 | boardfields[22].split(":")[1], '"'); 182 | // System.err.println(gjzf3); 183 | String gjzf5 = StringUtils.remove( 184 | boardfields[23].split(":")[1], '"'); 185 | // System.err.println(gjzf5); 186 | String gjzf10 = StringUtils.remove( 187 | boardfields[24].split(":")[1], '"'); 188 | // System.err.println(gjzf10); 189 | 190 | Integer boardID = boardMap.get(bCode); 191 | 192 | sql = String 193 | .format( 194 | "insert into boardday(boardid, zjlx, jgdlpm1, jgdlpm3, jgdlpm5, jgdlpm10,jgbyb1, jgbyb3, jgbyb5, jgbyb10, jjchl1, jjchl3, jjchl5, jjchl10, ddzpb1, ddzpb3, ddzpb5, ddzpb10, pmaqxs, pmylxs, gjzf1, gjzf3, gjzf5, gjzf10, tradeDate) values(%d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,'%s')", 195 | boardID, zjlx, jgdlpm1, jgdlpm3, jgdlpm5, 196 | jgdlpm10, jgbyb1, jgbyb3, jgbyb5, jgbyb10, 197 | jjchl1, jjchl3, jjchl5, jjchl10, ddzpb1, 198 | ddzpb3, ddzpb5, ddzpb10, pmaqxs, pmylxs, gjzf1, 199 | gjzf3, gjzf5, gjzf10, tradeDate); 200 | 201 | System.err.println(sql); 202 | updateStatement.execute(sql); 203 | } 204 | 205 | // sql = "insert into boardday(boardid,plpercent,tradedate) values(" 206 | // + 207 | // boardID + ", " + pl + ",'" + tradeDate+ "')"; 208 | // System.err.println(sql); 209 | // updateStatement.execute(sql); 210 | 211 | // calendar.add(Calendar.DAY_OF_WEEK, 1); 212 | 213 | Thread.sleep(35 * 1000); 214 | } 215 | 216 | conn.close(); 217 | 218 | } 219 | } 220 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/Analyzer2.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.InputStreamReader; 7 | import java.sql.Connection; 8 | import java.sql.DriverManager; 9 | import java.sql.ResultSet; 10 | import java.sql.SQLException; 11 | import java.sql.Statement; 12 | import java.util.ArrayList; 13 | import java.util.HashMap; 14 | import java.util.List; 15 | import java.util.Map; 16 | import java.util.Date; 17 | import java.util.Calendar; 18 | import java.text.DateFormat; 19 | import java.text.SimpleDateFormat; 20 | 21 | import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; 22 | import org.apache.commons.httpclient.HttpClient; 23 | import org.apache.commons.httpclient.HttpException; 24 | import org.apache.commons.httpclient.HttpStatus; 25 | import org.apache.commons.httpclient.methods.GetMethod; 26 | import org.apache.commons.httpclient.params.HttpMethodParams; 27 | 28 | /** 29 | * Hello world! 30 | * 31 | */ 32 | public class Analyzer2 { 33 | static String url = "jdbc:jtds:sqlserver://218.28.139.40:4433/stock"; 34 | static String driver = "net.sourceforge.jtds.jdbc.Driver"; 35 | 36 | public static void main(String[] args) throws Exception { 37 | analyseBuy(); 38 | // analyseSell(); 39 | 40 | } 41 | 42 | private static void analyseSell() throws ClassNotFoundException, 43 | SQLException { 44 | Connection selectConn, insertConn; 45 | 46 | Class.forName(driver); 47 | selectConn = DriverManager.getConnection(url, "sa", "chrdw,hdhxt."); 48 | insertConn = DriverManager.getConnection(url, "sa", "chrdw,hdhxt."); 49 | Statement selectStatement = selectConn.createStatement(); 50 | Statement lineStatement = selectConn.createStatement(); 51 | Statement insertStatement = insertConn.createStatement(); 52 | 53 | DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); 54 | Date tradedate = new Date(); 55 | String chooseDate = df.format(tradedate); 56 | 57 | String sql = "select * from stockaccount where tradedate='" 58 | + chooseDate + "'"; 59 | ResultSet resultSet = selectStatement.executeQuery(sql); 60 | 61 | Calendar calendar = Calendar.getInstance(); 62 | 63 | if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY) { 64 | calendar.add(Calendar.DAY_OF_WEEK, 3); 65 | } else { 66 | calendar.add(Calendar.DAY_OF_WEEK, 1); 67 | } 68 | 69 | while (resultSet.next()) { 70 | Double avg = 0d; 71 | String stockCode = resultSet.getString("stockcode"); 72 | Double currentPrice = resultSet.getDouble("currentPrice"); 73 | Double plPercent = resultSet.getDouble("plpercent"); 74 | Integer stockUsable = resultSet.getInt("stockremain"); 75 | 76 | String ssql = "select top 99 * from day where stockcode='" 77 | + stockCode + "' and tradedate<='" + chooseDate 78 | + "' order by tradedate desc"; 79 | ResultSet rs = lineStatement.executeQuery(ssql); 80 | while (rs.next()) { 81 | avg += rs.getDouble("closeprice"); 82 | } 83 | avg = avg / 99; 84 | 85 | if (avg > currentPrice) { 86 | avg -= avg * 0.005; 87 | StringBuilder sb = new StringBuilder(); 88 | sb 89 | .append("insert ROBOT(operation, Code, Price, Amount, priority, tradedate) values('SELL', "); 90 | sb.append("'" + stockCode + "', "); 91 | sb.append(avg + ","); 92 | sb.append(stockUsable + ",0,"); 93 | sb.append("'" + df.format(calendar.getTime()) + "')"); 94 | ssql = sb.toString(); 95 | System.err.println(ssql); 96 | insertStatement.execute(ssql); 97 | } 98 | } 99 | } 100 | 101 | private static void analyseBuy() throws ClassNotFoundException, 102 | SQLException { 103 | 104 | Connection selectConn, insertConn; 105 | 106 | Class.forName(driver); 107 | selectConn = DriverManager.getConnection(url, "sa", "chrdw,hdhxt."); 108 | insertConn = DriverManager.getConnection(url, "sa", "chrdw,hdhxt."); 109 | Statement selectStatement = selectConn.createStatement(); 110 | Statement st = selectConn.createStatement(); 111 | Statement lineStatement = selectConn.createStatement(); 112 | Statement insertStatement = insertConn.createStatement(); 113 | 114 | String sql = "select * from stock"; 115 | 116 | DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); 117 | 118 | Date tradedate = new Date(); 119 | 120 | String chooseDate = "2010-10-8"; // df.format(tradedate); 121 | 122 | ResultSet rsStock = selectStatement.executeQuery(sql); 123 | 124 | int count = 1; 125 | while (rsStock.next()) { 126 | System.err.println("分析第"+ count++ + "只股票"); 127 | 128 | String name = rsStock.getString("name"); 129 | if (name == null || name.toUpperCase().contains("ST")) 130 | continue; 131 | 132 | String pkid = rsStock.getString("pkid"); 133 | String stockCode = rsStock.getString("code"); 134 | String stockType = rsStock.getString("type"); 135 | SimpleDateFormat sFormat = new SimpleDateFormat("yyyy-MM-dd"); 136 | 137 | 138 | sql = "select * from day where stockcode='" + stockCode 139 | + "' and tradedate<='"+ chooseDate + "' order by tradedate"; 140 | 141 | ResultSet resultSet = st.executeQuery(sql); 142 | 143 | List tradeDateList = new ArrayList(); 144 | ArrayList priceList = new ArrayList(); 145 | 146 | while (resultSet.next()) { 147 | String stockcode = resultSet.getString("stockcode"); 148 | Double closeprice = resultSet.getDouble("closeprice"); 149 | priceList.add(closeprice); 150 | tradeDateList.add(resultSet.getString("tradedate")); 151 | } 152 | if (priceList.size() == 0) 153 | continue; 154 | 155 | Double[] avgList = new Double[priceList.size()]; 156 | Double[] avg3List = new Double[priceList.size()]; 157 | Double[] avg5List = new Double[priceList.size()]; 158 | Double[] avg21List = new Double[priceList.size()]; 159 | 160 | // System.err.println("首个交易日:" + tradeDateList.get(0)); 161 | 162 | Double maxPL = 0d; 163 | 164 | Map avgMap = new HashMap(); 165 | 166 | for (int i = 3; i <= 21; i++) { 167 | Double[] aList = new Double[priceList.size()]; 168 | 169 | for (int j = i; j < priceList.size(); j++) { 170 | Double currentavg = 0d; 171 | for (int k = j - i + 1; k <= j; k++) { 172 | currentavg += priceList.get(k); 173 | } 174 | aList[j] = currentavg / i; 175 | } 176 | 177 | avgMap.put(i, aList); 178 | } 179 | 180 | avg3List = avgMap.get(3); 181 | avg5List = avgMap.get(5); 182 | avg21List = avgMap.get(21); 183 | 184 | int i = priceList.size() - 1; 185 | Double last3avg = avg3List[i - 1]; 186 | Double last5avg = avg5List[i - 1]; 187 | Double last21avg = avg21List[i - 1]; 188 | 189 | Double current3avg = avg3List[i]; 190 | Double current5avg = avg5List[i]; 191 | Double current21avg = avg21List[i]; 192 | 193 | // if (preavg > avg) continue; //均线向下忽略 194 | 195 | if ((last5avg <= last21avg) && (current5avg > (current21avg+current21avg*0.01)) && current5avg > last5avg) // 符合条件 196 | { 197 | System.err.println("stockcode=" + stockCode); 198 | System.err.print(".昨日收盘价="+priceList.get(i-1) + ",今日收盘价="+priceList.get(i)); 199 | System.err.print("。昨日21日均线:"+last21avg); 200 | System.err.println("。今日21日均线:"+current21avg); 201 | 202 | 203 | StringBuilder sb = new StringBuilder(); 204 | sb 205 | .append("insert BAOHUA(ChooseType, StockCode, Price, Created) values(2,"); 206 | sb.append("'" + stockCode + "', "); 207 | sb.append(priceList.get(i) + ","); 208 | sb.append("'" + chooseDate + "')"); 209 | String ssql = sb.toString(); 210 | System.err.println(ssql); 211 | insertStatement.execute(ssql); 212 | } 213 | } 214 | 215 | sql = "select * from baohua where created = '" + chooseDate + "'"; 216 | 217 | 218 | ResultSet resultSet = selectStatement.executeQuery(sql); 219 | while (resultSet.next()) { 220 | Double price = resultSet.getDouble("price"); 221 | String stockCode = resultSet.getString("stockcode"); 222 | 223 | price += price * 0.005; 224 | if (price > 25) continue; 225 | 226 | int amount = 100; //1手 227 | while (price * amount < 2500) { 228 | amount += 100; 229 | } 230 | 231 | Calendar calendar = Calendar.getInstance(); 232 | 233 | if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY) { 234 | calendar.add(Calendar.DAY_OF_WEEK, 3); 235 | } else { 236 | calendar.add(Calendar.DAY_OF_WEEK, 1); 237 | } 238 | 239 | StringBuilder sb = new StringBuilder(); 240 | sb.append("insert ROBOT(operation, Code, Price, Amount, priority, tradedate) values('BUY', "); 241 | sb.append("'" + stockCode + "', "); 242 | sb.append(price + ","); 243 | sb.append(amount + ",0,"); 244 | sb.append("'" + df.format(calendar.getTime()) + "')"); 245 | String ssql = sb.toString(); 246 | System.err.println(ssql); 247 | insertStatement.execute(ssql); 248 | } 249 | lineStatement.close(); 250 | selectStatement.close(); 251 | insertStatement.close(); 252 | selectConn.close(); 253 | insertConn.close(); 254 | } 255 | } 256 | -------------------------------------------------------------------------------- /analyzer/src/main/java/cn/nit/stock/Analyzer.java: -------------------------------------------------------------------------------- 1 | package cn.nit.stock; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.InputStreamReader; 7 | import java.sql.Connection; 8 | import java.sql.DriverManager; 9 | import java.sql.ResultSet; 10 | import java.sql.SQLException; 11 | import java.sql.Statement; 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | import java.util.Date; 15 | import java.util.Calendar; 16 | import java.text.DateFormat; 17 | import java.text.SimpleDateFormat; 18 | 19 | import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; 20 | import org.apache.commons.httpclient.HttpClient; 21 | import org.apache.commons.httpclient.HttpException; 22 | import org.apache.commons.httpclient.HttpStatus; 23 | import org.apache.commons.httpclient.methods.GetMethod; 24 | import org.apache.commons.httpclient.params.HttpMethodParams; 25 | 26 | 27 | /** 28 | * Hello world! 29 | * 30 | */ 31 | public class Analyzer 32 | { 33 | static String url = "jdbc:jtds:sqlserver://218.28.139.40:4433/stock"; 34 | static String driver= "net.sourceforge.jtds.jdbc.Driver"; 35 | 36 | public static void main( String[] args ) throws Exception 37 | { 38 | analyseBuy(); 39 | //analyseSell(); 40 | 41 | } 42 | 43 | private static void analyseSell() throws ClassNotFoundException, 44 | SQLException { 45 | Connection selectConn, insertConn; 46 | 47 | Class.forName(driver); 48 | selectConn = DriverManager.getConnection(url, "sa", "chrdw,hdhxt."); 49 | insertConn = DriverManager.getConnection(url, "sa", "chrdw,hdhxt."); 50 | Statement selectStatement = selectConn.createStatement(); 51 | Statement lineStatement = selectConn.createStatement(); 52 | Statement insertStatement = insertConn.createStatement(); 53 | 54 | DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); 55 | Date tradedate = new Date(); 56 | String chooseDate = df.format(tradedate); 57 | 58 | String sql = "select * from stockaccount where tradedate='" + chooseDate + "'"; 59 | ResultSet resultSet = selectStatement.executeQuery(sql); 60 | 61 | Calendar calendar = Calendar.getInstance(); 62 | 63 | if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY) { 64 | calendar.add(Calendar.DAY_OF_WEEK, 3); 65 | } else { 66 | calendar.add(Calendar.DAY_OF_WEEK, 1); 67 | } 68 | 69 | while (resultSet.next()) { 70 | Double avg = 0d; 71 | String stockCode = resultSet.getString("stockcode"); 72 | Double currentPrice = resultSet.getDouble("currentPrice"); 73 | Double plPercent = resultSet.getDouble("plpercent"); 74 | Integer stockUsable = resultSet.getInt("stockremain"); 75 | 76 | 77 | String ssql = "select top 99 * from day where stockcode='" + stockCode + "' and tradedate<='" + chooseDate + "' order by tradedate desc"; 78 | ResultSet rs = lineStatement.executeQuery(ssql); 79 | while (rs.next()) { 80 | avg += rs.getDouble("closeprice"); 81 | } 82 | avg = avg / 99; 83 | 84 | if (avg > currentPrice) { 85 | avg -= avg * 0.005; 86 | StringBuilder sb = new StringBuilder(); 87 | sb.append("insert ROBOT(operation, Code, Price, Amount, priority, tradedate) values('SELL', "); 88 | sb.append("'" + stockCode + "', "); 89 | sb.append(avg + ","); 90 | sb.append(stockUsable + ",0,"); 91 | sb.append("'" + df.format(calendar.getTime()) + "')"); 92 | ssql = sb.toString(); 93 | System.err.println(ssql); 94 | insertStatement.execute(ssql); 95 | } 96 | } 97 | } 98 | 99 | private static void analyseBuy() throws ClassNotFoundException, 100 | SQLException { 101 | 102 | Connection selectConn, insertConn; 103 | 104 | Class.forName(driver); 105 | selectConn = DriverManager.getConnection(url, "sa", "chrdw,hdhxt."); 106 | insertConn = DriverManager.getConnection(url, "sa", "chrdw,hdhxt."); 107 | Statement selectStatement = selectConn.createStatement(); 108 | Statement lineStatement = selectConn.createStatement(); 109 | Statement insertStatement = insertConn.createStatement(); 110 | 111 | String sql = "select * from stock"; 112 | 113 | DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); 114 | 115 | Date tradedate = new Date(); 116 | 117 | String chooseDate = "2010-09-01"; //df.format(tradedate); 118 | 119 | ResultSet resultSet = selectStatement.executeQuery(sql); 120 | 121 | while (resultSet.next()) { 122 | Double close=0d,pre=0d,preavg=0d,avg=0d, preavg5 = 0d, avg5 = 0d; 123 | int j = 0; 124 | 125 | String name = resultSet.getString("name"); 126 | if (name == null || name.toUpperCase().contains("ST")) continue; 127 | 128 | String pkid = resultSet.getString("pkid"); 129 | String stockCode = resultSet.getString("code"); 130 | String stockType = resultSet.getString("type"); 131 | SimpleDateFormat sFormat = new SimpleDateFormat("yyyy-MM-dd"); 132 | String ssql = "select top 4 * from day where stockcode='" + stockCode + "' and tradedate<='" + chooseDate + "' order by tradedate desc"; 133 | //System.err.println(ssql); 134 | ResultSet rs = lineStatement.executeQuery(ssql); 135 | if (rs.next()) { 136 | close = rs.getDouble("closeprice"); 137 | pre = rs.getDouble("yesterdayprice"); 138 | String tradeDate = rs.getString("tradedate"); 139 | if (!tradeDate.startsWith(chooseDate)) continue; 140 | //System.err.println("分析"+ stockCode); 141 | Double lastPrice = 0d; 142 | 143 | while (rs.next()) { 144 | lastPrice = rs.getDouble("closeprice"); 145 | 146 | // if (j < 5) { 147 | // preavg5 += lastPrice; 148 | // } 149 | // 150 | // if (j < 4) { 151 | // avg5 += lastPrice; 152 | // } 153 | // 154 | preavg += lastPrice; 155 | j++; 156 | } 157 | 158 | avg5 += close; 159 | //if (preavg5 > avg5) continue; //5日均线向下忽略 160 | 161 | avg = close + preavg - lastPrice; 162 | avg = avg / 3; 163 | preavg = preavg / 3; 164 | } 165 | 166 | 167 | //if (preavg > avg) continue; //均线向下忽略 168 | 169 | if ((pre <= preavg) && (close > avg)) //符合条件 170 | { 171 | StringBuilder sb = new StringBuilder(); 172 | sb.append("收盘价="+close); 173 | sb.append(",昨日收盘价=" + pre); 174 | sb.append(",平均价=" + avg); 175 | sb.append(",昨日平均价=" + preavg); 176 | System.err.println(sb.toString()); 177 | System.err.println("stockcode=" + stockCode); 178 | 179 | sb = new StringBuilder(); 180 | sb.append("insert BAOHUA(ChooseType, StockCode, Price, Created) values(2,"); 181 | sb.append("'" + stockCode + "', "); 182 | sb.append(avg + ","); 183 | sb.append("'" + chooseDate + "')"); 184 | ssql = sb.toString(); 185 | System.err.println(ssql); 186 | //insertStatement.execute(ssql); 187 | } 188 | } 189 | 190 | // sql = "select * from baohua where created = '" + chooseDate + "'"; 191 | // 192 | // 193 | // resultSet = selectStatement.executeQuery(sql); 194 | // while (resultSet.next()) { 195 | // Double price = resultSet.getDouble("price"); 196 | // String stockCode = resultSet.getString("stockcode"); 197 | // 198 | // price += price * 0.005; 199 | // if (price > 25) continue; 200 | // 201 | // int amount = 100; //1手 202 | // while (price * amount < 2500) { 203 | // amount += 100; 204 | // } 205 | // 206 | // Calendar calendar = Calendar.getInstance(); 207 | // 208 | // if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY) { 209 | // calendar.add(Calendar.DAY_OF_WEEK, 3); 210 | // } else { 211 | // calendar.add(Calendar.DAY_OF_WEEK, 1); 212 | // } 213 | // 214 | // StringBuilder sb = new StringBuilder(); 215 | // sb.append("insert ROBOT(operation, Code, Price, Amount, priority, tradedate) values('BUY', "); 216 | // sb.append("'" + stockCode + "', "); 217 | // sb.append(price + ","); 218 | // sb.append(amount + ",0,"); 219 | // sb.append("'" + df.format(calendar.getTime()) + "')"); 220 | // String ssql = sb.toString(); 221 | // System.err.println(ssql); 222 | // insertStatement.execute(ssql); 223 | // } 224 | lineStatement.close(); 225 | selectStatement.close(); 226 | insertStatement.close(); 227 | selectConn.close(); 228 | insertConn.close(); 229 | } 230 | } 231 | --------------------------------------------------------------------------------