Profile Picture

Not Enough Cash

Posted By thinkjohn 3 Years Ago
Message
Posted Thursday June 19 2014
Hello,

I have coded a trading system that exits one position and enters another on the same day at the close. Since I am using the entire account value, I get the not enough cash warning and trades are being cancelled.

If I set the Paper Broker "Account Margin Factor" to a high enough number, the warnings and cancellations are avoided.

This is fine for me because it is only for analysis.

My problem is that I have several trading systems that would be affected by this change because it is a GLOBAL setting in RightEdge for the Paper Broker Service. It is set for any trading system you run in RightEdge with that Paper Broker service.

I would rather just change it for this one trading system. Is there an example of how to set this value in code? I do not want to build a new service for this one setting, I would like to just set it in the startup event.

Thanks,
John

Posted Friday June 20 2014
I second that it should be a system level setting not a global setting.


Posted Friday June 20 2014
I have the same problem but it has nothing to do with RightEdge software.

Seriously, this issue should be fixed on the broker at a minimum because these errors should not be happening globally because they would not with an appropriate broker account.

Once set in the broker, reducing margin for a specific trading system is straightforward. I created a method, in a separate library, which handles opening positions. Add the margin amount to a property on a position settings Tag and account for it in the method.

Duane
Posted Sunday June 22 2014
John and Kaizen,

Attached is a system that shows how you can set the paper broker account margin factor in your system's Startup code. It uses reflection to get at things that the trading system wouldn't normally have access to, so there's no guarantee that it will work in future versions of RightEdge, but I think it will be helpful.

Duane,

I didn't quite follow you. The account margin factor is for the RightEdge paper broker plugin. Are you saying you use a custom broker plugin that is more sophisticated in the way it handles the margins, or that you just set this to a high number and keep track of the margin yourself in a common library you use, or what?

Thanks,
Daniel9

Attachments
SetAccountMargin.cs (260 views, 2.00 KB)
Posted Tuesday June 24 2014
This worked. Thanks...
Posted Wednesday June 25 2014
Daniel,

I do not use a custom broker for testing (I do but not for the purposes of account margin). Instead, I’ve abstracted the order placement into a custom method in which I pass to this method variables via a custom tag on each position settings. This method is then responsible for correctly determining the allocation and method based on the variables on the custom tag. Obviously, the allocation method, amount, etc. can be customized per order/system. Part of the allocation process is determining the amount of cash available before setting the allocation.

Setting the account margin to an arbitrary high number can easily skew the results, e.g., if my real trading margin factor is 2 and I set the margin factor to 10 for the purposes of testing, the only thing that would prevent the margin in the test from exceeding 2 is either code (paragraph above as an example) or limiting the number of open positions (via the Properties tab).

As a note, there have been previous posts - I don't remember if these issues have been fixed - where the margin of the account is not respected for back testing. For example, if the margin factor is 2, the cash in the account is $100,000 and a long is placed worth $101,000, the order was rejected stating that there is not enough cash. Since the margin factor is 2, the buying power is actually $200,000 and the order should be placed without issue.

Duane

Edited: Wednesday June 25 2014 by alpha23
Posted Tuesday August 12 2014
Hello,

I have problem with the "account margin factor" in your default Paper Broker implementation.

I have Starting capital set to 50 000 and account margin factor to 3. I expected I will get 150 000 when calling SystemData.Broker.GetBuyingPower and 50 000 when calling SystemData.CurrentCapital. Instead I receive always 50 000 for both methods.

Did I misunderstood purpose of those methods ?

thank you
Posted Sunday August 17 2014
Daniel,

Please advise on this. The margin functionality is not working correctly per the above posts.

Thanks, Duane
Posted Monday August 18 2014
You are correct. RightEdge often uses the concepts of "buying power" and "cash in account" interchangeably. The margin factor support in the paper broker will allow the system to exercise buying power up to what is specified by the margin factor, but returns the actual cash held (which could be negative if you are using the margin factor) from GetBuyingPower().

This will probably be fixed in the next build of RightEdge.

Thanks,
Daniel
Posted Tuesday August 19 2014
Daniel,

Thank you in advance. I appreciate you fixing.

Duane


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems