public void GetTransformedPositionRecordsTest()
        {
            FXEntities.FXEntities fxEntities = new FXEntities.FXEntities();
            CurrencyDataSource currencyDataSource = new CurrencyDataSource(fxEntities);
           
            var startDate = new DateTime(2000, 1, 4);
            var endDate = new DateTime(2003, 1, 4);
            var periodicTimeDef = new PeriodicTimeDefinition(3, PeriodicType.Month);
            periodicTimeDef.Initialize(startDate, endDate);
            ProfitCalculationEngine_Accessor target = new ProfitCalculationEngine_Accessor(currencyDataSource);

            PositionRuntime positionRuntime = new PositionRuntime(FXStrategy.Interpreter.PositionType.Long);
            positionRuntime.PositionRecords.Add(new PositionRecord(
                new DateTime(2000, 1, 4), new Currency("USD"), new Currency("EUR"),
                 FXStrategy.Interpreter.PositionType.Long, positionRuntime)
                 {
                     EndDate = new DateTime(2001,3,2)
                 });

            //var actual = target.GetTransformedPositionRecords(positionRuntime, periodicTimeDef);

            //Assert.AreEqual(actual.Count, 6);
            //Assert.IsTrue(actual.ElementAt(5).Type == FXStrategy.Interpreter.PositionType.Short);
            //Assert.IsTrue(actual.Take(5).All(t => t.Type == FXStrategy.Interpreter.PositionType.Long));
        }
 public void GetTermFromPeriodTest()
 {
     DateTime positionStartDate = new DateTime(2000,1,4);
     DateTime positionEndDate = new DateTime(2000,7,15); 
     PeriodicTimeDefinition termLength = new PeriodicTimeDefinition(3, PeriodicType.Month);
     termLength.Initialize(positionStartDate, new DateTime(2001,1,1));
     List<Term> actual;
     actual = TermManager.GetTermFromPeriod(positionStartDate, positionEndDate, termLength);
     Assert.AreEqual(3, actual.Count);
 }
 public void CanExecuteTest()
 {
     PeriodicTimeDefinition target = new PeriodicTimeDefinition( 3,
           PeriodicType.Month
     );
     DateTime startDate = new DateTime(2000,1,7); 
     DateTime currentDate = new DateTime(2000,4,7);
     bool expected = true; // TODO: Initialize to an appropriate value
     bool actual;
     target.Initialize(startDate, currentDate);
     actual = target.CanExecute(currentDate);
     Assert.AreEqual(expected, actual);
 }
        /// <summary>
        /// Calculate returns from the position records in the position run time
        /// </summary>
        /// <param name="positionRunTimeList">list of positions (from the runtime)</param>
        /// <param name="startDate">start date of the back-testing analysis</param>
        /// <param name="endDate">end date of the back-testing analysis</param>
        /// <param name="termLength">Length of forward contract</param>
        public void Evaluate(List<PositionRuntime> positionRunTimeList, 
            DateTime startDate, DateTime endDate, PeriodicTimeDefinition termLength)
        {
             if (termLength.AvailableDates == null)
                termLength.Initialize(startDate, endDate);

             _effectiveDates = Util.DateTimeHelper.GetWeekdaysDate(startDate, endDate);

            _individualPositionIndex = new Dictionary<PositionRuntime, List<TimeSeriesData>>();

            // initialize data set
            _currencyDataSource.PreLoad();

            // Calculate profit for each position parallely
            positionRunTimeList.AsParallel().ForAll(position =>
                CalculateIndividualPositionProfitIndexes(startDate,endDate,termLength,position));

            CalculateReturnIndex(startDate,endDate,termLength);
        }