public void TransformerTest2() { string exampleCode = @" global variables{ define reEntryExRatePercent as 0.05; define noOfLongPosition as 3; define noOfShortPosition as 3; } define Portfolio{ set BaseCurrency to 'EUR'; LongPositions: Position<Long>[3]; } rule reallocation executes on every Friday{ for all position in Portfolio.LongPositions{ if position.Currency is not in Top3Currencies: Close position; } for all currency in Top3Currencies{ if currency is not in Currency of Portfolio.LongPositions: Open Portfolio.LongPositions with currency; } }"; StrategyLanguageParser fxParser = new StrategyLanguageParser(); TradingStrategyAstNode strategyAst = fxParser.Parse(exampleCode); AstTreeToModelTransformer transformer = new AstTreeToModelTransformer(); TradingStrategy strategy = transformer.Transform(strategyAst); //Assert.IsTrue(strategy.TradingRules.Count == 1); StrategyInterpreter strategyRunTime = new StrategyInterpreter(); DateTime startDate = new DateTime(2000, 1, 7); DateTime endDate = new DateTime(2000, 2, 25); strategyRunTime.Execute(strategy, startDate, endDate); //PositionSetRunTime longPositions = strategyRunTime.PositionSetTable["LongPositions"]; //Assert.IsTrue(longPositions.Positions.Any(p => p.CurrencyInPosition.Name == "USD")); //Assert.IsTrue(longPositions.Positions.Any(p => p.CurrencyInPosition.Name == "GBP")); //Assert.IsTrue(longPositions.Positions.Any(p => p.CurrencyInPosition.Name == "NOK")); }
public void TransformerTest() { StrategyLanguageParser fxParser = new StrategyLanguageParser(); TradingStrategyAstNode strategyAst = fxParser.Parse(ExampleCode); AstTreeToModelTransformer transformer = new AstTreeToModelTransformer(); TradingStrategy strategy = transformer.Transform(strategyAst); Assert.IsTrue(strategy.TradingRules.Count > 0); StrategyInterpreter strategyRunTime = new StrategyInterpreter(); DateTime startDate = new DateTime(2000, 1, 7); DateTime endDate = new DateTime(2000, 2, 25); Assert.IsTrue(strategy.ConstantVariableDefinitions.Count == 3); strategyRunTime.Execute(strategy, startDate, endDate); PositionSetRuntime longPositions = strategyRunTime.PositionSetTable["LongPositions"]; Assert.IsTrue(longPositions.Positions.Any(p => p.CurrencyInPosition.Name == "USD")); Assert.IsTrue(longPositions.Positions.Any(p => p.CurrencyInPosition.Name == "GBP")); Assert.IsTrue(longPositions.Positions.Any(p => p.CurrencyInPosition.Name == "NOK")); strategyRunTime.Clear(); strategyRunTime.Execute(strategy, startDate, new DateTime(2000, 3, 10)); longPositions = strategyRunTime.PositionSetTable["LongPositions"]; Assert.IsTrue(longPositions.Positions.Any(p => p.CurrencyInPosition.Name == "USD")); Assert.IsTrue(longPositions.Positions.Any(p => p.CurrencyInPosition.Name == "GBP")); Assert.IsTrue(longPositions.Positions.Any(p => p.CurrencyInPosition.Name == "NZD")); strategyRunTime.Clear(); strategyRunTime.Execute(strategy, startDate, new DateTime(2000, 4, 14)); longPositions = strategyRunTime.PositionSetTable["LongPositions"]; Assert.IsTrue(longPositions.Positions.Any(p => p.CurrencyInPosition.Name == "USD")); Assert.IsTrue(longPositions.Positions.Any(p => p.CurrencyInPosition.Name == "NOK")); Assert.IsTrue(longPositions.Positions.Any(p => p.CurrencyInPosition.Name == "NZD")); }