Example #1
0
 public void AddSymbol(Symbol symbol)
 {
     if (!Symbols.Contains(symbol))
     {
         Symbols.Add(symbol);
     }
 }
Example #2
0
        public void Can_Define_Vars()
        {
            var syms = new Symbols();

            syms.DefineVariable("a");
            syms.DefineVariable("c");
            syms.Global.DefineFunction(SymbolTestsHelper.ToFunction("add", 2, new string[] { "a", "b" }, LTypes.Object));
            syms.Push(new SymbolsFunction("add"), true);
            syms.DefineVariable("d");

            Assert.IsFalse(syms.Global.Contains("d"));
            Assert.IsTrue(syms.Current.Contains("d"));
            Assert.IsTrue(syms.Contains("d"));
            Assert.IsTrue(syms.Global.Contains("a"));
            Assert.IsTrue(syms.Contains("a"));
        }
Example #3
0
        public void Can_Have_Block_Inside_Function()
        {
            var syms = new Symbols();

            syms.DefineVariable("a");
            syms.Global.DefineFunction(SymbolTestsHelper.ToFunction("add", 2, new string[] { "a", "b" }, LTypes.Object));

            // func
            var sf = new SymbolsFunction("add", syms.Global);

            syms.Push(sf, true);

            // block in func
            var sb = new SymbolsNested("block", sf);

            syms.Push(sb, true);

            // put variable c in block in function
            syms.DefineVariable("c");

            Assert.IsFalse(syms.Global.Contains("c"));
            Assert.IsFalse(sf.Contains("c"));
            Assert.IsTrue(sb.Contains("c"));
            Assert.IsTrue(syms.Contains("c"));
            Assert.IsTrue(syms.Current.Contains("c"));
        }
Example #4
0
        protected void ProcessIFDirective(Directive directive)
        {
            string symbol = directive.Parameters[0].ToUpperInvariant();

            if (String.IsNullOrEmpty(symbol))
            {
                ThrowProcessingError("Invalid #IF parameter");
            }

            // Process IF
            bool activeDebug   = false;
            bool activeRelease = false;

            switch (symbol)
            {
            case "DEBUG":
                activeDebug   = true;
                activeRelease = false;
                break;

            case "RELEASE":
                activeDebug   = false;
                activeRelease = true;
                break;

            default:
                activeDebug = activeRelease = Symbols.Contains(symbol, StringComparer.OrdinalIgnoreCase);
                break;
            }
            _directiveFrames.Add(new DirectiveFrame {
                Directive = directive, ActiveDebug = activeDebug, ActiveRelease = activeRelease
            });
        }
Example #5
0
        public bool IsQuestionMark()
        {
            if (Symbols.Contains("?"))
            {
                return(true);
            }

            return(false);
        }
Example #6
0
 private bool InputContainsNotDefinedSymbols(string input)
 {
     foreach (char symbol in input.Where(c => !Symbols.Contains(c)))
     {
         Log += ConsoleWriter.Failure("Could not accept the input since the symbol " + symbol +
                                      " is not part of the alphabet") + "\n";
         return(true);
     }
     return(false);
 }
Example #7
0
        static IEnumerable <string> ParseLine(string Line)
        {
            ParseBuilder.Length = 0;
            //Line = Line.Replace("=", " = ").Replace(";", " ; ").Replace("\r", "").Replace("\n", "");
            bool InsideQuote = false;

            const string Symbols     = "+-=;";
            const string SkipSymbols = " ,";

            char LastChr = (char)0;

            foreach (var Chr in Line)
            {
                if (!InsideQuote && SkipSymbols.Contains(Chr))
                {
                    if (ParseBuilder.Length > 0)
                    {
                        yield return(ParseBuilder.ToString());

                        ParseBuilder.Length = 0;
                    }
                }
                else if (!InsideQuote && Symbols.Contains(Chr))
                {
                    if (ParseBuilder.Length > 0)
                    {
                        yield return(ParseBuilder.ToString());

                        ParseBuilder.Length = 0;
                    }

                    yield return(Chr.ToString());
                }
                else if (Chr == '"' && LastChr != '\\')
                {
                    InsideQuote = !InsideQuote;
                }
                else if (Chr == '"' && LastChr == '\\')
                {
                    ParseBuilder.Length--;
                    ParseBuilder.Append('"');
                }
                else
                {
                    ParseBuilder.Append(Chr);
                }

                LastChr = Chr;
            }

            if (ParseBuilder.Length > 0)
            {
                yield return(ParseBuilder.ToString());
            }
        }
Example #8
0
 public void AddStatement(Sentence sentence)
 {
     Sentences.Add(sentence);
     foreach (string l in sentence.Symbols)
     {
         if (!Symbols.Contains(l) && l != "")
         {
             Symbols.Add(l);
         }
     }
 }
Example #9
0
        public override NLPTokenTypes IdentifySymbol(NLPLexicalContext state)
        {
            var symbol = state.CurrentSymbol.ToLower();

            if (Symbols.Contains(symbol))
            {
                return(NLPTokenTypes.Identifier);
            }

            return(NLPTokenTypes.Unknown);
        }
