Exemplo n.º 1
0
        public void naNValuesInIntervall()
        {
            List <IBar> bars = new List <IBar>();

            for (long i = 0; i <= 10; i++)
            { // (NaN, 1, NaN, 2, NaN, 3, NaN, 4, ...)
                decimal closePrice = i % 2 == 0 ? i : Decimals.NaN;
                IBar    bar        = new BaseBar(DateTime.Now.AddDays(i), Decimals.NaN, Decimals.NaN, Decimals.NaN, Decimals.NaN, Decimals.NaN);
                bars.Add(bar);
            }

            BaseTimeSeries       series      = new BaseTimeSeries("NaN test", bars);
            LowestValueIndicator lowestValue = new LowestValueIndicator(new ClosePriceIndicator(series), 2);

            for (int i = series.GetBeginIndex(); i <= series.GetEndIndex(); i++)
            {
                if (i % 2 != 0)
                {
                    Assert.AreEqual(series.GetBar(i - 1).ClosePrice.ToString(), lowestValue.GetValue(i).ToString());
                }
                else
                {
                    Assert.AreEqual(series.GetBar(Math.Max(0, i - 1)).ClosePrice.ToString(), lowestValue.GetValue(i).ToString());
                }
            }
        }
Exemplo n.º 2
0
        //=====================================================================================================
        //  Menu: File | New...
        //=====================================================================================================
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TimeSeriesCreationDialog timeSeriesCreationDialog = new TimeSeriesCreationDialog();

            timeSeriesCreationDialog.ShowDialog();
            this.timeSeriesGroup = new TimeSeriesGroup();
            BaseTimeSeries timeseries = timeSeriesCreationDialog.TimeSeries;

            timeSeriesGroup.Items.Add(timeseries);
            if (timeseries is TimestampSeries)
            {
                this.timestampSeriesGrid.TimeSeriesData = (TimestampSeries)timeseries;
                this.timespanSeriesGrid.Visible         = false;
                this.timestampSeriesGrid.Visible        = true;
            }
            else if (timeseries is TimespanSeries)
            {
                this.timespanSeriesGrid.TimeSeriesData = (TimespanSeries)timeseries;
                this.timestampSeriesGrid.Visible       = false;
                this.timespanSeriesGrid.Visible        = true;
            }
            this.tsPlot.TimeSeriesDataSet = this.timeSeriesGroup;
            this.tsPlot.Repaint();
            this.tsPlot.Visible = true;
        }
Exemplo n.º 3
0
        public void naNValuesInIntervall()
        {
            List <IBar> bars = new List <IBar>();

            for (long i = 0; i <= 10; i++)
            { // (0, NaN, 2, NaN, 4, NaN, 6, NaN, 8, ...)
                decimal maxPrice = i % 2 == 0 ? i : Decimals.NaN;
                IBar    bar      = new BaseBar(DateTime.Now.AddDays(i), Decimals.NaN, maxPrice, Decimals.NaN, Decimals.NaN, Decimals.NaN);
                bars.Add(bar);
            }
            BaseTimeSeries   series           = new BaseTimeSeries("NaN test", bars);
            AroonUpIndicator aroonUpIndicator = new AroonUpIndicator(series, 5);

            for (int i = series.GetBeginIndex(); i <= series.GetEndIndex(); i++)
            {
                if (i % 2 != 0)
                {
                    Assert.AreEqual(Decimals.NaN, aroonUpIndicator.GetValue(i));
                }
                else
                {
                    Assert.AreEqual(Decimals.HUNDRED, aroonUpIndicator.GetValue(i));
                }
            }
        }
