If it helps any, in answer to my original question(s), Sergey kindly gave me some sample calculations that he used to test the API. From those couple of examples, I concluded the following (Anton or Sergey, please correct me if I'm wrong).
Here's how I explained the many API calls to myself:
Portfolios are modeled with several pieces (chunks of cash or value). There are three main pieces to the account:
• PositionValue – the amount of equity in open positions
• AccountValue – the amount of cash NOT in open positions
• DebtValue – the amount of liabilities borrowed on margin
Various combinations of these three basic values can be accessed by the following API calls:
• GetPositionValue gets the value of all open positions
• GetAccountValue gets the dollar value of cash not in open positions.
• GetValue gets the value of the assets = GetPositionValue + GetAccountValue.
• GetDebtValue = value of account debt liabilities (margin used)
• GetTotalEquity gets the dollar value of everything (GetValue – GetDebtValue)
Finally, GetCoreEquity seems to be a duplicate for GetAccountValue.
• GetCoreEquity gets the dollar value of cash not in open positions.
If I was to rename some API calls for better clarity, I would replace 'Account' with 'Cash' in all the GetAccountXXX calls, to give GetPositionValue, GetCashValue, GetDebtValue, because Position, Cash, and Debt are all very clear compared to Account. For example, does the Account value mean Net Liquidation Value (everything included), or Positions and Cash only, or maybe Debt included too? I think the use of the word Account is the source of almost all of the confusion.
The other source of confusion for me was the use of the word Net in some of the API calls. I could never intuitively figure out if Net meant "commissions included" or "commissions not included". If it was me, I would keep Net out of all API names except one, which could be used to fetch GetCommissionsExpense (or something like that), and then let users decide to add/subtract it from the numbers that they wanted to calculate.
Here's the code that I now use to watch for a daily profit target. It captures the account value (my definition of account value includes everything) at the BOD (beginning of day), and then compares the PnL on every bar. If the account reaches its daily profit target, the strategy quits for the day.
Code:
/// <summary>
/// Initialize the structure at BOD beginning of day.
/// </summary>
public void
InitAtBOD () {
// reset all variables
m_AcctBOD = me.Portfolio.GetTotalEquity ();
}
// get current profit at the arrival of each new bar
public double AcctPnl {
get { return (me.Portfolio.GetTotalEquity () - m_AcctBOD); }
}
// quit trading if daily profit target was reached
// calculate current daily profit
double profit = AcctPnl;
// quit for the day if profit target has been reached
if (profit >= ProfitLimitPerDay) {
fmt = "{0} Reached daily profit target. {1}";
Console.WriteLine (fmt, BD (bar), ProfitLimitPerDay);
.. shut down the strategy
}