31 public event EventHandler<SecurityHoldingQuantityChangedEventArgs>
QuantityChanged;
34 private bool _invested;
35 private decimal _averagePrice;
36 private decimal _quantity;
37 private decimal _price;
38 private decimal _totalSaleVolume;
39 private decimal _profit;
40 private decimal _lastTradeProfit;
41 private decimal _totalFees;
42 private decimal _totalDividends;
57 _currencyConverter = currencyConverter;
66 _security = holding._security;
67 _averagePrice = holding._averagePrice;
69 _price = holding._price;
70 _totalSaleVolume = holding._totalSaleVolume;
71 _profit = holding._profit;
72 _lastTradeProfit = holding._lastTradeProfit;
73 _totalFees = holding._totalFees;
74 _currencyConverter = holding._currencyConverter;
103 return _averagePrice;
107 _averagePrice = value;
126 _invested = Math.Abs(value) >= _security.SymbolProperties.LotSize;
149 return _security.Type;
160 return _security.BuyingPowerModel.GetLeverage(_security);
190 public virtual decimal
Price
267 get {
return _totalSaleVolume; }
275 get {
return _totalFees; }
283 get {
return _totalDividends; }
290 public virtual bool IsLong
329 return _lastTradeProfit;
337 public virtual decimal
Profit
339 get {
return _profit + _totalDividends; }
381 _totalFees += newFee;
390 _profit += profitLoss;
399 _totalSaleVolume += saleValue;
408 _totalDividends += dividend;
417 _lastTradeProfit = lastTradeProfit;
423 public virtual void SetHoldings(decimal averagePrice,
int quantity)
431 public virtual void SetHoldings(decimal averagePrice, decimal quantity)
433 var previousQuantity = _quantity;
434 var previousAveragePrice = _averagePrice;
437 _averagePrice = averagePrice;
448 _price = closingPrice;
471 var amount = price * quantity * _security.SymbolProperties.ContractMultiplier;
479 public virtual decimal
TotalCloseProfit(
bool includeFees =
true, decimal? exitPrice =
null, decimal? entryPrice =
null, decimal? quantity =
null)
481 var quantityToUse = quantity ??
Quantity;
482 if (quantityToUse == 0)
488 var orderFee =
Extensions.
GetMarketOrderFees(_security, -quantityToUse, _security.LocalTime.ConvertToUtc(_security.Exchange.TimeZone), out var marketOrder);
490 var feesInAccountCurrency = 0m;
493 feesInAccountCurrency = _currencyConverter.ConvertToAccountCurrency(orderFee).Amount;
496 var price = marketOrder.Direction ==
OrderDirection.Sell ? _security.BidPrice : _security.AskPrice;
501 price = _security.Price;
506 return potentialExitValue - entryValue - feesInAccountCurrency;
520 protected virtual void OnQuantityChanged(decimal previousAveragePrice, decimal previousQuantity)
523 _security, previousAveragePrice, previousQuantity