/******************************************************** * CLASS CONSTRUCTOR *********************************************************/ /******************************************************** * CLASS METHODS *********************************************************/ /// <summary> /// Generic Reader Implementation for Quandl Data. /// </summary> /// <param name="config">Subscription configuration</param> /// <param name="line">CSV line of data from the souce</param> /// <param name="date">Date of the requested line</param> /// <param name="datafeed">Datafeed type - live or backtest</param> /// <returns></returns> public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, DataFeedEndpoint datafeed) { var data = new Quandl(); data.Symbol = config.Symbol; var csv = line.Split(','); if (!_isInitialized) { _isInitialized = true; foreach (var propertyName in csv) { var property = propertyName.TrimStart().TrimEnd(); // should we remove property names like Time? // do we need to alias the Time?? data.SetProperty(property, 0m); _propertyNames.Add(property); } return data; } data.Time = DateTime.ParseExact(csv[0], "yyyy-MM-dd", CultureInfo.InvariantCulture); for (var i = 1; i < csv.Length; i++) { var value = csv[i].ToDecimal(); data.SetProperty(_propertyNames[i], value); } // we know that there is a close property, we want to set that to 'Value' data.Value = (decimal) data.GetProperty("Close"); return data; }
/******************************************************** * CLASS METHODS *********************************************************/ /// <summary> /// Generic Reader Implementation for Quandl Data. /// </summary> /// <param name="config">Subscription configuration</param> /// <param name="line">CSV line of data from the souce</param> /// <param name="date">Date of the requested line</param> /// <param name="datafeed">Datafeed type - live or backtest</param> /// <returns></returns> public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, DataFeedEndpoint datafeed) { var data = new Quandl(); data.Symbol = config.Symbol; var csv = line.Split(','); if (!_isInitialized) { _isInitialized = true; foreach (var propertyName in csv) { var property = propertyName.TrimStart().TrimEnd(); // should we remove property names like Time? // do we need to alias the Time?? data.SetProperty(property, 0m); _propertyNames.Add(property); } return(data); } data.Time = DateTime.ParseExact(csv[0], "yyyy-MM-dd", CultureInfo.InvariantCulture); for (var i = 1; i < csv.Length; i++) { var value = csv[i].ToDecimal(); data.SetProperty(_propertyNames[i], value); } // we know that there is a close property, we want to set that to 'Value' data.Value = (decimal)data.GetProperty(_valueColumn); return(data); }
/// <summary> /// Data Event Handler: New data arrives here. "TradeBars" type is a dictionary of strings so you can access it by symbol. /// </summary> /// <param name="data">Data.</param> public void OnData(Quandl data) { if (!Portfolio.HoldStock) { SetHoldings(_crude, 1); Debug(Time.ToString("u") + " Purchased Crude Oil: " + _crude); } }
/// Data Event Handler: New data arrives here. "TradeBars" type is a dictionary of strings so you can access it by symbol. public void OnData(Quandl data) { if (!Portfolio.HoldStock) { //Order function places trades: enter the string symbol and the quantity you want: SetHoldings(_quandlCode, 1); //Debug sends messages to the user console: "Time" is the algorithm time keeper object Debug("Purchased " + _quandlCode + " >> " + Time.ToShortDateString()); } }
public void AccessesGenericallyByType() { Quandl quandlSpy = new Quandl { Symbol = Symbols.SPY, Time = DateTime.Now }; Quandl quandlAapl = new Quandl { Symbol = Symbols.AAPL, Time = DateTime.Now }; Slice slice = new Slice(DateTime.Now, new[] { quandlSpy, quandlAapl }); DataDictionary<Quandl> quandlData = slice.Get<Quandl>(); Assert.AreEqual(2, quandlData.Count); }
public void AccessesGenericallyByTypeAndSymbol() { Quandl quandlSpy = new Quandl { Symbol = Symbols.SPY, Time = DateTime.Now }; Quandl quandlAapl = new Quandl { Symbol = Symbols.AAPL, Time = DateTime.Now }; Slice slice = new Slice(DateTime.Now, new[] { quandlSpy, quandlAapl }); Quandl quandlData = slice.Get<Quandl>(Symbols.SPY); Assert.AreEqual(quandlSpy, quandlData); }