Exemplo n.º 4
0
        /**
         * Gets a TimeSeries from the data section of a mutable Sheet. Data follows
         * a data section header and appears in the first six columns to the end of
         * the file. Empty cells in the data are forbidden.
         *
         * @param sheet mutable Sheet
         * @return TimeSeries of the data
         * @throws DataFormatException if getData throws DataFormatException or if
         *             the data contains empty cells
         */
        private static ITimeSeries GetSeries(ISheet sheet)
        {
            ITimeSeries       series       = new BaseTimeSeries();
            IFormulaEvaluator evaluator    = sheet.Workbook.GetCreationHelper().CreateFormulaEvaluator();
            TimeSpan          weekDuration = new TimeSpan(7, 0, 0, 0);
            List <IRow>       rows         = GetData(sheet);

            // parse the rows from the data section
            foreach (IRow row in rows)
            {
                CellValue[] cellValues = new CellValue[6];
                for (int i = 0; i < 6; i++)
                {
                    // empty cells in the data section are forbidden
                    if (row.GetCell(i) == null)
                    {
                        throw new FormatException("empty cell in xls time series data");
                    }
                    cellValues[i] = evaluator.Evaluate(row.GetCell(i));
                }
                // build a bar from the row and add it to the series
                DateTime weekEndDate = DateUtil.GetJavaDate(cellValues[0].NumberValue);
                IBar     bar         = new BaseBar(weekDuration, weekEndDate,
                                                   // open, high, low, close, volume
                                                   cellValues[1].FormatAsString().ToDecimal(),
                                                   cellValues[2].FormatAsString().ToDecimal(),
                                                   cellValues[3].FormatAsString().ToDecimal(),
                                                   cellValues[4].FormatAsString().ToDecimal(),
                                                   cellValues[5].FormatAsString().ToDecimal());
                series.AddBar(bar);
            }
            return(series);
        }
Exemplo n.º 5
0
        //
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        internal virtual BaseTimeSeries CreateBaseTimeSeries()
        {
            // TODO: Instantiate an appropriate concrete class.
            BaseTimeSeries target = null;

            return(target);
        }
Exemplo n.º 6
0
        public void setUp()
        {
            List <IBar> bars = new List <IBar>();

            // close, volume
            bars.Add(new MockBar(6, 100));
            bars.Add(new MockBar(7, 105));
            bars.Add(new MockBar(9, 130));
            bars.Add(new MockBar(12, 160));
            bars.Add(new MockBar(11, 150));
            bars.Add(new MockBar(10, 130));
            bars.Add(new MockBar(11, 95));
            bars.Add(new MockBar(13, 120));
            bars.Add(new MockBar(15, 180));
            bars.Add(new MockBar(12, 160));
            bars.Add(new MockBar(8, 150));
            bars.Add(new MockBar(4, 200));
            bars.Add(new MockBar(3, 150));
            bars.Add(new MockBar(4, 85));
            bars.Add(new MockBar(3, 70));
            bars.Add(new MockBar(5, 90));
            bars.Add(new MockBar(8, 100));
            bars.Add(new MockBar(9, 95));
            bars.Add(new MockBar(11, 110));
            bars.Add(new MockBar(10, 95));

            ITimeSeries data = new BaseTimeSeries(bars);

            close  = new ClosePriceIndicator(data);
            volume = new VolumeIndicator(data, 2);
        }
Exemplo n.º 7
0
        public void naNValuesInIntervall()
        {
            List <IBar> bars = new List <IBar>();

            for (long i = 0; i <= 10; i++)
            { // (0, NaN, 2, NaN, 3, NaN, 4, NaN, 5, ...)
                decimal closePrice = i % 2 == 0 ? i : Decimals.NaN;
                IBar    bar        = new BaseBar(DateTime.Now.AddDays(i), Decimals.NaN, Decimals.NaN, Decimals.NaN, closePrice, Decimals.NaN);
                bars.Add(bar);
            }

            BaseTimeSeries        series       = new BaseTimeSeries("NaN test", bars);
            HighestValueIndicator highestValue = new HighestValueIndicator(new ClosePriceIndicator(series), 2);

            // index is the biggest of (index, index-1)
            for (int i = series.GetBeginIndex(); i <= series.GetEndIndex(); i++)
            {
                if (i % 2 != 0) // current is NaN take the previous as highest
                {
                    Assert.AreEqual(series.GetBar(i - 1).ClosePrice.ToString(), highestValue.GetValue(i).ToString());
                }
                else // current is not NaN but previous, take the current
                {
                    Assert.AreEqual(series.GetBar(i).ClosePrice.ToString(), highestValue.GetValue(i).ToString());
                }
            }
        }
