Esempio n. 1
0
        public void read(string path, FinancialInstrument instr)
        {
            StreamReader file = new StreamReader(path);
            string       line;

            line = file.ReadLine();
            while ((line = file.ReadLine()) != null)
            {
                string[] splitLine = line.Split(',');

                //Преобразование даты и времени
                string   date = splitLine[2], time = splitLine[3];
                DateTime dateTime = new DateTime(
                    Int32.Parse(date.Substring(0, 4)),
                    Int32.Parse(date.Substring(4, 2)),
                    Int32.Parse(date.Substring(6, 2)),
                    Int32.Parse(time.Substring(0, 2)),
                    Int32.Parse(time.Substring(2, 2)),
                    Int32.Parse(time.Substring(4, 2))
                    );

                instr.add_interval(new TradingInterval(
                                       Double.Parse(splitLine[4].Replace('.', ',')),
                                       Double.Parse(splitLine[7].Replace('.', ',')),
                                       Double.Parse(splitLine[6].Replace('.', ',')),
                                       Double.Parse(splitLine[5].Replace('.', ',')),
                                       Double.Parse(splitLine[8].Replace('.', ',')),
                                       dateTime
                                       ));
            }

            file.Close();
            instr.Loaded = true;
        }
Esempio n. 2
0
 public override void update_value(int curIndex, FinancialInstrument instr)
 {
     if (curIndex <= period2)
     {
         add_value(instr.get_interval(curIndex, 0).ClosingPrice);
     }
     else
     {
         double newVal = get_value(curIndex, 0) * period;
         newVal -= instr.get_interval(curIndex, period).ClosingPrice - instr.get_interval(curIndex, period2).OpeningPrice;                //Удаляем старое значение из суммы
         newVal += instr.get_interval(curIndex, 0).ClosingPrice - instr.get_interval(curIndex, 0).OpeningPrice;                           //Добавляем новое значение
         add_value(newVal);
     }
 }
Esempio n. 3
0
        public void accept_new_interval(int curIndex, FinancialInstrument instrument)
        {
            double close = instrument.get_interval(curIndex, 0).ClosingPrice;
            double open  = instrument.get_interval(curIndex, 0).OpeningPrice;

            if (close > open && curDirection == 1)
            {
                curResult++;
            }
            else if (close < open && curDirection == -1)
            {
                curResult++;
            }
            else
            {
                curResult = 0;
            }
            result.Add(curResult);
        }
Esempio n. 4
0
        //Проверка срабатывания условия
        public bool check(int curIndex, FinancialInstrument instr)
        {
            //Обновить индикаторы
            if (indicator1 != null)
            {
                indicator1.update_value(curIndex, instr);
            }

            if (indicator2 != null)
            {
                indicator2.update_value(curIndex, instr);
            }

            double par1 = 0, par2 = 0;

            switch (parameter1)
            {
            case ParameterCondition.Const:
                par1 = const1;
                break;

            case ParameterCondition.PriceClose:
                par1 = instr.get_interval(curIndex, indexOfInterval1).ClosingPrice;
                break;

            case ParameterCondition.PriceOpen:
                par1 = instr.get_interval(curIndex, indexOfInterval1).OpeningPrice;
                break;

            case ParameterCondition.PriceMax:
                par1 = instr.get_interval(curIndex, indexOfInterval1).MaxPrice;
                break;

            case ParameterCondition.PriceMin:
                par1 = instr.get_interval(curIndex, indexOfInterval1).MinPrice;
                break;

            case ParameterCondition.Volume:
                par1 = instr.get_interval(curIndex, indexOfInterval1).Volume;
                break;

            default:                            //Индикатор
                par1 = indicator1.get_value(curIndex, indexOfInterval1);
                break;
            }

            switch (parameter2)
            {
            case ParameterCondition.Const:
                par2 = const2;
                break;

            case ParameterCondition.PriceClose:
                par2 = instr.get_interval(curIndex, indexOfInterval2).ClosingPrice;
                break;

            case ParameterCondition.PriceOpen:
                par2 = instr.get_interval(curIndex, indexOfInterval2).OpeningPrice;
                break;

            case ParameterCondition.PriceMax:
                par2 = instr.get_interval(curIndex, indexOfInterval2).MaxPrice;
                break;

            case ParameterCondition.PriceMin:
                par2 = instr.get_interval(curIndex, indexOfInterval2).MinPrice;
                break;

            case ParameterCondition.Volume:
                par2 = instr.get_interval(curIndex, indexOfInterval2).Volume;
                break;

            default:                            //Индикатор
                par2 = indicator2.get_value(curIndex, indexOfInterval2);
                break;
            }

            switch (predicate)
            {
            case Predicate.Equal:
                return(par1 == par2);

            case Predicate.Less:
                return(par1 < par2);

            case Predicate.LessEqual:
                return(par1 <= par2);

            case Predicate.More:
                return(par1 > par2);

            case Predicate.MoreEqual:
                return(par1 >= par2);
            }
            return(false);
        }
Esempio n. 5
0
 public ForecastingModule(TradingStrategy strategy, FinancialInstrument instrument)
 {
     this.strategy   = strategy;
     this.instrument = instrument;
 }