public static object CreateMarketDataSource(string ContractHandle, object[] Timestamps, object[] MidPrices, object SpreadOpt) { double spread = Utils.GetOptionalParameter(SpreadOpt, 0.0); Contract cc = XLOM.Get <Contract>(ContractHandle); object[] timestamps = Utils.GetVector <object>(Timestamps); double[] midprices = Utils.GetVector <double>(MidPrices); int nData = timestamps.Length; bool oaDate = (timestamps[0].GetType() == typeof(double)); List <ITimestampedDatum> DataSource = new List <ITimestampedDatum>(nData); for (int i = 0; i < nData; ++i) { DateTimeOffset now = new DateTimeOffset((oaDate ? DateTime.FromOADate((double)timestamps[i]) : DateTime.Parse(timestamps[i].ToString())), new TimeSpan(0, 0, 0)); DataSource.Add(new Market(now, cc.Id, (decimal)(midprices[i] * (1 - 0.5 * spread)), (decimal)(midprices[i] * (1 + 0.5 * spread)))); } DataSourceInfo dsi = new DataSourceInfo("InMemoryMarketDataSource", cc.Id, cc.Symbol); if (XLOM.Contains(dsi.ToString())) { XLOM.Remove(dsi.ToString()); } return(XLOM.Add(dsi.ToString(), DataSource)); }
public static object CreateImpliedVolDataSource(int ContractId, object[] Timestamps, double[] ImpliedVols) { int nData = Timestamps.Length; bool oaDate = (Timestamps[0].GetType() == typeof(double)); List <ITimestampedDatum> DataSource = new List <ITimestampedDatum>(nData); for (int i = 0; i < nData; ++i) { DateTimeOffset now = new DateTimeOffset((oaDate ? DateTime.FromOADate((double)Timestamps[i]) : DateTime.Parse(Timestamps[i].ToString())), new TimeSpan(0, 0, 0)); DataSource.Add(new ImpliedVol(now, ContractId, ImpliedVols[i])); } DataSourceInfo dsi = new DataSourceInfo("InMemoryImpliedVolDataSource", ContractId, "ATMF"); if (XLOM.Contains(dsi.ToString())) { XLOM.Remove(dsi.ToString()); } return(XLOM.Add(dsi.ToString(), DataSource)); }
public static object CreateDepositRateDataSource(string Currency, object[] Timestamps, double[] DepositRates) { int nData = Timestamps.Length; bool oaDate = (Timestamps[0].GetType() == typeof(double)); List <ITimestampedDatum> DataSource = new List <ITimestampedDatum>(nData); for (int i = 0; i < nData; ++i) { DateTimeOffset now = new DateTimeOffset((oaDate ? DateTime.FromOADate((double)Timestamps[i]) : DateTime.Parse(Timestamps[i].ToString())), new TimeSpan(0, 0, 0)); DataSource.Add(new DepositRate(now, Currency, DepositRates[i])); } DataSourceInfo dsi = new DataSourceInfo("InMemoryDepositRateDataSource", 0, Currency); if (XLOM.Contains(dsi.ToString())) { XLOM.Remove(dsi.ToString()); } return(XLOM.Add(dsi.ToString(), DataSource)); }