Exemplo n.º 8
0
        public void naNValuesInIntervall()
        {
            List <IBar> bars = new List <IBar>();

            for (long i = 10; i >= 0; i--)
            { // (10, NaN, 9, NaN, 8, NaN, 7, NaN)
                decimal minPrice = i % 2 == 0 ? i : Decimals.NaN;
                IBar    bar      = new BaseBar(DateTime.Now.AddDays(10 - i), Decimals.NaN, Decimals.NaN, minPrice, Decimals.NaN, Decimals.NaN);
                bars.Add(bar);
            }
            bars.Add(new BaseBar(DateTime.Now.AddDays(11), Decimals.NaN, Decimals.NaN, Decimals.TEN, Decimals.NaN, Decimals.NaN));
            BaseTimeSeries     series             = new BaseTimeSeries("NaN test", bars);
            AroonDownIndicator aroonDownIndicator = new AroonDownIndicator(series, 5);

            for (int i = series.GetBeginIndex(); i <= series.GetEndIndex(); i++)
            {
                if (i % 2 != 0 && i < 11)
                {
                    Assert.AreEqual(Decimals.NaN.ToString(), aroonDownIndicator.GetValue(i).ToString());
                }
                else if (i < 11)
                {
                    Assert.AreEqual(aroonDownIndicator.GetValue(i), Decimals.HUNDRED);
                }
                else
                {
                    Assert.AreEqual(aroonDownIndicator.GetValue(i), 80);
                }
            }
        }
Exemplo n.º 9
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            DateTime     dp                = this.dateTimePicker1.Value;
            DateTime     start             = new DateTime(dp.Year, dp.Month, dp.Day, dp.Hour, dp.Minute, dp.Second);
            string       name              = this.IdTextBox.Text;
            int          timeStepLength    = Convert.ToInt32(this.textBoxTimeStepLength.Text);
            int          numberOfTimesteps = Convert.ToInt32(this.textBoxNumberOfTimeSteps.Text);
            double       defaultValue      = Convert.ToDouble(this.DefaultValueTextBox.Text);
            TimestepUnit timeStepUnit      = new TimestepUnit();


            if (this.comboBoxTimeStepLength.Text == "Years")
            {
                timeStepUnit = TimestepUnit.Years;
            }
            else if (this.comboBoxTimeStepLength.Text == "Months")
            {
                timeStepUnit = TimestepUnit.Months;
            }
            else if (this.comboBoxTimeStepLength.Text == "Days")
            {
                timeStepUnit = TimestepUnit.Days;
            }
            else if (this.comboBoxTimeStepLength.Text == "Hours")
            {
                timeStepUnit = TimestepUnit.Hours;
            }
            else if (this.comboBoxTimeStepLength.Text == "Minutes")
            {
                timeStepUnit = TimestepUnit.Minutes;
            }
            else if (this.comboBoxTimeStepLength.Text == "Seconds")
            {
                timeStepUnit = TimestepUnit.Seconds;
            }
            else
            {
                throw new System.Exception("invalid timestep length unit");
            }

            if (this.timestampBasedRadioButton.Checked)
            {
                timeSeries = new TimestampSeries(name, start, numberOfTimesteps, timeStepLength, timeStepUnit, defaultValue);
            }
            else if (this.timespanBasedRadioButton.Checked)
            {
                timeSeries = new TimespanSeries(name, start, numberOfTimesteps, timeStepLength, timeStepUnit, defaultValue);
            }
            else
            {
                throw new Exception("Unexpected exception in TimeSeriesCreationDialog");
            }

            this.Close();
        }
