本文整理汇总了C#中Position.ToTrade方法的典型用法代码示例。如果您正苦于以下问题:C# Position.ToTrade方法的具体用法?C# Position.ToTrade怎么用?C# Position.ToTrade使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Position
的用法示例。
在下文中一共展示了Position.ToTrade方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Adjust
// returns any closed PL calculated on position basis (not per share)
/// <summary>
/// Adjusts the position by applying a new position.
/// </summary>
/// <param name="pos">The position adjustment to apply.</param>
/// <returns></returns>
public decimal Adjust(Position pos)
{
if ((_sym!="") && (this.Symbol != pos.Symbol)) throw new Exception("Failed because adjustment symbol did not match position symbol");
if (_acct == "") _acct = pos.Account;
if (_acct != pos.Account) throw new Exception("Failed because adjustment account did not match position account.");
if ((_sym=="") && pos.isValid) _sym = pos.Symbol;
if (!pos.isValid) throw new Exception("Invalid position adjustment, existing:" + this.ToString() + " adjustment:" + pos.ToString());
if (pos.isFlat) return 0; // nothing to do
bool oldside = isLong;
decimal pl = Calc.ClosePL(this,pos.ToTrade());
if (this.isFlat) this._price = pos.AvgPrice; // if we're leaving flat just copy price
else if ((pos.isLong && this.isLong) || (!pos.isLong && !this.isLong)) // sides match, adding so adjust price
this._price = ((this._price * this._size) + (pos.AvgPrice * pos.Size)) / (pos.Size+ this.Size);
this._size += pos.Size; // adjust the size
if (oldside != isLong) _price = pos.AvgPrice; // this is for when broker allows flipping sides in one trade
if (this.isFlat) _price = 0; // if we're flat after adjusting, size price back to zero
_closedpl += pl; // update running closed pl
return pl;
}
示例2: GotPosition
/// <summary>
/// pass new positions as they arrive
/// </summary>
/// <param name="p"></param>
public void GotPosition(Position p)
{
if (p.isFlat)
return;
fills.Add(p.ToTrade());
}
示例3: GotPosition
/// <summary>
/// pass new positions as they arrive
/// </summary>
/// <param name="p"></param>
public void GotPosition(Position p)
{
fills.Add(p.ToTrade());
}