Пример #1
0
 public float GetValor(Formula f)
 {
     if (!valores.ContainsKey(f.GetCode()))
     {
         float calc = f.Calc(this);
         SetValor(f, calc);
         return(calc);
     }
     return(valores[f.GetCode()]);
 }
Пример #2
0
        public void TestTradeSystem()
        {
            facade = new FacadeBacktester();
            Config      config      = new Config();
            TradeSystem tradeSystem = new TradeSystem(config);
            MonteCarlo  mc          = new MonteCarlo("teste");

            float    valorInicial = 100000;
            Carteira carteira     = new Carteira(facade, valorInicial, config, tradeSystem, mc);

            config.custoOperacao = 20f;

            tradeSystem.condicaoEntradaC = "GREATER(MME(C,9),MME(C,3))";
            tradeSystem.condicaoSaidaC   = "LOWER(MME(C,9),MME(C,3))";
            tradeSystem.condicaoEntradaV = "LOWER(MME(C,9),MME(C,3))";

            Periodo periodo = new Periodo("01-01-2017");
            Ativo   ativo   = new Ativo(facade, "TESTE", 100);
            Candle  candle  = new Candle(periodo, ativo);

            ativo.firstCandle = candle;
            candle.SetValor("MME(C,9)", 10);
            candle.SetValor("MME(C,3)", 5);
            candle.SetValor("SUBTRACT(L,MULTIPLY(STD(C,10),2))", 2);
            candle.SetValor("H", 10);
            candle.SetValor(tradeSystem.stopInicialC, 5);

            Formula formulaGreater = facade.formulaManager.GetFormula(tradeSystem.condicaoEntradaC);
            float   value          = formulaGreater.Calc(candle);

            Assert.IsTrue(value > 0, value + "<=0");

            Formula formulaLower = facade.formulaManager.GetFormula(tradeSystem.condicaoEntradaV);

            value = formulaLower.Calc(candle);
            Assert.IsTrue(value == 0, value + ">0");

            float result = tradeSystem.checaCondicaoEntrada(candle, config);

            Assert.IsTrue(result > 0, "result:" + result);

            candle.SetValor("MME(C,9)", 2);
            candle.SetValor("C", 2);
            candle.RemoveValor(tradeSystem.condicaoEntradaC);

            result = tradeSystem.checaCondicaoEntrada(candle, config);
            Assert.IsTrue(result == 0, "result:" + result);
        }
Пример #3
0
        public float GetValor(string name)
        {
            if (valores.ContainsKey(name))
            {
                return(valores[name]);
            }
            Formula f = ativo.facade.formulaManager.GetFormula(name);

            if (valores.ContainsKey(name))
            {
                return(valores[name]);
            }
            float calc = f.Calc(this);

            SetValor(name, calc);
            return(calc);
        }
Пример #4
0
        public List <PointD> GeneratePoints(ref int FuncNumber)
        {
            List <PointD> Result = new List <PointD>((int)udPointsCount.Value);

            //DoubleFunc AccurateFunc = GetFunc(cmbFunc.SelectedIndex);

            formula = new Formula(cmbFunc.Text);
            double XL = Convert.ToDouble(tbXL.Text);
            double XR = Convert.ToDouble(tbXR.Text);
            double h  = (XR - XL) / (double)(udPointsCount.Value - 1);
            double x  = XL;

            for (int i = 0; i < udPointsCount.Value; i++)
            {
                Result.Add(new PointD(x, formula.Calc(x)));
                x += h;
            }

            return(Result);
        }
Пример #5
0
        static void Main(string[] args)
        {
            /*
             *  // debug
             *  straight func time: 7,900974 sec
             *  static func time:   10,49656 sec
             *  dynamic func time: 11,75082 sec
             *
             *  straight func time: 7,908769 sec
             *  static func time:   9,859972 sec
             *  dynamic func time: 10,90511 sec
             *
             *  straight func time: 7,898407 sec
             *  static func time:   10,48148 sec
             *  dynamic func time: 11,72088 sec
             *
             *
             *  // release
             *  straight func time: 8,883073 sec
             *  static func time:   9,085726 sec
             *  dynamic func time: 9,893035 sec
             *
             *  straight func time: 8,867755 sec
             *  static func time:   9,073434 sec
             *  dynamic func time: 9,919697 sec
             *
             *  straight func time: 8,320682 sec
             *  static func time:   9,591556 sec
             *  dynamic func time: 10,24124 sec
             */

            Console.WriteLine("Write any key.... ");
            Console.Read();

            Thread.CurrentThread.Priority = ThreadPriority.Highest;
            Process CurProcess = Process.GetCurrentProcess();

            CurProcess.PriorityClass = ProcessPriorityClass.RealTime;

            uint N = 100000000;

            double  X;
            Formula F = new Formula("Cos(X) + Sin(X) - X");
            int     i;

            X = 0;
            PerfCounter perfCount = new PerfCounter();

            /*while (true)
             * {
             *  F = new Formula("Cos(X) + Sin(X) - X");
             *  Console.WriteLine("F created");
             *  Console.ReadKey();
             * }*/

            perfCount.Start();
            for (i = 0; i < N; i++)
            {
                X = Math.Cos(X) + Math.Sin(X) - X;
            }
            Console.WriteLine("straight func time: " + perfCount.Finish().ToString() + " sec");

            perfCount.Start();
            for (i = 0; i < N; i++)
            {
                X = StatCalc(X);
            }
            Console.WriteLine("static func time:   " + perfCount.Finish().ToString() + " sec");

            perfCount.Start();
            for (i = 0; i < N; i++)
            {
                X = F.Calc(X);
            }
            Console.WriteLine("dynamic func time: " + perfCount.Finish().ToString() + " sec");

            Console.WriteLine("Calculating done.... ");

            Thread.CurrentThread.Priority = ThreadPriority.Normal;
            CurProcess.PriorityClass      = ProcessPriorityClass.Normal;

            Console.ReadKey();
        }
Пример #6
0
 public double Formula_Calc(int x, int y, int z)
 {
     return(Formula.Calc(x, y, z));
 }