/// <summary> /// Retrieve algorithm-specific registry value. /// </summary> /// <param name="algo">algorithm with which the value is associated</param> /// <param name="valueName">name of the value</param> /// <param name="defaultValue">default value, in case it has not been assigned</param> /// <returns></returns> public static object GetRegistryValue(this SimulatorCore algo, string valueName, object defaultValue = null) { object retValue = GetRegistryValue(algo.Name, valueName); if (retValue == null && defaultValue != null) { SetRegistryValue(algo.Name, valueName, defaultValue); retValue = defaultValue; } return(retValue); }
/// <summary> /// find next bar time that is not a holiday /// </summary> /// <param name="sim">simulator object</param> /// <returns>next bar time</returns> static public DateTime NextSimTime(this SimulatorCore sim) { DateTime currentBarTime = sim.SimTime[0]; DateTime nextBarTime = currentBarTime; do { nextBarTime += TimeSpan.FromDays(1); } while (!IsTradingDay(nextBarTime)); return(nextBarTime); }
/// <summary> /// Factory method to create new data updater object, based on info dictionary. /// </summary> /// <param name="simulator">parent simulator</param> /// <param name="info">info dictionary</param> /// <returns>new data updater object</returns> static public DataUpdater New(SimulatorCore simulator, Dictionary <DataSourceParam, string> info) { if (!info.ContainsKey(DataSourceParam.dataUpdater)) { return(null); } string dataUpdater = info[DataSourceParam.dataUpdater].ToLower(); if (dataUpdater.Contains("iq") && info.ContainsKey(DataSourceParam.symbolIqfeed)) { return(new DataUpdaterIQFeed(simulator, info)); } if (dataUpdater.Contains("ib") && info.ContainsKey(DataSourceParam.symbolInteractiveBrokers)) { return(new DataUpdaterIBOptions(simulator, info)); } if (dataUpdater.Contains("yahoo") && dataUpdater.Contains("opt") && info.ContainsKey(DataSourceParam.symbolYahoo)) { return(new DataUpdaterYahooOptions(simulator, info)); } if (dataUpdater.Contains("yahoo") && info.ContainsKey(DataSourceParam.symbolYahoo)) { return(new DataUpdaterYahoo(simulator, info)); } if (dataUpdater.Contains("stooq") && info.ContainsKey(DataSourceParam.symbolStooq)) { return(new DataUpdaterStooq(simulator, info)); } if (dataUpdater.Contains("fred") && info.ContainsKey(DataSourceParam.symbolFred)) { return(new DataUpdaterFred(simulator, info)); } return(null); }
/// <summary> /// Create and initialize instrument. Algorithms should not create /// instrument objects directly. Instead, the simulator engine will /// create these objects as required, and while processing bars from /// DataSource objects. /// </summary> /// <param name="simulator">parent simulator object</param> /// <param name="source">associated data source</param> public Instrument(SimulatorCore simulator, DataSource source) { Simulator = simulator; DataSource = source; _timeSeries = new BarSeriesAccessor <DateTime>(t => this[t].Time); _openSeries = new BarSeriesAccessor <double>(t => this[t].Open); _highSeries = new BarSeriesAccessor <double>(t => this[t].High); _lowSeries = new BarSeriesAccessor <double>(t => this[t].Low); _closeSeries = new BarSeriesAccessor <double>(t => this[t].Close); _volumeSeries = new BarSeriesAccessor <long>(t => this[t].Volume); _bidSeries = new BarSeriesAccessor <double>(t => this[t].Bid); _askSeries = new BarSeriesAccessor <double>(t => this[t].Ask); _bidVolume = new BarSeriesAccessor <long>(t => this[t].BidVolume); _askVolume = new BarSeriesAccessor <long>(t => this[t].AskVolume); }
/// <summary> /// Create and initialize data updater. /// </summary> /// <param name="simulator">parent simulator</param> /// <param name="info">info dictionary</param> public DataUpdaterYahooOptions(SimulatorCore simulator, Dictionary <DataSourceParam, string> info) : base(simulator, info) { }
/// <summary> /// Set algorithm-specific registry value. /// </summary> /// <param name="algo">algorithm with which the value is associated</param> /// <param name="valueName">name of the value</param> /// <param name="value">new value to be assigned</param> public static void SetRegistryValue(this SimulatorCore algo, string valueName, object value) { SetRegistryValue(algo.Name, valueName, value); }
/// <summary> /// Create and initialize generic data updater object. /// </summary> /// <param name="simulator">parent simulator</param> /// <param name="info">info dictionary</param> protected DataUpdater(SimulatorCore simulator, Dictionary <DataSourceParam, string> info) { Simulator = simulator; Info = info; }
//----- object factory #region static public DataUpdater New(SimulatorCore simulator, Dictionary<DataSourceValue, string> info) /// <summary> /// Factory method to create new data updater object, based on info dictionary. /// </summary> /// <param name="simulator">parent simulator</param> /// <param name="info">info dictionary</param> /// <returns>new data updater object</returns> static public DataUpdater New(SimulatorCore simulator, Dictionary <DataSourceParam, string> info) { return(DataUpdaterCollection.New(simulator, info)); }