/// <summary>
        /// Simulates a given scenario and calculates profit / loss that would be made if scenario happened on each second in history of captured market order books.
        /// Profit/losses are output to a file given in scenario description.
        /// </summary>
        /// <param name="scenario">Scenario to simulate.</param>
        /// <param name="historyLoader">Loader to be used to access history of market order books.</param>
        public ProfitSimulator(SimulationScenario scenario, BitstampHistoryLoader historyLoader)
        {
            _historyEnumerator = new HistoryEnumerator(historyLoader);
            var firstEntry = _historyEnumerator.PeekNext();

            if (firstEntry == null)
            {
                return;
            }

            _engine = new SimulationEngine(firstEntry.AcqTime);
            _engine.AfterEventSimulation += LoadOrderBookHistoryEventsIntoEngine;


            _dependencyFactory = new SimulationDependencyFactory(_engine);

            _scenario = scenario;
            _dependencyFactory.HedgingEngine.WhenStrategy.Delay         = _scenario.HedgingDelay * 1000;
            _dependencyFactory.PricingEngine.PricingStrategy.SellSpread = _scenario.SellSpread / 100;
            _dependencyFactory.PricingEngine.PricingStrategy.BuySpread  = _scenario.BuySpread / 100;
            _dependencyFactory.SolarisBank.InfiniteBalance = true;
            _dependencyFactory.SolarisBank.TransferDelay   = 10;

            _resultWriter = new CsvProfitSimulationWriter(_scenario.OutputFilename);
            _resultWriter.Initialize();

            _isSimulationDone = false;

            _liquidityEngine = new SimulationLiquidityEngineMoq(_dependencyFactory);
        }
Esempio n. 2
0
        // ###########################################################################
        //
        // P U B L I C
        //
        // ###########################################################################

        // ===========================================================================
        /// \brief	Initialize the history for a given max length
        // ===========================================================================
        public History(int length)
        {
            this.length         = length;
            this.items          = new LinkedList <T> ( );
            this.idxStart       = 0;
            this.idxEnd         = -1;
            this.safeEnumerator = null;
        }
Esempio n. 3
0
        // ===========================================================================
        /// \brief	Terminate explicitly a safe enumeration
        // ===========================================================================
        public void EndLockedEnumeration()
        {
            HistoryEnumerator <T> e;

            e = safeEnumerator;
            safeEnumerator = null;

            // Disposing the enumerator will release the lock
            e.Dispose( );
        }
Esempio n. 4
0
        // ===========================================================================
        /// \brief	Return a new enumerator on this history
        // ===========================================================================
        public IEnumerator <T> GetEnumerator()
        {
            IEnumerator <T> e;

            lock (locker)
            {
                // Create a new enumerator only if 'BeginLockedEnumeration' is not in use
                if (safeEnumerator == null)
                {
                    e = new HistoryEnumerator <T> (this, scaler, idxStart, idxEnd, locker);
                }
                else
                {
                    safeEnumerator.Reset( );
                    e = safeEnumerator;
                }
            }

            return(e);
        }
Esempio n. 5
0
 // ===========================================================================
 /// \brief	Begin explicitly a safe enumeration
 // ===========================================================================
 public void BeginLockedEnumeration()
 {
     // Creating the enumerator will get the lock
     safeEnumerator = new HistoryEnumerator <T> (this, scaler, idxStart, idxEnd, locker);
 }