Exemplo n.º 10
0
        public void getValue()
        {
            DateTime    now  = DateTime.Now;
            List <IBar> bars = new List <IBar>();

            bars.Add(new BaseBar(now, 0M, 62.34M, 61.37M, 62.15M, 7849.025M));
            bars.Add(new BaseBar(now, 0M, 62.05M, 60.69M, 60.81M, 11692.075M));
            bars.Add(new BaseBar(now, 0M, 62.27M, 60.10M, 60.45M, 10575.307M));
            bars.Add(new BaseBar(now, 0M, 60.79M, 58.61M, 59.18M, 13059.128M));
            bars.Add(new BaseBar(now, 0M, 59.93M, 58.71M, 59.24M, 20733.508M));
            bars.Add(new BaseBar(now, 0M, 61.75M, 59.86M, 60.20M, 29630.096M));
            bars.Add(new BaseBar(now, 0M, 60.00M, 57.97M, 58.48M, 17705.294M));
            bars.Add(new BaseBar(now, 0M, 59.00M, 58.02M, 58.24M, 7259.203M));
            bars.Add(new BaseBar(now, 0M, 59.07M, 57.48M, 58.69M, 10474.629M));
            bars.Add(new BaseBar(now, 0M, 59.22M, 58.30M, 58.65M, 5203.714M));
            bars.Add(new BaseBar(now, 0M, 58.75M, 57.83M, 58.47M, 3422.865M));
            bars.Add(new BaseBar(now, 0M, 58.65M, 57.86M, 58.02M, 3962.150M));
            bars.Add(new BaseBar(now, 0M, 58.47M, 57.91M, 58.17M, 4095.905M));
            bars.Add(new BaseBar(now, 0M, 58.25M, 57.83M, 58.07M, 3766.006M));
            bars.Add(new BaseBar(now, 0M, 58.35M, 57.53M, 58.13M, 4239.335M));
            bars.Add(new BaseBar(now, 0M, 59.86M, 58.58M, 58.94M, 8039.979M));
            bars.Add(new BaseBar(now, 0M, 59.53M, 58.30M, 59.10M, 6956.717M));
            bars.Add(new BaseBar(now, 0M, 62.10M, 58.53M, 61.92M, 18171.552M));
            bars.Add(new BaseBar(now, 0M, 62.16M, 59.80M, 61.37M, 22225.894M));

            bars.Add(new BaseBar(now, 0M, 62.67M, 60.93M, 61.68M, 14613.509M));
            bars.Add(new BaseBar(now, 0M, 62.38M, 60.15M, 62.09M, 12319.763M));
            bars.Add(new BaseBar(now, 0M, 63.73M, 62.26M, 62.89M, 15007.690M));
            bars.Add(new BaseBar(now, 0M, 63.85M, 63.00M, 63.53M, 8879.667M));
            bars.Add(new BaseBar(now, 0M, 66.15M, 63.58M, 64.01M, 22693.812M));
            bars.Add(new BaseBar(now, 0M, 65.34M, 64.07M, 64.77M, 10191.814M));
            bars.Add(new BaseBar(now, 0M, 66.48M, 65.20M, 65.22M, 10074.152M));
            bars.Add(new BaseBar(now, 0M, 65.23M, 63.21M, 63.28M, 9411.620M));
            bars.Add(new BaseBar(now, 0M, 63.40M, 61.88M, 62.40M, 10391.690M));
            bars.Add(new BaseBar(now, 0M, 63.18M, 61.11M, 61.55M, 8926.512M));
            bars.Add(new BaseBar(now, 0M, 62.70M, 61.25M, 62.69M, 7459.575M));
            ITimeSeries series = new BaseTimeSeries(bars);

            ChaikinMoneyFlowIndicator cmf = new ChaikinMoneyFlowIndicator(series, 20);

            Assert.AreEqual(cmf.GetValue(0), 0.6082474226804123711340206186M);
            Assert.AreEqual(cmf.GetValue(1), -0.2484311743072140165124562343M);
            Assert.AreEqual(cmf.GetValue(19), -0.12109525344467201822861587M);
            Assert.AreEqual(cmf.GetValue(20), -0.0996934222876103824404821392M);
            Assert.AreEqual(cmf.GetValue(21), -0.065928274226956289145366249M);
            Assert.AreEqual(cmf.GetValue(22), -0.0256877564683178956522684246M);
            Assert.AreEqual(cmf.GetValue(23), -0.0617035928215171828140621566M);
            Assert.AreEqual(cmf.GetValue(24), -0.048105977389585559132748056M);
            Assert.AreEqual(cmf.GetValue(25), -0.0085966816372546350865067276M);
            Assert.AreEqual(cmf.GetValue(26), -0.0087040876420881401439180481M);
            Assert.AreEqual(cmf.GetValue(27), -0.005051500548553229341727545M);
            Assert.AreEqual(cmf.GetValue(28), -0.057409204188786737790197221M);
            Assert.AreEqual(cmf.GetValue(29), -0.0147899751712651882445236589M);
        }
