Example usage for org.joda.time Period days

List of usage examples for org.joda.time Period days

Introduction

In this page you can find the example usage for org.joda.time Period days.

Prototype

public static Period days(int days) 

Source Link

Document

Create a period with a specified number of days.

Usage

From source file:org.openvpms.archetype.rules.util.DateUnits.java

License:Open Source License

/**
 * Converts a value in the units to a {@code Period}.
 *
 * @param value the value//  w w  w  . j  a v a 2s.  c o  m
 * @return a new period
 */
public Period toPeriod(int value) {
    switch (this) {
    case MINUTES:
        return Period.minutes(value);
    case HOURS:
        return Period.hours(value);
    case DAYS:
        return Period.days(value);
    case WEEKS:
        return Period.weeks(value);
    case MONTHS:
        return Period.months(value);
    default:
        return Period.years(value);
    }
}

From source file:ta4jexamples.analysis.BuyAndSellSignalsToChart.java

License:Open Source License

public static void main(String[] args) {
    TimeSeries series = new TimeSeries("rb1610", Period.days(1));
    ///*from  w ww  .  jav a  2  s. co  m*/
    OHLCDataService oHLCDataService = (OHLCDataService) SpringUtil.getBean("oHLCDataService");
    List<OHLCData1Day> ls = oHLCDataService.getLatestList(OHLCData1Day.class, "rb1610", 5000);
    for (OHLCData1Day o : ls) {
        series.addTick(new Tick(new DateTime(o.getId()), Decimal.valueOf(o.getOpenPrice()),
                Decimal.valueOf(o.getHighPrice()), Decimal.valueOf(o.getLowPrice()),
                Decimal.valueOf(o.getClosePrice()), Decimal.valueOf(o.getVolume())));
    }
    // Getting the time series
    // Building the trading strategy
    Strategy strategy = KLineShapeStrategy.buildStrategy(series);

    /**
     * Building chart datasets
     */
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(buildChartTimeSeries(series, new ClosePriceIndicator(series), "Bitstamp Bitcoin (BTC)"));

    /**
     * Creating the chart
     */
    JFreeChart chart = ChartFactory.createTimeSeriesChart("Bitstamp BTC", // title
            "Date", // x-axis label
            "Price", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );
    XYPlot plot = (XYPlot) chart.getPlot();
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MM-dd HH:mm"));

    /**
     * Running the strategy and adding the buy and sell signals to plot
     */
    addBuySellSignals(series, strategy, plot);

    /**
     * Displaying the chart
     */
    displayChart(chart);
}