Is there any simple method to purchase stock by its total value rather than specifying a quantity of shares? E.g. BTO $5000 of stock A rather than an order for 384 shares? Preferably through an API?
Hi, Hal - I’m afraid there is no way to do that currently, but I’ll look into adding it in the near future.
Good to hear. Can you clarify ‘near future’?
Since there’s currently no way to do this, is there a way to obtain the market quotes in the API so I can do the approximate calculations manually? When entering signals manually on the website, a delayed market quote is displayed before the signal is entered. It would be great if there were some sort of way to view this delayed market quote using an API (perhaps there is, I’ve only been working in depth with the signal entry API thus far). What about exchange rates so the above can be calculated for foreign market orders? Would be very helpful for systems based on portfolio weightings.
Another quick question. I noticed last night when I was attempting to familiarise myself with the accounts that are used by C2 that my trades didn’t seem to work the way that I’ve seen you post in the forums. In your posts about buy power and cash, you’ve mentioned that purchases on stock >$5 can be margined so that half comes out of cash and the other half buy power, with shorting having similar rules. My purchases were all in the European markets (because they happened to be open at the time!), I assume that foreign purchases can’t be margined?
Sorry, this is getting off topic, but Hal raised a point that is of interest to me. How does one go about making a purchase that uses some margin buying power and some cash? I’m not even sure what keywords on which to search that would get me more information.
To be honest, I do not know what "near future" means. Probably within a month or two, perhaps radically less. But I am unable to commit strongly to any date.
Regarding your other question: You are correct. While C2 automatically uses "margin" in the C2 Model Account for U.S. stocks above $5, we do not use any for non-USA stocks at this time.
This happens automatically when your system’s C2 Model Account buys any U.S. stock that is greater than $5. For example, imagine your model account starts with $1,000. You tell C2 to BUY 100 shares of XYZ @ $8 per share.
You will see the following happen to your model account:
Your cash will be reduced by $400 dollars.
Your “margin used” will be increased by $400.
You will own $800 worth of stock (100 shares).
Sorry, I wasn’t clear. Can I to do this in my Interactive Brokers account?
I’m not sure I understand. Can you do what at IB? Use margin? If your account is set up to use margin, then yes, you will. Remember how C2 works: we just send a trade into your account. How much margin it uses in your account, and how much margin you have left after the trade, is determined solely by your broker and the way you have established your account.
I meant use a portion of buying power and a portion of cash for a purchase, eventho there is enough cash in the account for the entire purchase. One of my IB accounts is set up for margin trading, but I couldn’t find any way to buy on margin before I’ve used all my cash for other purchases. If IB doesn’t allow this, I don’t see how a C2 model could force a purchase using buying power when there is sufficient cash in the account.
Related to my original question:
I’m developing a system that uses portfolio weightings to allocate shares. These weightings are with respect to the total value of the account. In C2, this seems to be the Total System Equity that I can see under Model Account Status on my systems page.
I started programming away and realised that the getsystemhypothetical method actually returns buy power as totalequityavail rather than returning total system equity (which I assume it was originally supposed to return, since there is a separate getbuypower command).
Is there any way to get the total system equity using either the signal entry API or the C2DS API?
I seem to get around the right figure if I use Total System Equity = startingcash+dollarwin-dollarloss, but I’m hesitant to use this as I’m not sure if it’s taking into account transaction costs or if these dollarwin and dollarloss values reset from day to day.
The way C2’s Model Account uses margin is something of a simplification, but I think it can be safely filed under “Good Enough.” When you buy a U.S. stock in your C2 Model account, you automatically use 2:1 leverage (i.e. you “borrow” half the purchase price and thus only spend 50% of the value of the stock using your Model Account cash.) So your cash is deducted by 50% of the purchase price, and then the bucket we rather messily call “margin used” is increased by 50% of the purchase price.
That bucket, “margin used,” is the same bucket into which we toss other kinds of margin or surety, too. So, for example, if you also trade futures contracts, the good-faith deposit required by the exchange (called “margin,” too) is added to that “margin used” bucket when you hold a futures position.
Ultimately, your Model Account value (cash + equity - margin used) must stay positive. A negative balance means you’re using too much margin (or don’t have enough cash), and a C2 margin call will be triggered.
This entire description talks about the C2 Model Account, a purely imaginary thing that exists only at C2. Your broker account, which is quite real, obviously, will be different. The way that C2 handles margin is not exactly how the real-world works, but it’s a pretty good approximation. The main difference is that in the real world, there is no universal account containing multiple instruments. You have a futures account and you have an equity account, and you can borrow against one, or are required to put up a surety against the other. Some brokers hide this fact by presenting a “universal” account in their user interface, but behind the scenes they are two separate accounts.
Anyway, this is all a long-winded way of saying that when you buy stocks in your imaginary C2 Model Account, C2 automatically lets you borrow (interest free, at that) half the purchase price. You need only “spend” cash in the amount of 50% of the purchase.
Your real-life IB account may work differently.
Hal - Give me a minute to stare at the code and see which API call returns what. I’ll be back with a solution shortly.
OK, Hal - I made a few changes in response to your question/request.
First, if you use the C2ATI and call getsystemhypo, we’ve added two new fields to the XML response. They are:
These return the total system equity value you are looking for (effectively the latest point on the big equity chart on the system page), along with the Unix Epoch timestamp that this value was last updated.
There is also a separate, new API call in the Signal Entry API which returns the same exact information. The new call is called getystemequity and you can read about it in the Signal Entry API documentation ( http://www.collective2.com/content/automation.htm ).
Thanks! That’s a big help.
Any chance it could be added to the C2DS getsystemoverview also? It seems to be more comprehensive than the hypothetical system command in the signal entry API. Having everything in the one place could be really helpful.
Per your request, I have made the total system equity value available in the C2 Data Services API (C2DS API).
You’ll find it in the <margin/> node, labeled as <totalSystemValue/>.
This is the same value you would get by calling the getsystemequity command available in the Signal Entry API.
Hal - This feature (ability for you to specify order quantity as a dollar value instead of number of shares) is now available to API software developers. (It is not yet available in the Web-based order entry screen, but we’ll look into adding that later.)
You can learn more here:
Note also that we added the ability to specify order size as a percentage of C2 Model Account, as well.
Wow, thanks for making all those changes.
A few quick points.
The accountpercent function doesn’t seem to take the exchange rate of foreign stocks into account.
totalSystemValue from the C2DS Api and the getsystemequity functions both seem to give values different to total system equity that is displayed on the website. This is true even when all my positions are closed (and the signals to close these positions should have caused a recalculation of all model parameters, yes?)
It is however closer to the value calculated by taking the starting cash and addding and subtracting all the profits and losses of each position (but not exact).
While of course it’s possible that the new feature is wrong or has some design flaw, your theory about exchange rate doesn’t really seem possible. Let me tell you basically how the “getsystemequity” function works. It takes the right-most Y value of your system equity chart. So, if your system equity chart is correct, then the getsystemequity function should be correct, too.
That’s why I will ask you to give me more specific details about what you think is wrong and why you think so. You write: “totalSystemValue from the C2DS Api and the getsystemequity functions both seem to give values different to total system equity that is displayed on the website.” Can you email or post the specific values you are getting, the associated time stamps, and of course the system id in question, and I will look at it and try to see what is going on.
Ah, I notice now that the system equity chart doesn’t seem to be updating. I’ve been performing a large number of fake trades to ensure that my interface is sending the correct signals to the API, so the model account status numbers have been changing constantly. But the system equity chart on my systems page (69237871) is constant at 99732.
This is the value I’ve been receiving all day as opposed to the total system equity that is seen in model account status (which at the time of this post is 99833).
I’m guessing that the system equity chart just doesn’t update as often?