Exemplo n.º 11
0
        private void Summarize(int MaxCount, BaseTimeSeries bts)
        {
            TimespanSeries  tspan = bts as TimespanSeries;
            TimestampSeries tstam = bts as TimestampSeries;

            if (tspan != null)
            {
                if (tspan.Items.Count > MaxCount)
                {
                    List <TimespanValue> temp = new List <TimespanValue>();

                    DateTime Start      = tspan.Items.First().StartTime;
                    DateTime End        = tspan.Items.Last().EndTime;
                    double   periodDays = End.Subtract(Start).TotalDays / MaxCount;

                    for (int i = 0; i < MaxCount; i++)
                    {
                        TimespanValue TValue = new TimespanValue(Start.AddDays(i * periodDays), Start.AddDays((i + 1) * periodDays), 0);
                        TValue.Value = tspan.GetValue(TValue.StartTime, TValue.EndTime);
                        temp.Add(TValue);
                    }
                    tspan.Items.Clear();

                    foreach (var v in temp)
                    {
                        tspan.Items.Add(v);
                    }
                }
            }
            if (tstam != null)
            {
                if (tstam.Items.Count > MaxCount)
                {
                    List <TimestampValue> temp = new List <TimestampValue>();

                    DateTime Start      = tstam.Items.First().Time;
                    DateTime End        = tstam.Items.Last().Time;
                    double   periodDays = End.Subtract(Start).TotalDays / MaxCount;

                    for (int i = 0; i < MaxCount; i++)
                    {
                        TimestampValue TValue = new TimestampValue(Start.AddDays(i * periodDays), 0);
                        TValue.Value = tstam.GetValue(TValue.Time);
                        temp.Add(TValue);
                    }
                    tstam.Items.Clear();

                    foreach (var v in temp)
                    {
                        tstam.Items.Add(v);
                    }
                }
            }
        }
