本文整理汇总了C#中SecurityManager.Update方法的典型用法代码示例。如果您正苦于以下问题:C# SecurityManager.Update方法的具体用法?C# SecurityManager.Update怎么用?C# SecurityManager.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SecurityManager
的用法示例。
在下文中一共展示了SecurityManager.Update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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"),
x.Get<string>("Symbol"),
x.Get<OrderStatus>("Status"),
x.Get<decimal>("FillPrice"),
x.Get<int>("FillQuantity"))
).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);
securities.Add("CASH", new Security(SecurityExchangeHours.AlwaysOpen, subscriptions.Add(SecurityType.Base, "CASH", Resolution.Daily, "usa", TimeZones.NewYork), leverage: 10));
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);
// the value of 'CASH' increments for each fill, the original test algo did this monthly
// the time doesn't really matter though
var updateData = new Dictionary<int, List<BaseData>>();
updateData.Add(0, new List<BaseData> {new IndicatorDataPoint("CASH", time, i + 1)});
securities.Update(time, updateData);
portfolio.ProcessFill(fill);
Assert.AreEqual(equity[i + 1], portfolio.TotalPortfolioValue, "Failed on " + i);
}
}
示例2: ForexCashFills
public void ForexCashFills()
{
// this test asserts the portfolio behaves according to the Test_Cash algo, but for a Forex security,
// see TestData\CashTestingStrategy.csv; also "https://www.dropbox.com/s/oiliumoyqqj1ovl/2013-cash.csv?dl=1"
const string fillsFile = "TestData\\test_forex_fills.xml";
const string equityFile = "TestData\\test_forex_equity.xml";
const string mchQuantityFile = "TestData\\test_forex_fills_mch_quantity.xml";
const string jwbQuantityFile = "TestData\\test_forex_fills_jwb_quantity.xml";
var fills = XDocument.Load(fillsFile).Descendants("OrderEvent").Select(x => new OrderEvent(
x.Get<int>("OrderId"),
x.Get<string>("Symbol"),
x.Get<OrderStatus>("Status"),
x.Get<decimal>("FillPrice"),
x.Get<int>("FillQuantity"))
).ToList();
var equity = XDocument.Load(equityFile).Descendants("decimal")
.Select(x => decimal.Parse(x.Value, CultureInfo.InvariantCulture))
.ToList();
var mchQuantity = XDocument.Load(mchQuantityFile).Descendants("decimal")
.Select(x => decimal.Parse(x.Value, CultureInfo.InvariantCulture))
.ToList();
var jwbQuantity = XDocument.Load(jwbQuantityFile).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 transactions = new SecurityTransactionManager(securities);
var portfolio = new SecurityPortfolioManager(securities, transactions);
portfolio.SetCash(equity[0]);
portfolio.CashBook.Add("MCH", mchQuantity[0], 0);
portfolio.CashBook.Add("JWB", jwbQuantity[0], 0);
var jwbCash = portfolio.CashBook["JWB"];
var mchCash = portfolio.CashBook["MCH"];
var usdCash = portfolio.CashBook["USD"];
var mchJwbSecurity = new QuantConnect.Securities.Forex.Forex(SecurityExchangeHours.AlwaysOpen, jwbCash, subscriptions.Add(SecurityType.Forex, "MCHJWB", Resolution.Minute, "fxcm", TimeZones.NewYork), leverage: 10);
var mchUsdSecurity = new QuantConnect.Securities.Forex.Forex(SecurityExchangeHours.AlwaysOpen, usdCash, subscriptions.Add(SecurityType.Forex, "MCHUSD", Resolution.Minute, "fxcm", TimeZones.NewYork), leverage: 10);
var usdJwbSecurity = new QuantConnect.Securities.Forex.Forex(SecurityExchangeHours.AlwaysOpen, mchCash, subscriptions.Add(SecurityType.Forex, "USDJWB", Resolution.Minute, "fxcm", TimeZones.NewYork), leverage: 10);
// no fee model
mchJwbSecurity.TransactionModel = new SecurityTransactionModel();
mchUsdSecurity.TransactionModel = new SecurityTransactionModel();
usdJwbSecurity.TransactionModel = new SecurityTransactionModel();
securities.Add(mchJwbSecurity);
securities.Add(usdJwbSecurity);
securities.Add(mchUsdSecurity);
portfolio.CashBook.EnsureCurrencyDataFeeds(securities, subscriptions, SecurityExchangeHoursProvider.FromDataFolder());
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);
// the value of 'MCJWB' increments for each fill, the original test algo did this monthly
// the time doesn't really matter though
decimal mchJwb = i + 1;
decimal mchUsd = (i + 1)/(i + 2m);
decimal usdJwb = i + 2;
Assert.AreEqual((double)mchJwb, (double)(mchUsd*usdJwb), 1e-10);
//Console.WriteLine("Step: " + i + " -- MCHJWB: " + mchJwb);
var updateData = new Dictionary<int, List<BaseData>>();
updateData.Add(0, new List<BaseData> {new IndicatorDataPoint("MCHJWB", time, mchJwb)});
updateData.Add(1, new List<BaseData> {new IndicatorDataPoint("MCHUSD", time, mchUsd)});
updateData.Add(2, new List<BaseData> {new IndicatorDataPoint("JWBUSD", time, usdJwb)});
securities.Update(time, updateData);
portfolio.CashBook.Update(updateData);
portfolio.ProcessFill(fill);
//Console.WriteLine("-----------------------");
//Console.WriteLine(fill);
//Console.WriteLine("Post step: " + i);
//foreach (var cash in portfolio.CashBook)
//{
// Console.WriteLine(cash.Value);
//}
//Console.WriteLine("CashValue: " + portfolio.CashBook.TotalValueInAccountCurrency);
Console.WriteLine(i + 1 + " " + portfolio.TotalPortfolioValue.ToString("C"));
//Assert.AreEqual((double) equity[i + 1], (double)portfolio.TotalPortfolioValue, 2e-2);
Assert.AreEqual((double) mchQuantity[i + 1], (double)portfolio.CashBook["MCH"].Quantity);
Assert.AreEqual((double) jwbQuantity[i + 1], (double)portfolio.CashBook["JWB"].Quantity);
//Console.WriteLine();
//Console.WriteLine();
}
//.........这里部分代码省略.........