public List <Signal> GenerateOnClose(DateTime ts, int leadingIndex, SystemState systemState) { List <Signal> res = new List <Signal>(); if (leadingIndex <= _statSMA.BackBufferLength) { return(res); } StockPricesData data = _dataLoader.Get(_stock.FullName, _dataRange, 0, ts, ts); if ((data.C[leadingIndex - 1] <= _statSMA.Data(StatSMAData.SMA)[leadingIndex - 1 - _statSMA.BackBufferLength]) && (data.C[leadingIndex] > _statSMA.Data(StatSMAData.SMA)[leadingIndex - _statSMA.BackBufferLength])) { res.Add(CreateSignal(PositionDir.Long, systemState, data.C[leadingIndex])); } if ((data.C[leadingIndex - 1] >= _statSMA.Data(StatSMAData.SMA)[leadingIndex - 1 - _statSMA.BackBufferLength]) && (data.C[leadingIndex] < _statSMA.Data(StatSMAData.SMA)[leadingIndex - _statSMA.BackBufferLength])) { res.Add(CreateSignal(PositionDir.Short, systemState, data.C[leadingIndex])); } return(res); }
/// <summary> /// Gets stockpricesdata and index of specified ts. Returns true if index found. /// </summary> /// <param name="dataLoader"></param> /// <param name="stockName"></param> /// <param name="dataRange"></param> /// <param name="ts"></param> /// <param name="spData"></param> /// <param name="dataIndex"></param> /// <returns></returns> public static bool GetWithIndex(this ISystemDataLoader dataLoader, string stockName, StockDataRange dataRange, DateTime ts, out StockPricesData spData, out int dataIndex) { spData = dataLoader.Get(stockName, dataRange, 0, ts, ts); dataIndex = spData.FindByTS(ts); return(dataIndex >= 0); }
public List <Signal> GenerateOnClose(DateTime ts, int leadingIndex, SystemState systemState) { List <Signal> res = new List <Signal>(); if (leadingIndex <= _statBB.BackBufferLength) { return(res); } StockPricesData data = _dataLoader.Get(_stock.FullName, _dataRange, 0, ts, ts); _currentTrend = BBTrendRecognizer.BBTrendRecognizer.RecognizeTrend(data, (StatBB)_statBB, leadingIndex, _currentTrend, out _); BBTrendExpectation expectation = BBTrendRecognizer.BBTrendRecognizer.GetExpectation(data, (StatBB)_statBB, leadingIndex, _currentTrend); if (systemState.PositionsActive.Count > 0) { if (systemState.PositionsActive.Count > 1) { throw new Exception("More than 1 active position"); } if ((expectation == BBTrendExpectation.DownAndFalling) || (expectation == BBTrendExpectation.DownButPossibleChange)) { systemState.PositionsActive[0].CloseMode = PositionCloseMode.OnOpen; } } else { if ((expectation == BBTrendExpectation.UpAndRaising) || (expectation == BBTrendExpectation.UpButPossibleChange)) { res.Add(CreateSignal(PositionDir.Long, systemState, data.C[leadingIndex])); } } return(res); }
private float CalcActive(SystemState system, DateTime ts, ISystemDataLoader dataLoader) { return(system.PositionsActive.Sum(p => { StockPricesData prices = dataLoader.Get(p.Stock.FullName, p.DataRange, p.IntradayInterval, ts, ts); int ix = prices.FindByTS(ts); return p.DirectionMultiplier() * prices.C[ix] * p.Volume; })); }
private StockPricesData GetLeadingData(SystemConfiguration systemConfiguration) { StockPricesData res = _dataLoader.Get(systemConfiguration.dataDefinition.stocks[0].stock.FullName, systemConfiguration.dataDefinition.stocks[0].dataRange, 0, systemConfiguration.tsFrom, systemConfiguration.tsTo); if (res.Length == 0) { throw new Exception("Leading prices data is empty."); } return(res); }
private bool LastDataTSNotBeforeSimulationEnds(string fundName, DateTime ts) { if (!_dataLoader.GetWithIndex(fundName, _dataRange, ts, out StockPricesData spData, out int dataIndex)) { return(false); } if (dataIndex < spData.Length - 2) { return(true); } StockPricesData spFirstData = _dataLoader.Get(_fundsData.Stocks[0].FullName, _dataRange, 0, ts, ts); return(spData.TS[spData.Length - 1] == spFirstData.TS[spFirstData.Length - 1]); }
public void SetUp() { _dataLoader = Substitute.For <ISystemDataLoader>(); _testSys = new SystemState() { Cash = CashValue }; _stockPrices = new StockPricesData(1); _testObj = new SystemValueCalculator(); _stockPrices.TS[0] = CurrentTS; _stockPrices.C[0] = PriceL; _dataLoader .Get(Arg.Compat.Any <string>(), Arg.Compat.Any <StockDataRange>(), Arg.Compat.Any <int>(), Arg.Compat.Any <DateTime>(), Arg.Compat.Any <DateTime>()) .Returns(_stockPrices); }
public static (StockPricesData pricesData, int pricesDataIndex) GetPricesDataAndIndex(this ISystemDataLoader dataLoader, string stockName, StockDataRange dataRange, int intradayInterval, DateTime ts) { StockPricesData data = dataLoader.Get(stockName, dataRange, intradayInterval, ts, ts); return(data, data.FindByTS(ts)); }
private StockPricesData GetPricesData(Position position, DateTime ts) { return _dataLoader.Get(position.Stock.FullName, position.DataRange, position.IntradayInterval, ts, ts); }