Exemplo n.º 12
0
        public void onlyNaNValues()
        {
            List <IBar> bars = new List <IBar>();

            for (long i = 0; i <= 10000; i++)
            {
                IBar bar = new BaseBar(DateTime.Now.AddDays(i), Decimals.NaN, Decimals.NaN, Decimals.NaN, Decimals.NaN, Decimals.NaN);
                bars.Add(bar);
            }

            BaseTimeSeries       series      = new BaseTimeSeries("NaN test", bars);
            LowestValueIndicator lowestValue = new LowestValueIndicator(new ClosePriceIndicator(series), 5);

            for (int i = series.GetBeginIndex(); i <= series.GetEndIndex(); i++)
            {
                Assert.AreEqual(Decimals.NaN.ToString(), lowestValue.GetValue(i).ToString());
            }
        }
        public TimeSeriesPropertiesDialog(BaseTimeSeries timeSeriesData)
        {
            this.timeSeriesData = timeSeriesData;

            InitializeComponent();


            this.tabControl1.TabPages["tabPageGeneral"].Controls["TextBoxID"].Text          = timeSeriesData.Name;
            this.tabControl1.TabPages["tabPageGeneral"].Controls["textBoxDescription"].Text = timeSeriesData.Description;

            this.tabControl1.TabPages["unitTabPage"].Controls["unitIDTextBox"].Text          = timeSeriesData.Unit.ID;
            this.tabControl1.TabPages["unitTabPage"].Controls["UnitDescriptionTextBox"].Text = timeSeriesData.Unit.Description;
            this.tabControl1.TabPages["unitTabPage"].Controls["ConcersionToSITextBox"].Text  = timeSeriesData.Unit.ConversionFactorToSI.ToString();
            this.tabControl1.TabPages["unitTabPage"].Controls["offSetToSITextBox"].Text      = timeSeriesData.Unit.OffSetToSI.ToString();

            this.tabControl1.TabPages["dimensionTabPage"].Controls["DimensionLengthComboBox"].Text            = timeSeriesData.Unit.Dimension.GetPower(DimensionBase.Length).ToString();
            this.tabControl1.TabPages["dimensionTabPage"].Controls["DimensionMassComboBox"].Text              = timeSeriesData.Unit.Dimension.GetPower(DimensionBase.Mass).ToString();
            this.tabControl1.TabPages["dimensionTabPage"].Controls["DimensionTimeComboBox"].Text              = timeSeriesData.Unit.Dimension.GetPower(DimensionBase.Time).ToString();
            this.tabControl1.TabPages["dimensionTabPage"].Controls["dimensionElectricCurrentComboBox"].Text   = timeSeriesData.Unit.Dimension.GetPower(DimensionBase.ElectricCurrent).ToString();
            this.tabControl1.TabPages["dimensionTabPage"].Controls["DimensionTemeratureComboBox"].Text        = timeSeriesData.Unit.Dimension.GetPower(DimensionBase.Temperature).ToString();
            this.tabControl1.TabPages["dimensionTabPage"].Controls["DimensionAmountOfSubstanceComboBox"].Text = timeSeriesData.Unit.Dimension.GetPower(DimensionBase.AmountOfSubstance).ToString();
            this.tabControl1.TabPages["dimensionTabPage"].Controls["LuminousIntensityComboBox"].Text          = timeSeriesData.Unit.Dimension.GetPower(DimensionBase.LuminousIntensity).ToString();
            this.tabControl1.TabPages["dimensionTabPage"].Controls["DimensionCurrencyComboBox"].Text          = timeSeriesData.Unit.Dimension.GetPower(DimensionBase.Currency).ToString();


            //if (this.timeSeriesData.TimeSeriesType == TimeSeriesType.TimeStampBased)
            //{
            //    ((RadioButton)this.tabControl1.TabPages["tabPageGeneral"].Controls["radioButtonIsTimeStamp"]).Checked = true;
            //    ((RadioButton)this.tabControl1.TabPages["tabPageGeneral"].Controls["radioButtonIsTimeSpan"]).Checked = false;
            //}
            //else
            //{
            //    ((RadioButton)this.tabControl1.TabPages["tabPageGeneral"].Controls["radioButtonIsTimeStamp"]).Checked = false;
            //    ((RadioButton)this.tabControl1.TabPages["tabPageGeneral"].Controls["radioButtonIsTimeSpan"]).Checked = true;
            //}
        }
Exemplo n.º 14
0
 private void OkButton_Click(object sender, EventArgs e)
 {
     selectedTimeSeries = timeSeriesGroup.Items[itemSelectionComboBox.SelectedIndex];
     Close();
 }
Exemplo n.º 15
0
 public SinkSourceBoundary(BaseTimeSeries ts) : this()
 {
     TS = ts;
 }