zoukankan      html  css  js  c++  java
  • 获取股票的历史数据

       从sina网站上获取,获取下来可以做分析使用,用于搭建自己的交易模型,选取

    符合自己交易系统的股票。

       代码1:

       

    package com.xiaole.stock;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import org.jsoup.Jsoup;
    import org.jsoup.nodes.Document;
    import org.jsoup.nodes.Element;
    import org.jsoup.select.Elements;
    
    public class GetHistoryData {
    
        public static void main(String[] args) {
            String url = "http://money.finance.sina.com.cn/corp/go.php/vMS_MarketHistory/stockid/000952.phtml?year=2014&jidu=3";
            System.out.println(url);
            String msg = HttpService.sendHttpMsg(url, false,"gbk",null);
            Document document = Jsoup.parse(msg);
            Elements stockdatas = document.select("table#FundHoldSharesTable").select("tr");
            for(Element e : stockdatas){
                String time;
                double openPrice;
                double highPrice;
                double endPrice;
                double lowPrice;
                int dealCount;
                int dealAmount;
                Element tmp = e.select("td").select("a").first();
                if(tmp != null){
                    List<String> infoList = new ArrayList<String>();
                    Elements infos = e.select("td");
                    for(Element info : infos){
                        String tmpMsg = info.text();
                        infoList.add(tmpMsg);
                    }
                    HisStockData hisData = new HisStockData();
                    time = infoList.get(0);
                    openPrice = Double.parseDouble(infoList.get(1));
                    highPrice = Double.parseDouble(infoList.get(2));
                    endPrice= Double.parseDouble(infoList.get(3));
                    lowPrice= Double.parseDouble(infoList.get(4));
                    dealCount= Integer.parseInt(infoList.get(5));
                    dealAmount = Integer.parseInt(infoList.get(6));
                    hisData.setTime(time);
                    hisData.setOpenPrice(openPrice);
                    hisData.setHighPrice(highPrice);
                    hisData.setEndPrice(endPrice);
                    hisData.setLowPrice(lowPrice);
                    hisData.setDealAmount(dealAmount);
                    hisData.setDealCount(dealCount);
                    System.out.println(hisData.toString()); 
                }
            }
    
        }
    
    }
    View Code

     代码2:

    package com.xiaole.stock;
    
    public class HisStockData {
        private String time;
        private double openPrice;
        private double highPrice;
        private double endPrice;
        private double lowPrice;
        private int dealCount;
        private int dealAmount;
        public String getTime() {
            return time;
        }
        public void setTime(String time) {
            this.time = time;
        }
        public double getOpenPrice() {
            return openPrice;
        }
        public void setOpenPrice(double openPrice) {
            this.openPrice = openPrice;
        }
        public double getHighPrice() {
            return highPrice;
        }
        public void setHighPrice(double highPrice) {
            this.highPrice = highPrice;
        }
        public double getEndPrice() {
            return endPrice;
        }
        public void setEndPrice(double endPrice) {
            this.endPrice = endPrice;
        }
        public double getLowPrice() {
            return lowPrice;
        }
        public void setLowPrice(double lowPrice) {
            this.lowPrice = lowPrice;
        }
        public int getDealCount() {
            return dealCount;
        }
        public void setDealCount(int dealCount) {
            this.dealCount = dealCount;
        }
        public int getDealAmount() {
            return dealAmount;
        }
        public void setDealAmount(int dealAmount) {
            this.dealAmount = dealAmount;
        }
        @Override
        public String toString() {
            return "HisStockData [time=" + time + ", openPrice=" + openPrice
                    + ", highPrice=" + highPrice + ", endPrice=" + endPrice
                    + ", lowPrice=" + lowPrice + ", dealCount=" + dealCount
                    + ", dealAmount=" + dealAmount + "]";
        }
    }

     代码3:

    if(!stockList.isEmpty()){
                String filePath = "data/stockcode.txt";
                PrintStream ps = null;
                try {
                    ps = new PrintStream(new FileOutputStream(filePath));
                } catch (FileNotFoundException e1) {
                    e1.printStackTrace();
                }
                for(StockItem data : stockList){
                        ps.println(data.getCode() + "	" + data.getName());
                }
                if (null != ps) {
                    ps.close();
                }
            }
    View Code
  • 相关阅读:
    剑指Offer-30.连续子数组的最大和(C++/Java)
    剑指Offer-29.最小的K个数(C++/Java)
    UVA 1616 Caravan Robbers 商队抢劫者(二分)
    UVA 10570 Meeting with Aliens 外星人聚会
    UVA 11093 Just Finish it up 环形跑道 (贪心)
    UVA 12673 Erratic Expansion 奇怪的气球膨胀 (递推)
    UVA 10954 Add All 全部相加 (Huffman编码)
    UVA 714 Copying Books 抄书 (二分)
    UVALive 3523 Knights of the Round Table 圆桌骑士 (无向图点双连通分量)
    codeforecs Gym 100286B Blind Walk
  • 原文地址:https://www.cnblogs.com/cstar/p/3925138.html
Copyright © 2011-2022 走看看