/// <summary> /// Trying to find if current Cape is the lowest Cape in three months to indicate selling period /// </summary> public void OnData(CAPE data) { _newLow = false; //Adds first four Cape Ratios to array c _currCape = data.Cape; if (_counter < 4) { _c[_counter++] = _currCape; } //Replaces oldest Cape with current Cape //Checks to see if current Cape is lowest in the previous quarter //Indicating a sell off else { Array.Copy(_c, _cCopy, 4); Array.Sort(_cCopy); if (_cCopy[0] > _currCape) { _newLow = true; } _c[_counter2++] = _currCape; if (_counter2 == 4) { _counter2 = 0; } } Debug("Current Cape: " + _currCape + " on " + data.Time); if (_newLow) { Debug("New Low has been hit on " + data.Time); } }
/// <summary> /// Reader Method :: using set of arguements we specify read out type. Enumerate /// until the end of the data stream or file. E.g. Read CSV file line by line and convert /// into data types. /// </summary> /// <returns>BaseData type set by Subscription Method.</returns> /// <param name="config">Config.</param> /// <param name="line">Line.</param> /// <param name="date">Date.</param> /// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param> public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode) { var index = new CAPE(); try { //Example File Format: //Date | Price | Div | Earning | CPI | FractionalDate | Interest Rate | RealPrice | RealDiv | RealEarnings | CAPE //2014.06 1947.09 37.38 103.12 238.343 2014.37 2.6 1923.95 36.94 101.89 25.55 var data = line.Split(','); //Dates must be in the format YYYY-MM-DD. If your data source does not have this format, you must use //DateTime.ParseExact() and explicit declare the format your data source has. var dateString = data[0]; index.Time = DateTime.ParseExact(dateString, Format, _provider); index.Cape = Convert.ToDecimal(data[10], CultureInfo.InvariantCulture); index.Symbol = "CAPE"; index.Value = index.Cape; } catch { } return(index); }