how to identify turning points in stock price data

前端 未结 4 989
眼角桃花
眼角桃花 2021-01-31 23:19

This question is a continuation of this one.

My goal is to find the turning points in stock price data.

So far I:

Tried differentiating the smoothed pri

4条回答
  •  耶瑟儿~
    2021-02-01 00:03

    That's works Patrick87, Thanks. Following are java function to implement the same:

    Assume StockPrices has a map of key date and value StockPrice (price, average where x = 5)

    private double getCx(StockPrices stockPrices, LocalDate executionDate, int x, double m) { return Math.abs(getFx(stockPrices, executionDate) - getGx(stockPrices, executionDate)) - m * getHx(stockPrices, executionDate, x); }

    private double getGx(StockPrices stockPrices, LocalDate executionDate) {
        return stockPrices.getAvg(executionDate, 5);
    }
    
    private double getFx(StockPrices stockPrices, LocalDate executionDate) {
        return stockPrices.getPrice(executionDate);
    }
    
    public double getHx(StockPrices stockPrice, LocalDate localDate, int x) {
        //standard deviation
        return Math.sqrt(getVariance(stockPrice, localDate, x));
    }
    
    private double getVariance(StockPrices stockPrice, LocalDate localDate, int x) {
        double sum = 0;
        int count = 0;
        for (int i = - (x / 2); i <= (x / 2) ; i++) {
            LocalDate date = localDate.with(BusinessDay.add(localDate, i, stockPrice.getPriceMap(), 2));
            double avg = stockPrice.getAvg(date, 5);
            double price = stockPrice.getPrice(date);
            if (price != 0.0) {
                sum += Math.pow((price - avg), 2);
                count++;
            }
        }
        return sum / count;
    }
    

提交回复
热议问题