Example #10
0
        private Int16 ConvertACmd(string item)
        {
            if (Parser.IsVariable(item))
            {
                if (!Symbols.Contains(item.Substring(1)))
                {
                    Symbols.AddEntry(item.Substring(1), variableBaseAddress);
                    variableBaseAddress++;
                }

                return(Convert.ToInt16(Symbols.GetAddress(item.Substring(1))));
            }

            string address = item.Substring(1);

            return(Convert.ToInt16(address));
        }
            /// <summary>
            ///
            /// </summary>
            private void LoadFile()
            {
                var path = Path.Combine(Path.GetDirectoryName(MainForm.Instance.FilePath), FileName);

                if (!System.IO.File.Exists(path))
                {
                    path = FileIO.OpenFile(ApplicationSettings.HSDFileFilter, FileName);
                }

                if (path != null)
                {
                    var file = new HSDRawFile(path);

                    if (file.Roots.Find(s => Symbols.Contains(s.Name)) != null)
                    {
                        File                 = file;
                        FilePath             = path;
                        LoadedLabel.Image    = Properties.Resources.ts_check;
                        ImportButton.Visible = false;

                        OnFileLoaded.Invoke(this, null);
                    }
                }
            }
Example #12
0
 public bool IsQuestionMark()
 {
     return(Symbols.Contains("?"));
 }
Example #13
0
        private void ProcessTrade(TradeResult tr, Position pos, decimal pospl)
        {
            //Compare to prevpos
            bool initial = false;

            if (_prevPos == null)
            {
                _prevPos = pos;
                initial  = true;
            }

            if (_tradecount.ContainsKey(tr.Source.Symbol))
            {
                _tradecount[tr.Source.Symbol]++;
            }
            else
            {
                _tradecount.Add(tr.Source.Symbol, 1);
            }
            if (!_days.Contains(tr.Source.Xdate))
            {
                _days.Add(tr.Source.Xdate);
            }

            int usizebefore = _prevPos.UnsignedSize;
            var miubefore   = _prevPos.IsFlat ? 0 : _prevPos.UnsignedSize * _prevPos.AvgPrice;

            //Use new position from here
            bool isroundturn = (usizebefore > 0) && pospl != 0 && !initial && (pos.Direction != _prevPos.Direction);

            // get comissions
            Commissions += tr.Commission;

            // calculate MIU and store on array
            var miu = pos.IsFlat ? 0 : pos.AvgPrice * pos.UnsignedSize;

            if (miu != 0)
            {
                _miu.Add(miu);
            }

            // if we closed something, update return
            decimal grosspl = pospl;
            decimal netpl   = grosspl - tr.Commission;

            // count return
            _grossreturn.Add(grosspl);
            _netreturns.Add(netpl);
            // get pct return for portfolio
            decimal pctret;

            if (miubefore == 0)
            {
                pctret = netpl / miu;
            }
            else
            {
                pctret = netpl / miubefore;
            }
            _pctrets.Add(pctret);

            //adjust initial capital based balance
            decimal portfolioreturn = netpl / Balance;

            _portfPctreturns.Add(portfolioreturn);

            // add to neg returns if negative
            if (portfolioreturn < 0)
            {
                _portfNegpctreturns.Add(portfolioreturn);
            }

            // adjust current balance
            Balance += netpl;

            // if it is below our zero, count it as negative return
            if (pctret < 0)
            {
                _negret.Add(pctret);
            }

            if (isroundturn)
            {
                RoundTurns++;
                if (pospl >= 0)
                {
                    RoundWinners++;
                }
                else if (pospl < 0)
                {
                    RoundLosers++;
                }
            }

            if (!Symbols.Contains(tr.Source.Symbol))
            {
                Symbols += tr.Source.Symbol + ",";
                SymbolCount++;
            }
            Trades++;
            SharesTraded += Math.Abs(tr.Source.Xsize / tr.Source.Security.LotSize);
            GrossPL      += tr.ClosedPl;

            if ((tr.ClosedPl > 0) && !_exitscounted.Contains(tr.Source.Id))
            {
                if (tr.Source.Direction == Direction.Long)
                {
                    SellWins++;
                    SellPL += tr.ClosedPl;
                }
                else
                {
                    BuyWins++;
                    BuyPL += tr.ClosedPl;
                }
                if (tr.Source.Id != 0)
                {
                    _exitscounted.Add(tr.Id);
                }
                Winners++;
                _consecWinners++;
                _consecLosers = 0;
            }
            else if ((tr.ClosedPl < 0) && !_exitscounted.Contains(tr.Source.Id))
            {
                if (tr.Source.Direction == Direction.Long)
                {
                    SellLosers++;
                    SellPL += tr.ClosedPl;
                }
                else
                {
                    BuyLosers++;
                    BuyPL += tr.ClosedPl;
                }
                if (tr.Source.Id != 0)
                {
                    _exitscounted.Add(tr.Id);
                }
                Losers++;
                _consecLosers++;
                _consecWinners = 0;
            }
            if (tr.ClosedPl > 0)
            {
                _winpnl += tr.ClosedPl;
            }
            else if (tr.ClosedPl < 0)
            {
                _losepnl += tr.ClosedPl;
            }

            if (_consecWinners > ConsecWin)
            {
                ConsecWin = _consecWinners;
            }
            if (_consecLosers > ConsecLose)
            {
                ConsecLose = _consecLosers;
            }
            if ((tr.OpenSize == 0) && (tr.ClosedPl == 0))
            {
                Flats++;
            }
            if (tr.ClosedPl > MaxWin)
            {
                MaxWin = tr.ClosedPl;
            }
            if (tr.ClosedPl < MaxLoss)
            {
                MaxLoss = tr.ClosedPl;
            }
            if (tr.OpenPl > MaxOpenWin)
            {
                MaxOpenWin = tr.OpenPl;
            }
            if (tr.OpenPl < MaxOpenLoss)
            {
                MaxOpenLoss = tr.OpenPl;
            }

            //set prev position
            _prevPos = pos;
        }