本文整理汇总了C#中SecurityManager类的典型用法代码示例。如果您正苦于以下问题:C# SecurityManager类的具体用法?C# SecurityManager怎么用?C# SecurityManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SecurityManager类属于命名空间,在下文中一共展示了SecurityManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: QCAlgorithm
/********************************************************
* CLASS CONSTRUCTOR
*********************************************************/
/// <summary>
/// Initialise the Algorithm
/// </summary>
public QCAlgorithm()
{
//Initialise the Algorithm Helper Classes:
//- Note - ideally these wouldn't be here, but because of the DLL we need to make the classes shared across
// the Worker & Algorithm, limiting ability to do anything else.
Securities = new SecurityManager();
Transacions = new SecurityTransactionManager(Securities);
Portfolio = new SecurityPortfolioManager(Securities, Transacions);
//Initialise Data Manager
DataManager = new DataManager();
//Initialise Error and Order Holders:
Errors = new List<string>();
//Initialise Algorithm RunMode to Automatic:
_runMode = RunMode.Automatic;
//Initialise to unlocked:
_locked = false;
//Initialise Start and End Dates:
_startDate = new DateTime();
_endDate = new DateTime();
}
开发者ID:joyanta,项目名称:QCAlgorithm,代码行数:31,代码来源:Algorithm.cs
示例2: FundsAreSettledImmediately
public void FundsAreSettledImmediately()
{
var securities = new SecurityManager(TimeKeeper);
var transactions = new SecurityTransactionManager(securities);
var portfolio = new SecurityPortfolioManager(securities, transactions);
var model = new ImmediateSettlementModel();
var config = CreateTradeBarConfig();
var security = new Security(SecurityExchangeHoursTests.CreateUsEquitySecurityExchangeHours(), config);
portfolio.SetCash(1000);
Assert.AreEqual(1000, portfolio.Cash);
Assert.AreEqual(0, portfolio.UnsettledCash);
var timeUtc = Noon.ConvertToUtc(TimeZones.NewYork);
model.ApplyFunds(portfolio, security, timeUtc, "USD", 1000);
Assert.AreEqual(2000, portfolio.Cash);
Assert.AreEqual(0, portfolio.UnsettledCash);
model.ApplyFunds(portfolio, security, timeUtc, "USD", -500);
Assert.AreEqual(1500, portfolio.Cash);
Assert.AreEqual(0, portfolio.UnsettledCash);
model.ApplyFunds(portfolio, security, timeUtc, "USD", 1000);
Assert.AreEqual(2500, portfolio.Cash);
Assert.AreEqual(0, portfolio.UnsettledCash);
}
开发者ID:iorixyz,项目名称:Lean,代码行数:29,代码来源:ImmediateSettlementModelTests.cs
示例3: EachTradeableDay
/// <summary>
/// Define an enumerable Date Range:
/// </summary>
/// <param name="securities">Securities we have in portfolio</param>
/// <param name="from">start date</param>
/// <param name="thru">end date</param>
/// <returns>Enumerable Date Range:</returns>
public static IEnumerable<DateTime> EachTradeableDay(SecurityManager securities, DateTime from, DateTime thru)
{
for (var day = from.Date; day.Date <= thru.Date; day = day.AddDays(1)) {
if (Time.TradableDate(securities, day)) {
yield return day;
}
}
}
开发者ID:vdt,项目名称:QCAlgorithm,代码行数:15,代码来源:Time.cs
示例4: SecurityManager_CreateMockX509Certificate_Will_Create_Mock_Certificate_Test
public void SecurityManager_CreateMockX509Certificate_Will_Create_Mock_Certificate_Test()
{
SecurityManager manager = new SecurityManager();
MockX509Certificate cert = manager.CreateMockX509Certificate();
Confirm.Different(null, cert.PrivateKey);
Confirm.Different(null, cert.PublicKey);
}
开发者ID:thelgevold,项目名称:ExpressUnit,代码行数:8,代码来源:SecurityManagerTest.cs
示例5: SecurityTransactionManager
/// <summary>
/// Initialise the transaction manager for holding and processing orders.
/// </summary>
public SecurityTransactionManager(SecurityManager security)
{
//Private reference for processing transactions
_securities = security;
//Internal storage for transaction records:
_transactionRecord = new Dictionary<DateTime, decimal>();
}
开发者ID:bestwpw,项目名称:Lean,代码行数:11,代码来源:SecurityTransactionManager.cs
示例6: SellOnThursdaySettleOnTuesday
public void SellOnThursdaySettleOnTuesday()
{
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, new Cash(CashBook.AccountCurrency, 0, 1m), SymbolProperties.GetDefault(CashBook.AccountCurrency));
portfolio.SetCash(3000);
Assert.AreEqual(3000, portfolio.Cash);
Assert.AreEqual(0, portfolio.UnsettledCash);
// Sell on Thursday
var timeUtc = Noon.AddDays(3).ConvertToUtc(TimeZones.NewYork);
model.ApplyFunds(portfolio, security, timeUtc, "USD", 1000);
portfolio.ScanForCashSettlement(timeUtc);
Assert.AreEqual(3000, portfolio.Cash);
Assert.AreEqual(1000, portfolio.UnsettledCash);
// Friday, still unsettled
timeUtc = timeUtc.AddDays(1);
portfolio.ScanForCashSettlement(timeUtc);
Assert.AreEqual(3000, portfolio.Cash);
Assert.AreEqual(1000, portfolio.UnsettledCash);
// Saturday, still unsettled
timeUtc = timeUtc.AddDays(1);
portfolio.ScanForCashSettlement(timeUtc);
Assert.AreEqual(3000, portfolio.Cash);
Assert.AreEqual(1000, portfolio.UnsettledCash);
// Sunday, still unsettled
timeUtc = timeUtc.AddDays(1);
portfolio.ScanForCashSettlement(timeUtc);
Assert.AreEqual(3000, portfolio.Cash);
Assert.AreEqual(1000, portfolio.UnsettledCash);
// Monday, still unsettled
timeUtc = timeUtc.AddDays(1);
portfolio.ScanForCashSettlement(timeUtc);
Assert.AreEqual(3000, portfolio.Cash);
Assert.AreEqual(1000, portfolio.UnsettledCash);
// Tuesday 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);
// Tuesday at 8 AM, now settled
timeUtc = timeUtc.AddMinutes(5);
portfolio.ScanForCashSettlement(timeUtc);
Assert.AreEqual(4000, portfolio.Cash);
Assert.AreEqual(0, portfolio.UnsettledCash);
}
开发者ID:kaffeebrauer,项目名称:Lean,代码行数:57,代码来源:DelayedSettlementModelTests.cs
示例7: ScheduleManager
/// <summary>
/// Initializes a new instance of the <see cref="ScheduleManager"/> class
/// </summary>
/// <param name="securities">Securities manager containing the algorithm's securities</param>
/// <param name="timeZone">The algorithm's time zone</param>
public ScheduleManager(SecurityManager securities, DateTimeZone timeZone)
{
_securities = securities;
DateRules = new DateRules(securities);
TimeRules = new TimeRules(securities, timeZone);
// used for storing any events before the event schedule is set
_preInitializedEvents = new List<ScheduledEvent>();
}
开发者ID:skyfyl,项目名称:Lean,代码行数:14,代码来源:ScheduleManager.cs
示例8: SecurityTransactionManager
/********************************************************
* CLASS CONSTRUCTOR
*********************************************************/
/// <summary>
/// Initialise the Algorithm Transaction Class
/// </summary>
public SecurityTransactionManager(SecurityManager security)
{
//Private reference for processing transactions
this.Securities = security;
//Initialise the Order Caches:
this.ProcessedOrders = new Dictionary<int, Order>();
this.OutstandingOrders = new Dictionary<int, Order>();
}
开发者ID:vdt,项目名称:QCAlgorithm,代码行数:15,代码来源:SecurityTransactionManager.cs
示例9: SecurityTransactionManager
/********************************************************
* CLASS CONSTRUCTOR
*********************************************************/
/// <summary>
/// Initialise the Algorithm Transaction Class
/// </summary>
public SecurityTransactionManager(SecurityManager security)
{
//Private reference for processing transactions
this.Securities = security;
//Initialise the Order Cache -- Its a mirror of the TransactionHandler.
this._orders = new ConcurrentDictionary<int, Order>();
//Temporary Holding Queue of Orders to be Processed.
this.OrderQueue = new ConcurrentQueue<Order>();
}
开发者ID:nagyist,项目名称:QuantConnect-QCAlgorithm,代码行数:17,代码来源:SecurityTransactionManager.cs
示例10: TestCashFills
public void TestCashFills()
{
// this test asserts the portfolio behaves according to the Test_Cash algo, see TestData\CashTestingStrategy.csv
// also "https://www.dropbox.com/s/oiliumoyqqj1ovl/2013-cash.csv?dl=1"
const string fillsFile = "TestData\\test_cash_fills.xml";
const string equityFile = "TestData\\test_cash_equity.xml";
var fills = XDocument.Load(fillsFile).Descendants("OrderEvent").Select(x => new OrderEvent(
x.Get<int>("OrderId"),
SymbolMap[x.Get<string>("Symbol")],
DateTime.MinValue,
x.Get<OrderStatus>("Status"),
x.Get<int>("FillQuantity") < 0 ? OrderDirection.Sell
: x.Get<int>("FillQuantity") > 0 ? OrderDirection.Buy
: OrderDirection.Hold,
x.Get<decimal>("FillPrice"),
x.Get<int>("FillQuantity"),
0m)
).ToList();
var equity = XDocument.Load(equityFile).Descendants("decimal")
.Select(x => decimal.Parse(x.Value, CultureInfo.InvariantCulture))
.ToList();
Assert.AreEqual(fills.Count + 1, equity.Count);
// we're going to process fills and very our equity after each fill
var subscriptions = new SubscriptionManager(TimeKeeper);
var securities = new SecurityManager(TimeKeeper);
var security = new Security(SecurityExchangeHours, subscriptions.Add(CASH, Resolution.Daily, TimeZones.NewYork, TimeZones.NewYork), new Cash(CashBook.AccountCurrency, 0, 1m), SymbolProperties.GetDefault(CashBook.AccountCurrency));
security.SetLeverage(10m);
securities.Add(CASH, security);
var transactions = new SecurityTransactionManager(securities);
var portfolio = new SecurityPortfolioManager(securities, transactions);
portfolio.SetCash(equity[0]);
for (int i = 0; i < fills.Count; i++)
{
// before processing the fill we must deduct the cost
var fill = fills[i];
var time = DateTime.Today.AddDays(i);
TimeKeeper.SetUtcDateTime(time.ConvertToUtc(TimeZones.NewYork));
// the value of 'CASH' increments for each fill, the original test algo did this monthly
// the time doesn't really matter though
security.SetMarketPrice(new IndicatorDataPoint(CASH, time, i + 1));
portfolio.ProcessFill(fill);
Assert.AreEqual(equity[i + 1], portfolio.TotalPortfolioValue, "Failed on " + i);
}
}
开发者ID:aajtodd,项目名称:Lean,代码行数:51,代码来源:SecurityPortfolioManagerTests.cs
示例11: EnsureCurrencyDataFeedAddsSubscription
public void EnsureCurrencyDataFeedAddsSubscription()
{
const int quantity = 100;
const decimal conversionRate = 1 / 100m;
var cash = new Cash("JPY", quantity, conversionRate);
var subscriptions = new SubscriptionManager(TimeKeeper);
var abcConfig = subscriptions.Add(Symbols.SPY, Resolution.Minute, TimeZone, TimeZone);
var securities = new SecurityManager(TimeKeeper);
securities.Add(Symbols.SPY, new Security(SecurityExchangeHours, abcConfig, 1m));
cash.EnsureCurrencyDataFeed(securities, subscriptions, MarketHoursDatabase.AlwaysOpen);
Assert.AreEqual(1, subscriptions.Subscriptions.Count(x => x.Symbol == Symbols.USDJPY));
Assert.AreEqual(1, securities.Values.Count(x => x.Symbol == Symbols.USDJPY));
}
开发者ID:skyfyl,项目名称:Lean,代码行数:14,代码来源:CashTests.cs
示例12: AdminServer
private AdminServer()
{
_disposed = false;
_isRunning = false;
_securityManager = new SecurityManager();
_gameServerManager = new GameServerManager();
_connectionManager = new ConnectionManager();
_messageEngine = new MessageEngine();
_gameServerMonitor = new GameServerMonitor();
_automationManager = new AutomationManager();
_strategyManager = new StrategyManager();
_scheduledTaskManager = new ScheduledTaskManager();
_FTPClient = new FTPClient();
_batchTaskManager = new BatchTaskManager();
_paysysManager = new PaysysManager();
_ibShopManager = new IBShopManager();
}
开发者ID:viticm,项目名称:pap2,代码行数:17,代码来源:AdminServer.cs
示例13: SecurityTransactionManager
/// <summary>
/// Initialise the transaction manager for holding and processing orders.
/// </summary>
public SecurityTransactionManager(SecurityManager security)
{
//Private reference for processing transactions
_securities = security;
//Initialise the Order Cache -- Its a mirror of the TransactionHandler.
_orders = new ConcurrentDictionary<int, Order>();
//Temporary Holding Queue of Orders to be Processed.
_orderQueue = new ConcurrentQueue<Order>();
// Internal order events storage.
_orderEvents = new ConcurrentDictionary<int, List<OrderEvent>>();
//Interal storage for transaction records:
_transactionRecord = new Dictionary<DateTime, decimal>();
}
开发者ID:reddream,项目名称:Lean,代码行数:20,代码来源:SecurityTransactionManager.cs
示例14: NotifiesWhenSecurityAddedViaIndexer
public void NotifiesWhenSecurityAddedViaIndexer()
{
var timeKeeper = new TimeKeeper(new DateTime(2015, 12, 07));
var manager = new SecurityManager(timeKeeper);
var security = new Security(SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork), CreateTradeBarConfig(), new Cash(CashBook.AccountCurrency, 0, 1m), SymbolProperties.GetDefault(CashBook.AccountCurrency));
manager.CollectionChanged += (sender, args) =>
{
if (args.NewItems.OfType<object>().Single() != security)
{
Assert.Fail("Expected args.NewItems to have exactly one element equal to security");
}
else
{
Assert.IsTrue(args.Action == NotifyCollectionChangedAction.Add);
Assert.Pass();
}
};
manager[security.Symbol] = security;
}
开发者ID:kaffeebrauer,项目名称:Lean,代码行数:21,代码来源:SecurityManagerTests.cs
示例15: NotifiesWhenSecurityRemoved
public void NotifiesWhenSecurityRemoved()
{
var timeKeeper = new TimeKeeper(new DateTime(2015, 12, 07));
var manager = new SecurityManager(timeKeeper);
var security = new Security(SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork), CreateTradeBarConfig());
manager.Add(security.Symbol, security);
manager.CollectionChanged += (sender, args) =>
{
if (args.OldItems.OfType<object>().Single() != security)
{
Assert.Fail("Expected args.NewItems to have exactly one element equal to security");
}
else
{
Assert.IsTrue(args.Action == NotifyCollectionChangedAction.Remove);
Assert.Pass();
}
};
manager.Remove(security.Symbol);
}
开发者ID:iorixyz,项目名称:Lean,代码行数:22,代码来源:SecurityManagerTests.cs
示例16: EnsureCurrencyDataFeed
/// <summary>
/// Ensures that we have a data feed to conver this currency into the base currency.
/// This will add a subscription at the lowest resolution if one is not found.
/// </summary>
/// <param name="securities">The security manager</param>
/// <param name="subscriptions">The subscription manager used for searching and adding subscriptions</param>
/// <param name="exchangeHoursProvider">A security exchange hours provider instance used to resolve exchange hours for new subscriptions</param>
public void EnsureCurrencyDataFeed(SecurityManager securities, SubscriptionManager subscriptions, SecurityExchangeHoursProvider exchangeHoursProvider)
{
if (Symbol == CashBook.AccountCurrency)
{
SecuritySymbol = string.Empty;
_isBaseCurrency = true;
ConversionRate = 1.0m;
return;
}
if (subscriptions.Count == 0)
{
throw new InvalidOperationException("Unable to add cash when no subscriptions are present. Please add subscriptions in the Initialize() method.");
}
// we require a subscription that converts this into the base currency
string normal = Symbol + CashBook.AccountCurrency;
string invert = CashBook.AccountCurrency + Symbol;
foreach (var config in subscriptions.Subscriptions.Where(config => config.SecurityType == SecurityType.Forex))
{
if (config.Symbol == normal)
{
SecuritySymbol = config.Symbol;
return;
}
if (config.Symbol == invert)
{
SecuritySymbol = config.Symbol;
_invertRealTimePrice = true;
return;
}
}
// get the market from the first Forex subscription
string market = (from config in subscriptions.Subscriptions
where config.SecurityType == SecurityType.Forex
select config.Market).FirstOrDefault() ?? "fxcm";
// if we've made it here we didn't find a subscription, so we'll need to add one
var currencyPairs = Forex.Forex.CurrencyPairs;
var minimumResolution = subscriptions.Subscriptions.Min(x => x.Resolution);
var objectType = minimumResolution == Resolution.Tick ? typeof (Tick) : typeof (TradeBar);
foreach (var symbol in currencyPairs)
{
if (symbol == normal || symbol == invert)
{
_invertRealTimePrice = symbol == invert;
var exchangeHours = exchangeHoursProvider.GetExchangeHours(market, symbol, SecurityType.Forex);
// set this as an internal feed so that the data doesn't get sent into the algorithm's OnData events
var config = subscriptions.Add(objectType, SecurityType.Forex, symbol, minimumResolution, market, exchangeHours.TimeZone, true, false, true);
var security = new Forex.Forex(this, config, 1m);
SecuritySymbol = config.Symbol;
securities.Add(symbol, security);
Log.Trace("Cash.EnsureCurrencyDataFeed(): Adding " + symbol + " for cash " + Symbol + " currency feed");
return;
}
}
// if this still hasn't been set then it's an error condition
throw new ArgumentException(string.Format("In order to maintain cash in {0} you are required to add a subscription for Forex pair {0}{1} or {1}{0}", Symbol, CashBook.AccountCurrency));
}
开发者ID:dalebrubaker,项目名称:Lean,代码行数:68,代码来源:Cash.cs
示例17: ComputeMarginProperlyShortCoverZeroLong
public void ComputeMarginProperlyShortCoverZeroLong()
{
const decimal leverage = 2m;
const int amount = 1000;
const int quantity = (int)(amount * leverage);
var securities = new SecurityManager(TimeKeeper);
var transactions = new SecurityTransactionManager(securities);
var orderProcessor = new OrderProcessor();
transactions.SetOrderProcessor(orderProcessor);
var portfolio = new SecurityPortfolioManager(securities, transactions);
portfolio.CashBook["USD"].SetAmount(amount);
var config = CreateTradeBarDataConfig(SecurityType.Equity, Symbols.AAPL);
securities.Add(new Security(SecurityExchangeHours, config, new Cash(CashBook.AccountCurrency, 0, 1m), SymbolProperties.GetDefault(CashBook.AccountCurrency)));
var security = securities[Symbols.AAPL];
security.SetLeverage(leverage);
var time = DateTime.Now;
const decimal sellPrice = 1m;
security.SetMarketPrice(new TradeBar(time, Symbols.AAPL, sellPrice, sellPrice, sellPrice, sellPrice, 1));
var order = new MarketOrder(Symbols.AAPL, -quantity, time) { Price = sellPrice };
var fill = new OrderEvent(order, DateTime.UtcNow, 0) { FillPrice = sellPrice, FillQuantity = -quantity };
orderProcessor.AddOrder(order);
var request = new SubmitOrderRequest(OrderType.Market, security.Type, security.Symbol, order.Quantity, 0, 0, order.Time, null);
request.SetOrderId(0);
orderProcessor.AddTicket(new OrderTicket(null, request));
portfolio.ProcessFill(fill);
// we shouldn't be able to place a new short order
var newOrder = new MarketOrder(Symbols.AAPL, -1, time.AddSeconds(1)) { Price = sellPrice };
var sufficientCapital = transactions.GetSufficientCapitalForOrder(portfolio, newOrder);
Assert.IsFalse(sufficientCapital);
// we should be able to place cover to zero
newOrder = new MarketOrder(Symbols.AAPL, quantity, time.AddSeconds(1)) { Price = sellPrice };
sufficientCapital = transactions.GetSufficientCapitalForOrder(portfolio, newOrder);
Assert.IsTrue(sufficientCapital);
// now the stock doubles, so we should have negative margin remaining
time = time.AddDays(1);
const decimal highPrice = sellPrice * 2;
security.SetMarketPrice(new TradeBar(time, Symbols.AAPL, highPrice, highPrice, highPrice, highPrice, 1));
// we still shouldn be able to place cover to zero
newOrder = new MarketOrder(Symbols.AAPL, quantity, time.AddSeconds(1)) { Price = highPrice };
sufficientCapital = transactions.GetSufficientCapitalForOrder(portfolio, newOrder);
Assert.IsTrue(sufficientCapital);
// we shouldn't be able to place cover to long
newOrder = new MarketOrder(Symbols.AAPL, quantity + 1, time.AddSeconds(1)) { Price = highPrice };
sufficientCapital = transactions.GetSufficientCapitalForOrder(portfolio, newOrder);
Assert.IsFalse(sufficientCapital);
}
开发者ID:aajtodd,项目名称:Lean,代码行数:55,代码来源:SecurityPortfolioManagerTests.cs
示例18: DateRules
/// <summary>
/// Initializes a new instance of the <see cref="DateRules"/> helper class
/// </summary>
/// <param name="securities">The security manager</param>
public DateRules(SecurityManager securities)
{
_securities = securities;
}
开发者ID:nooperpudd,项目名称:Lean,代码行数:8,代码来源:DateRules.cs
示例19: 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);
}
开发者ID:aajtodd,项目名称:Lean,代码行数:46,代码来源:SecurityPortfolioManagerTests.cs
示例20: ForexFillUpdatesCashCorrectly
public void ForexFillUpdatesCashCorrectly()
{
var securities = new SecurityManager(TimeKeeper);
var transactions = new SecurityTransactionManager(securities);
var portfolio = new SecurityPortfolioManager(securities, transactions);
portfolio.SetCash(1000);
portfolio.CashBook.Add("EUR", 0, 1.1000m);
securities.Add(Symbols.EURUSD, new QuantConnect.Securities.Forex.Forex(SecurityExchangeHours, portfolio.CashBook["USD"], CreateTradeBarDataConfig(SecurityType.Forex, Symbols.EURUSD), SymbolProperties.GetDefault(CashBook.AccountCurrency)));
var security = securities[Symbols.EURUSD];
Assert.AreEqual(0, security.Holdings.Quantity);
Assert.AreEqual(1000, portfolio.Cash);
var orderFee = security.FeeModel.GetOrderFee(security, new MarketOrder(Symbols.EURUSD, 100, DateTime.MinValue));
var fill = new OrderEvent(1, Symbols.EURUSD, DateTime.MinValue, OrderStatus.Filled, OrderDirection.Buy, 1.1000m, 100, orderFee);
portfolio.ProcessFill(fill);
Assert.AreEqual(100, security.Holdings.Quantity);
Assert.AreEqual(998, portfolio.Cash);
Assert.AreEqual(100, portfolio.CashBook["EUR"].Amount);
Assert.AreEqual(888, portfolio.CashBook["USD"].Amount);
}
开发者ID:aajtodd,项目名称:Lean,代码行数:21,代码来源:SecurityPortfolioManagerTests.cs
注:本文中的SecurityManager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论