本文整理匯總了C#中QuantConnect.Securities.Security.SetMarketPrice方法的典型用法代碼示例。如果您正苦於以下問題:C# Security.SetMarketPrice方法的具體用法?C# Security.SetMarketPrice怎麽用?C# Security.SetMarketPrice使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類QuantConnect.Securities.Security
的用法示例。
在下文中一共展示了Security.SetMarketPrice方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: UpdatesAfterCorrectPeriodElapses
public void UpdatesAfterCorrectPeriodElapses()
{
const int periods = 3;
var periodSpan = Time.OneMinute;
var reference = new DateTime(2016, 04, 06, 12, 0, 0);
var referenceUtc = reference.ConvertToUtc(TimeZones.NewYork);
var timeKeeper = new TimeKeeper(referenceUtc);
var config = new SubscriptionDataConfig(typeof (TradeBar), Symbols.SPY, Resolution.Minute, TimeZones.NewYork, TimeZones.NewYork, true, false, false);
var security = new Security(SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork), config, new Cash("USD", 0, 0), SymbolProperties.GetDefault("USD"));
security.SetLocalTimeKeeper(timeKeeper.GetLocalTimeKeeper(TimeZones.NewYork));
var model = new RelativeStandardDeviationVolatilityModel(periodSpan, periods);
security.VolatilityModel = model;
var first = new IndicatorDataPoint(reference, 1);
security.SetMarketPrice(first);
Assert.AreEqual(0m, model.Volatility);
const decimal value = 0.471404520791032M; // std of 1,2 is ~0.707 over a mean of 1.5
var second = new IndicatorDataPoint(reference.AddMinutes(1), 2);
security.SetMarketPrice(second);
Assert.AreEqual(value, model.Volatility);
// update should not be applied since not enough time has passed
var third = new IndicatorDataPoint(reference.AddMinutes(1.01), 1000);
security.SetMarketPrice(third);
Assert.AreEqual(value, model.Volatility);
var fourth = new IndicatorDataPoint(reference.AddMinutes(2), 3m);
security.SetMarketPrice(fourth);
Assert.AreEqual(0.5m, model.Volatility);
}
示例2: PerformsLimitFillSell
public void PerformsLimitFillSell()
{
var model = new SecurityTransactionModel();
var order = new LimitOrder(Symbol, -100, 101.5m, DateTime.Now, type: SecurityType.Equity);
var config = new SubscriptionDataConfig(typeof(TradeBar), SecurityType.Equity, Symbol, Resolution.Minute, true, true, true, true, false, 0);
var security = new Security(config, 1);
security.SetMarketPrice(DateTime.Now, new IndicatorDataPoint(Symbol, DateTime.Now, 101m));
var fill = model.LimitFill(security, order);
Assert.AreEqual(0, fill.FillQuantity);
Assert.AreEqual(0, fill.FillPrice);
Assert.AreEqual(OrderStatus.None, fill.Status);
Assert.AreEqual(OrderStatus.None, order.Status);
security.SetMarketPrice(DateTime.Now, new TradeBar(DateTime.Now, Symbol, 102m, 103m, 101m, 102.3m, 100));
fill = model.LimitFill(security, order);
// this fills worst case scenario, so it's at the limit price
Assert.AreEqual(order.Quantity, fill.FillQuantity);
Assert.AreEqual(Math.Max(order.LimitPrice, security.Low), fill.FillPrice);
Assert.AreEqual(OrderStatus.Filled, fill.Status);
Assert.AreEqual(OrderStatus.Filled, order.Status);
}
示例3: PerformsLimitFillBuy
public void PerformsLimitFillBuy()
{
var model = new SecurityTransactionModel();
var order = new LimitOrder(Symbol, 100, 101.5m, Noon, type: SecurityType.Equity);
var config = CreateTradeBarConfig(Symbol);
var security = new Security(SecurityExchangeHoursTests.CreateUsEquitySecurityExchangeHours(), config, 1);
security.SetMarketPrice(Noon, new IndicatorDataPoint(Symbol, Noon, 102m));
var fill = model.LimitFill(security, order);
Assert.AreEqual(0, fill.FillQuantity);
Assert.AreEqual(0, fill.FillPrice);
Assert.AreEqual(OrderStatus.None, fill.Status);
Assert.AreEqual(OrderStatus.None, order.Status);
security.SetMarketPrice(Noon, new TradeBar(Noon, Symbol, 102m, 103m, 101m, 102.3m, 100));
fill = model.LimitFill(security, order);
// this fills worst case scenario, so it's at the limit price
Assert.AreEqual(order.Quantity, fill.FillQuantity);
Assert.AreEqual(Math.Min(order.LimitPrice, security.High), fill.FillPrice);
Assert.AreEqual(OrderStatus.Filled, fill.Status);
Assert.AreEqual(OrderStatus.Filled, order.Status);
}
示例4: PerformsLimitFillBuy
public void PerformsLimitFillBuy()
{
var model = new ForexTransactionModel();
var order = new LimitOrder(Symbol, 100, 101.5m, DateTime.Now, type: SecurityType.Forex);
var config = CreateTradeBarDataConfig(SecurityType.Forex, Symbol);
var security = new Security(SecurityExchangeHours.AlwaysOpen, config, 1);
security.SetLocalTimeKeeper(TimeKeeper.GetLocalTimeKeeper(TimeZones.NewYork));
security.SetMarketPrice(new IndicatorDataPoint(Symbol, DateTime.Now, 102m));
var fill = model.LimitFill(security, order);
Assert.AreEqual(0, fill.FillQuantity);
Assert.AreEqual(0, fill.FillPrice);
Assert.AreEqual(OrderStatus.None, fill.Status);
Assert.AreEqual(OrderStatus.None, order.Status);
security.SetMarketPrice(new TradeBar(DateTime.Now, Symbol, 102m, 103m, 101m, 102.3m, 100));
fill = model.LimitFill(security, order);
// this fills worst case scenario, so it's at the limit price
Assert.AreEqual(order.Quantity, fill.FillQuantity);
Assert.AreEqual(Math.Min(order.LimitPrice, security.High), fill.FillPrice);
Assert.AreEqual(OrderStatus.Filled, fill.Status);
Assert.AreEqual(OrderStatus.Filled, order.Status);
}
示例5: PerformsMarketFillSell
public void PerformsMarketFillSell()
{
var model = new SecurityTransactionModel();
var order = new MarketOrder(Symbols.SPY, -100, Noon);
var config = CreateTradeBarConfig(Symbols.SPY);
var security = new Security(SecurityExchangeHoursTests.CreateUsEquitySecurityExchangeHours(), config, new Cash(CashBook.AccountCurrency, 0, 1m), SymbolProperties.GetDefault(CashBook.AccountCurrency));
security.SetLocalTimeKeeper(TimeKeeper.GetLocalTimeKeeper(TimeZones.NewYork));
security.SetMarketPrice(new IndicatorDataPoint(Symbols.SPY, Noon, 101.123m));
var fill = model.MarketFill(security, order);
Assert.AreEqual(order.Quantity, fill.FillQuantity);
Assert.AreEqual(security.Price, fill.FillPrice);
Assert.AreEqual(OrderStatus.Filled, fill.Status);
}
示例6: PerformsMarketFillBuy
public void PerformsMarketFillBuy()
{
var model = new SecurityTransactionModel();
var order = new MarketOrder(Symbols.SPY, 100, Noon, type: SecurityType.Equity);
var config = CreateTradeBarConfig(Symbols.SPY);
var security = new Security(SecurityExchangeHoursTests.CreateUsEquitySecurityExchangeHours(), config, 1);
security.SetLocalTimeKeeper(TimeKeeper.GetLocalTimeKeeper(TimeZones.NewYork));
security.SetMarketPrice(new IndicatorDataPoint(Symbols.SPY, Noon, 101.123m));
var fill = model.MarketFill(security, order);
Assert.AreEqual(order.Quantity, fill.FillQuantity);
Assert.AreEqual(security.Price, fill.FillPrice);
Assert.AreEqual(OrderStatus.Filled, fill.Status);
}
示例7: Initialize
/// <summary>
/// Initializes the specified security by setting up the models
/// </summary>
/// <param name="security">The security to be initialized</param>
public virtual void Initialize(Security security)
{
// set leverage and models
security.SetLeverage(_brokerageModel.GetLeverage(security));
security.FillModel = _brokerageModel.GetFillModel(security);
security.FeeModel = _brokerageModel.GetFeeModel(security);
security.SlippageModel = _brokerageModel.GetSlippageModel(security);
security.SettlementModel = _brokerageModel.GetSettlementModel(security, _brokerageModel.AccountType);
BaseData seedData = _securitySeeder.GetSeedData(security);
if (seedData != null)
{
security.SetMarketPrice(seedData);
}
}
示例8: PerformsLimitFillBuy
public void PerformsLimitFillBuy()
{
var model = new SecurityTransactionModel();
var order = new LimitOrder(Symbols.SPY, 100, 101.5m, Noon);
var config = CreateTradeBarConfig(Symbols.SPY);
var security = new Security(SecurityExchangeHoursTests.CreateUsEquitySecurityExchangeHours(), config, new Cash(CashBook.AccountCurrency, 0, 1m), SymbolProperties.GetDefault(CashBook.AccountCurrency));
security.SetLocalTimeKeeper(TimeKeeper.GetLocalTimeKeeper(TimeZones.NewYork));
security.SetMarketPrice(new IndicatorDataPoint(Symbols.SPY, Noon, 102m));
var fill = model.LimitFill(security, order);
Assert.AreEqual(0, fill.FillQuantity);
Assert.AreEqual(0, fill.FillPrice);
Assert.AreEqual(OrderStatus.None, fill.Status);
security.SetMarketPrice(new TradeBar(Noon, Symbols.SPY, 102m, 103m, 101m, 102.3m, 100));
fill = model.LimitFill(security, order);
// this fills worst case scenario, so it's at the limit price
Assert.AreEqual(order.Quantity, fill.FillQuantity);
Assert.AreEqual(Math.Min(order.LimitPrice, security.High), fill.FillPrice);
Assert.AreEqual(OrderStatus.Filled, fill.Status);
}
示例9: Update
private void Update(Security security, decimal close)
{
security.SetMarketPrice(new TradeBar
{
Time = DateTime.Now,
Symbol = security.Symbol,
Open = close,
High = close,
Low = close,
Close = close
});
}
示例10: InitializeTest
private static DateTime InitializeTest(out BasicTemplateAlgorithm algorithm, out Security security, out PartialMarketFillModel model, out MarketOrder order, out OrderTicket ticket)
{
var referenceTimeNY = new DateTime(2015, 12, 21, 13, 0, 0);
var referenceTimeUtc = referenceTimeNY.ConvertToUtc(TimeZones.NewYork);
algorithm = new BasicTemplateAlgorithm();
algorithm.SetDateTime(referenceTimeUtc);
var transactionHandler = new BacktestingTransactionHandler();
transactionHandler.Initialize(algorithm, new BacktestingBrokerage(algorithm), new TestResultHandler(Console.WriteLine));
Task.Run(() => transactionHandler.Run());
algorithm.Transactions.SetOrderProcessor(transactionHandler);
var config = new SubscriptionDataConfig(typeof(TradeBar), Symbols.SPY, Resolution.Second, TimeZones.NewYork, TimeZones.NewYork, false, false, false);
security = new Security(SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork), config);
model = new PartialMarketFillModel(algorithm.Transactions, 2);
algorithm.Securities.Add(security);
algorithm.Securities[Symbols.SPY].FillModel = model;
security.SetMarketPrice(new Tick { Symbol = Symbols.SPY, Value = 100 });
algorithm.SetFinishedWarmingUp();
order = new MarketOrder(Symbols.SPY, 100, referenceTimeUtc) { Id = 1 };
var request = new SubmitOrderRequest(OrderType.Market, security.Type, security.Symbol, order.Quantity, 0, 0, algorithm.UtcTime, null);
ticket = algorithm.Transactions.ProcessRequest(request);
return referenceTimeUtc;
}
示例11: InitializeTest
private Security InitializeTest(DateTime reference, out SecurityPortfolioManager portfolio)
{
var security = new Security(SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork), CreateTradeBarConfig(), new Cash(CashBook.AccountCurrency, 0, 1m), SymbolProperties.GetDefault(CashBook.AccountCurrency));
security.SetMarketPrice(new Tick { Value = 100 });
var timeKeeper = new TimeKeeper(reference);
var securityManager = new SecurityManager(timeKeeper);
securityManager.Add(security);
var transactionManager = new SecurityTransactionManager(securityManager);
portfolio = new SecurityPortfolioManager(securityManager, transactionManager);
portfolio.SetCash("USD", 100 * 1000m, 1m);
Assert.AreEqual(0, security.Holdings.Quantity);
Assert.AreEqual(100*1000m, portfolio.CashBook[CashBook.AccountCurrency].Amount);
return security;
}
示例12: PerformsMarketOnCloseUsingClosingPrice
public void PerformsMarketOnCloseUsingClosingPrice()
{
var reference = new DateTime(2015, 06, 05, 15, 0, 0); // before market close
var model = new SecurityTransactionModel();
var order = new MarketOnCloseOrder(Symbol, SecurityType.Equity, 100, reference);
var config = CreateTradeBarConfig(Symbol);
var security = new Security(SecurityExchangeHoursTests.CreateUsEquitySecurityExchangeHours(), config, 1)
{
Exchange = new EquityExchange(SecurityExchangeHoursTests.CreateUsEquitySecurityExchangeHours())
};
var time = reference;
security.SetMarketPrice(time, new TradeBar(time, Symbol, 1m, 2m, 0.5m, 1.33m, 100));
var fill = model.MarketOnCloseFill(security, order);
Assert.AreEqual(0, fill.FillQuantity);
// market closes after 60min, so this is just before market Close
time = reference.AddMinutes(59);
security.SetMarketPrice(time, new TradeBar(time, Symbol, 1.33m, 2.75m, 1.15m, 1.45m, 100));
fill = model.MarketOnCloseFill(security, order);
Assert.AreEqual(0, fill.FillQuantity);
// market closes
time = reference.AddMinutes(60);
security.SetMarketPrice(time, new TradeBar(time, Symbol, 1.45m, 2.0m, 1.1m, 1.40m, 100));
while (security.Exchange.ExchangeOpen)
{
time += TimeSpan.FromTicks(1);
security.SetMarketPrice(time, null);
}
Console.WriteLine("Time: " + time);
fill = model.MarketOnCloseFill(security, order);
Assert.AreEqual(order.Quantity, fill.FillQuantity);
Assert.AreEqual(security.Close, fill.FillPrice);
}
示例13: CreateSecurity
private static Security CreateSecurity(DateTime newLocalTime)
{
var security = new Security(CreateUsEquitySecurityExchangeHours(), CreateTradeBarConfig(), new Cash(CashBook.AccountCurrency, 0, 1m), SymbolProperties.GetDefault(CashBook.AccountCurrency));
security.Exchange.SetLocalDateTimeFrontier(newLocalTime);
security.SetLocalTimeKeeper(TimeKeeper.GetLocalTimeKeeper(TimeZones.NewYork));
security.SetMarketPrice(new IndicatorDataPoint(Symbols.SPY, newLocalTime, 100m));
return security;
}
示例14: PerformsStopLimitFillSell
public void PerformsStopLimitFillSell()
{
var model = new SecurityTransactionModel();
var order = new StopLimitOrder(Symbols.SPY, -100, 101.75m, 101.50m, Noon, type: SecurityType.Equity);
var config = CreateTradeBarConfig(Symbols.SPY);
var security = new Security(SecurityExchangeHoursTests.CreateUsEquitySecurityExchangeHours(), config, 1);
security.SetLocalTimeKeeper(TimeKeeper.GetLocalTimeKeeper(TimeZones.NewYork));
security.SetMarketPrice(new IndicatorDataPoint(Symbols.SPY, Noon, 102m));
var fill = model.StopLimitFill(security, order);
Assert.AreEqual(0, fill.FillQuantity);
Assert.AreEqual(0, fill.FillPrice);
Assert.AreEqual(OrderStatus.None, fill.Status);
security.SetMarketPrice(new IndicatorDataPoint(Symbols.SPY, Noon, 101m));
fill = model.StopLimitFill(security, order);
Assert.AreEqual(0, fill.FillQuantity);
Assert.AreEqual(0, fill.FillPrice);
Assert.AreEqual(OrderStatus.None, fill.Status);
security.SetMarketPrice(new IndicatorDataPoint(Symbols.SPY, Noon, 101.66m));
fill = model.StopLimitFill(security, order);
// this fills worst case scenario, so it's at the limit price
Assert.AreEqual(order.Quantity, fill.FillQuantity);
Assert.AreEqual(order.LimitPrice, fill.FillPrice);
Assert.AreEqual(OrderStatus.Filled, fill.Status);
}
示例15: PerformsStopLimitFillSell
public void PerformsStopLimitFillSell()
{
var model = new ForexTransactionModel();
var order = new StopLimitOrder(Symbol, -100, 101.75m, 101.50m, DateTime.Now, type: SecurityType.Forex);
var config = CreateTradeBarDataConfig(SecurityType.Forex, Symbol);
var security = new Security(SecurityExchangeHours.AlwaysOpen, config, 1);
security.SetMarketPrice(DateTime.Now, new IndicatorDataPoint(Symbol, DateTime.Now, 102m));
var fill = model.StopLimitFill(security, order);
Assert.AreEqual(0, fill.FillQuantity);
Assert.AreEqual(0, fill.FillPrice);
Assert.AreEqual(OrderStatus.None, fill.Status);
Assert.AreEqual(OrderStatus.None, order.Status);
security.SetMarketPrice(DateTime.Now, new IndicatorDataPoint(Symbol, DateTime.Now, 101m));
fill = model.StopLimitFill(security, order);
Assert.AreEqual(0, fill.FillQuantity);
Assert.AreEqual(0, fill.FillPrice);
Assert.AreEqual(OrderStatus.None, fill.Status);
Assert.AreEqual(OrderStatus.None, order.Status);
security.SetMarketPrice(DateTime.Now, new IndicatorDataPoint(Symbol, DateTime.Now, 101.66m));
fill = model.StopLimitFill(security, order);
// this fills worst case scenario, so it's at the limit price
Assert.AreEqual(order.Quantity, fill.FillQuantity);
Assert.AreEqual(order.LimitPrice, fill.FillPrice);
Assert.AreEqual(OrderStatus.Filled, fill.Status);
Assert.AreEqual(OrderStatus.Filled, order.Status);
}