本文整理汇总了C#中Position.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Position.ToString方法的具体用法?C# Position.ToString怎么用?C# Position.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Position
的用法示例。
在下文中一共展示了Position.ToString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClosePT
// these are for calculating closed pl
// they do not adjust positions themselves
/// <summary>
/// Gets the closed PL on a per-share basis, ignoring how many shares are held.
/// </summary>
/// <param name="existing">The existing position.</param>
/// <param name="closing">The portion of the position that's being closed/changed.</param>
/// <returns></returns>
public static decimal ClosePT(Position existing, Trade adjust)
{
if (!existing.isValid || !adjust.isValid)
throw new Exception("Invalid position provided. (existing:" + existing.ToString() + " adjustment:" + adjust.ToString());
if (existing.isFlat) return 0; // nothing to close
if (existing.isLong == adjust.side) return 0; // if we're adding, nothing to close
return existing.isLong ? adjust.xprice- existing.AvgPrice: existing.AvgPrice- adjust.xprice;
}
示例2: 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;
}
示例3: ToString
/// <summary>
/// Describes a ship
/// </summary>
/// <returns>String description of a ship</returns>
public override string ToString()
{
Position endPosition = new Position();
if (Orientation == Orientation.Horizontal)
{
endPosition.Row = Position.Row;
endPosition.Column = Position.Column + Size - 1;
}
else
{
endPosition.Row = Position.Row + Size - 1;
endPosition.Column = Position.Column;
}
return String.Format("{0} {1} {2}", Code, Position.ToString(), endPosition.ToString());
}
示例4: tl_gotPosition
void tl_gotPosition(Position pos)
{
debug("pos: " + pos.ToString());
pt.Adjust(pos);
int[] rows = new int[0];
if (symidx.TryGetValue(pos.Symbol, out rows))
{
foreach (int r in rows)
{
qt.Rows[r]["AvgPrice"] = pos.AvgPrice.ToString(_dispdecpointformat);
qt.Rows[r]["PosSize"] = pos.Size.ToString();
qt.Rows[r]["ClosedPL"] = pos.ClosedPL.ToString(_dispdecpointformat);
}
}
}
示例5: GetFactors
public static void GetFactors(
Position position,
out double fgfactor,
out double tpfactor,
out double ftfactor,
out double orebfactor,
out double rebfactor,
out double astfactor,
out double stlfactor,
out double blkfactor,
out double ptsfactor,
out double ftrfactor)
{
if (position.ToString().EndsWith("G"))
{
fgfactor = 0.443707;
tpfactor = 0.361878;
ftfactor = 0.813468;
orebfactor = 0.800345;
rebfactor = 3.539908;
astfactor = 4.999772;
stlfactor = 1.251853;
blkfactor = 0.245448;
ptsfactor = 15.35178;
ftrfactor = 0.253303;
}
else if (position.ToString().EndsWith("F"))
{
fgfactor = 0.476727;
tpfactor = 0.346698;
ftfactor = 0.757107;
orebfactor = 1.982639;
rebfactor = 6.986424;
astfactor = 2.329346;
stlfactor = 0.964269;
blkfactor = 0.856456;
ptsfactor = 15.5138;
ftrfactor = 0.2671;
}
else if (position.ToString().EndsWith("C"))
{
fgfactor = 0.505723;
tpfactor = 0.261248;
ftfactor = 0.670934;
orebfactor = 2.115109;
rebfactor = 6.527221;
astfactor = 1.093232;
stlfactor = 0.531171;
blkfactor = 1.304965;
ptsfactor = 9.309844;
ftrfactor = 0.276999;
}
else
{
fgfactor = 0.474997;
tpfactor = 0.352848;
ftfactor = 0.769459;
orebfactor = 1.762842;
rebfactor = 6.640311;
astfactor = 3.901761;
stlfactor = 1.147817;
blkfactor = 0.899758;
ptsfactor = 17.78004;
ftrfactor = 0.290733;
}
}
示例6: ExpectedTokenNotFoundException
internal ExpectedTokenNotFoundException(string token, string foundToken, Position position)
: base("Expected: '" + token + "' but found: '" + foundToken + "' at " + position.ToString())
{
}
示例7: Print
public void Print(Position row, Position column, byte[] buffer, int offset, int count)
{
SetCursorPosition(int.Parse(column.ToString()), int.Parse(row.ToString()));
Write(buffer, offset, count);
}
示例8: bestReturnStrategySimulationMenuItem_Click
private void bestReturnStrategySimulationMenuItem_Click(object sender, EventArgs e)
{
int maxPositions = 2;
float maxPositionValue = 10000f;
string portofolioName = "BestReturn";
float portofolioValue = 10000;
float cashValue = portofolioValue;
#region CreatePortofolio
// Create new simulation portofolio
if (CurrentPortofolio == null)
{
CurrentPortofolio = this.StockPortofolioList.Find(p => p.Name == portofolioName);
if (CurrentPortofolio == null)
{
CurrentPortofolio = new StockPortofolio(portofolioName);
CurrentPortofolio.IsSimulation = true;
CurrentPortofolio.TotalDeposit = portofolioValue;
this.StockPortofolioList.Add(CurrentPortofolio);
}
}
#endregion
StockSerie referenceSerie = this.StockDictionary["CAC40"];
referenceSerie.Initialise();
referenceSerie.BarDuration = StockSerie.StockBarDuration.Monthly;
List<StockSerie> stockSeries =
this.StockDictionary.Values.Where(s => s.BelongsToGroup(StockSerie.Groups.CAC40) && s.Initialise()).ToList();
// Switch to monthly values
foreach (StockSerie serie in stockSeries)
{
serie.BarDuration = StockSerie.StockBarDuration.Monthly;
}
DateTime startDate = referenceSerie.Keys.First();
List<StockDailyValue> values = new List<StockDailyValue>();
List<Position> portofolio = new List<Position>();
DateTime lastDate = referenceSerie.Keys.Last();
foreach (DateTime date in referenceSerie.Keys)
{
StockLog.Write(date.ToShortDateString());
values.Clear();
// Find matching values
foreach (StockSerie serie in stockSeries)
{
int index = serie.IndexOf(date);
if (index > 0)
{
values.Add(serie[date]);
}
}
// Select positives + order by return
List<StockDailyValue> selectedValues =
values.Where(s => s.VARIATION > 0).OrderByDescending(s => s.VARIATION).ToList();
// Close not listed names.
foreach (Position pos in portofolio.Where(p => float.IsNaN(p.Close)))
{
if (!selectedValues.Any(s => s.NAME == pos.Name))
{
cashValue += pos.EndPosition(stockSeries.First(s => s.StockName == pos.Name)[date].OPEN);
portofolioValue += pos.Gain;
StockLog.Write("Selling: " + pos.ToString() + " gain: " + pos.Gain.ToString());
}
else
{
selectedValues.RemoveAll(s => s.NAME == pos.Name);
}
}
// Open new positions
int openPositionsCount = portofolio.Count(p => p.IsOpened);
int candidateCount = selectedValues.Count();
int nbPositionsToOpen = maxPositions - openPositionsCount;
float consumedCash = 0;
for (int i = 0; i < nbPositionsToOpen && i < candidateCount; i++)
{
StockDailyValue value = selectedValues[i];
int size = (int)((Math.Min(cashValue / nbPositionsToOpen, maxPositionValue)) / value.CLOSE);
Position pos = new Position(value.NAME, value.CLOSE, size);
portofolio.Add(pos);
consumedCash = value.CLOSE * size;
StockLog.Write("Buying: " + pos.ToString() + " at: " + pos.Open.ToString());
}
cashValue -= consumedCash;
if (date == lastDate)
//.........这里部分代码省略.........