本文整理汇总了C#中SecurityPortfolioManager.ScanForCashSettlement方法的典型用法代码示例。如果您正苦于以下问题:C# SecurityPortfolioManager.ScanForCashSettlement方法的具体用法?C# SecurityPortfolioManager.ScanForCashSettlement怎么用?C# SecurityPortfolioManager.ScanForCashSettlement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SecurityPortfolioManager
的用法示例。
在下文中一共展示了SecurityPortfolioManager.ScanForCashSettlement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SellOnMondaySettleOnThursday
public void SellOnMondaySettleOnThursday()
{
var securities = new SecurityManager(TimeKeeper);
var transactions = new SecurityTransactionManager(securities);
var portfolio = new SecurityPortfolioManager(securities, transactions);
// settlement at T+3, 8:00 AM
var model = new DelayedSettlementModel(3, TimeSpan.FromHours(8));
var config = CreateTradeBarConfig(Symbols.SPY);
var security = new Security(SecurityExchangeHoursTests.CreateUsEquitySecurityExchangeHours(), config, 1);
portfolio.SetCash(3000);
Assert.AreEqual(3000, portfolio.Cash);
Assert.AreEqual(0, portfolio.UnsettledCash);
// Sell on Monday
var timeUtc = Noon.ConvertToUtc(TimeZones.NewYork);
model.ApplyFunds(portfolio, security, timeUtc, "USD", 1000);
portfolio.ScanForCashSettlement(timeUtc);
Assert.AreEqual(3000, portfolio.Cash);
Assert.AreEqual(1000, portfolio.UnsettledCash);
// Tuesday, still unsettled
timeUtc = timeUtc.AddDays(1);
portfolio.ScanForCashSettlement(timeUtc);
Assert.AreEqual(3000, portfolio.Cash);
Assert.AreEqual(1000, portfolio.UnsettledCash);
// Wednesday, still unsettled
timeUtc = timeUtc.AddDays(1);
portfolio.ScanForCashSettlement(timeUtc);
Assert.AreEqual(3000, portfolio.Cash);
Assert.AreEqual(1000, portfolio.UnsettledCash);
// Thursday at 7:55 AM, still unsettled
timeUtc = timeUtc.AddDays(1).AddHours(-4).AddMinutes(-5);
portfolio.ScanForCashSettlement(timeUtc);
Assert.AreEqual(3000, portfolio.Cash);
Assert.AreEqual(1000, portfolio.UnsettledCash);
// Thursday at 8 AM, now settled
timeUtc = timeUtc.AddMinutes(5);
portfolio.ScanForCashSettlement(timeUtc);
Assert.AreEqual(4000, portfolio.Cash);
Assert.AreEqual(0, portfolio.UnsettledCash);
}
示例2: EquitySellAppliesSettlementCorrectly
public void EquitySellAppliesSettlementCorrectly()
{
var securityExchangeHours = SecurityExchangeHoursTests.CreateUsEquitySecurityExchangeHours();
var securities = new SecurityManager(TimeKeeper);
var transactions = new SecurityTransactionManager(securities);
var portfolio = new SecurityPortfolioManager(securities, transactions);
portfolio.SetCash(1000);
securities.Add(Symbols.AAPL, new QuantConnect.Securities.Equity.Equity(securityExchangeHours, CreateTradeBarDataConfig(SecurityType.Equity, Symbols.AAPL), new Cash(CashBook.AccountCurrency, 0, 1m), SymbolProperties.GetDefault(CashBook.AccountCurrency)));
var security = securities[Symbols.AAPL];
security.SettlementModel = new DelayedSettlementModel(3, TimeSpan.FromHours(8));
Assert.AreEqual(0, security.Holdings.Quantity);
Assert.AreEqual(1000, portfolio.Cash);
Assert.AreEqual(0, portfolio.UnsettledCash);
// Buy on Monday
var timeUtc = new DateTime(2015, 10, 26, 15, 30, 0);
var orderFee = security.FeeModel.GetOrderFee(security,new MarketOrder(Symbols.AAPL, 10, timeUtc));
var fill = new OrderEvent(1, Symbols.AAPL, timeUtc, OrderStatus.Filled, OrderDirection.Buy, 100, 10, orderFee);
portfolio.ProcessFill(fill);
Assert.AreEqual(10, security.Holdings.Quantity);
Assert.AreEqual(-1, portfolio.Cash);
Assert.AreEqual(0, portfolio.UnsettledCash);
// Sell on Tuesday, cash unsettled
timeUtc = timeUtc.AddDays(1);
orderFee = security.FeeModel.GetOrderFee(security, new MarketOrder(Symbols.AAPL, 10, timeUtc));
fill = new OrderEvent(2, Symbols.AAPL, timeUtc, OrderStatus.Filled, OrderDirection.Sell, 100, -10, orderFee);
portfolio.ProcessFill(fill);
Assert.AreEqual(0, security.Holdings.Quantity);
Assert.AreEqual(-2, portfolio.Cash);
Assert.AreEqual(1000, portfolio.UnsettledCash);
// Thursday, still cash unsettled
timeUtc = timeUtc.AddDays(2);
portfolio.ScanForCashSettlement(timeUtc);
Assert.AreEqual(-2, portfolio.Cash);
Assert.AreEqual(1000, portfolio.UnsettledCash);
// Friday at open, cash settled
var marketOpen = securityExchangeHours.MarketHours[timeUtc.DayOfWeek].GetMarketOpen(TimeSpan.Zero, false);
Assert.IsTrue(marketOpen.HasValue);
timeUtc = timeUtc.AddDays(1).Date.Add(marketOpen.Value).ConvertToUtc(securityExchangeHours.TimeZone);
portfolio.ScanForCashSettlement(timeUtc);
Assert.AreEqual(998, portfolio.Cash);
Assert.AreEqual(0, portfolio.UnsettledCash);
}
示例3: EquitySellAppliesSettlementCorrectly
public void EquitySellAppliesSettlementCorrectly()
{
var securityExchangeHours = SecurityExchangeHoursTests.CreateUsEquitySecurityExchangeHours();
var securities = new SecurityManager(TimeKeeper);
var transactions = new SecurityTransactionManager(securities);
var portfolio = new SecurityPortfolioManager(securities, transactions);
portfolio.SetCash(1000);
securities.Add("AAPL", new QuantConnect.Securities.Equity.Equity(securityExchangeHours, CreateTradeBarDataConfig(SecurityType.Equity, "AAPL"), 1));
securities["AAPL"].SettlementModel = new DelayedSettlementModel(3, TimeSpan.FromHours(8));
Assert.AreEqual(0, securities["AAPL"].Holdings.Quantity);
Assert.AreEqual(1000, portfolio.Cash);
Assert.AreEqual(0, portfolio.UnsettledCash);
// Buy on Monday
var timeUtc = new DateTime(2015, 10, 26, 15, 30, 0);
var fill = new OrderEvent(1, "AAPL", timeUtc, OrderStatus.Filled, OrderDirection.Buy, 100, 10, 0);
portfolio.ProcessFill(fill);
Assert.AreEqual(10, securities["AAPL"].Holdings.Quantity);
Assert.AreEqual(-1, portfolio.Cash);
Assert.AreEqual(0, portfolio.UnsettledCash);
// Sell on Tuesday, cash unsettled
timeUtc = timeUtc.AddDays(1);
fill = new OrderEvent(2, "AAPL", timeUtc, OrderStatus.Filled, OrderDirection.Sell, 100, -10, 0);
portfolio.ProcessFill(fill);
Assert.AreEqual(0, securities["AAPL"].Holdings.Quantity);
Assert.AreEqual(-2, portfolio.Cash);
Assert.AreEqual(1000, portfolio.UnsettledCash);
// Thursday, still cash unsettled
timeUtc = timeUtc.AddDays(2);
portfolio.ScanForCashSettlement(timeUtc);
Assert.AreEqual(-2, portfolio.Cash);
Assert.AreEqual(1000, portfolio.UnsettledCash);
// Friday at open, cash settled
timeUtc = timeUtc.AddDays(1).Date.Add(securityExchangeHours.MarketHours[timeUtc.DayOfWeek].MarketOpen).ConvertToUtc(securityExchangeHours.TimeZone);
portfolio.ScanForCashSettlement(timeUtc);
Assert.AreEqual(998, portfolio.Cash);
Assert.AreEqual(0, portfolio.UnsettledCash);
}