Gamestudio Links
Zorro Links
Newest Posts
EUR/USD .t6 for 2019
by kalmar. 01/25/20 22:56
Average Position Up
by AndrewAMD. 01/25/20 17:44
Add safety string functions ("strcpy_s", etc.)
by AndrewAMD. 01/25/20 16:43
Imgui Lite-c Development
by txesmi. 01/23/20 23:26
Warning: Data both split and skipped!
by StefanCGN. 01/22/20 19:10
Simulate complex commission costs [Test]
by AndrewAMD. 01/22/20 13:05
Any Old Timers Still Around?
by Eagle. 01/21/20 21:51
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
2 registered members (AndrewAMD, Dooley), 801 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
andy_sh, dolorado, alterpips, Leohermoso, matchristrading
18360 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Simulate complex commission costs [Test] #478725
12/04/19 22:05
12/04/19 22:05
Joined: Feb 2017
Posts: 835
Chicago
AndrewAMD Online OP
User
AndrewAMD  Online OP
User

Joined: Feb 2017
Posts: 835
Chicago
jcl,

In [Test] mode, can I simply subtract from Capital over time to emulate various costs/withdrawals? (The manual says that Balance and Equity are calculated based on Capital and trade profit - this suggests that Balance and Equity are strictly outputs in Test mode.)

Example applications:
* Assets with complicated commissions costs, especially IB assets. (Commissions set to zero in the asset list.)
* Monthly fees, such as data fees.
* Monthly balance withdrawals.

If not, what is the correct approach?

Thanks,
Andrew

Re: Simulate complex commission costs [Test] [Re: AndrewAMD] #478754
12/09/19 13:25
12/09/19 13:25
Joined: Jul 2000
Posts: 27,095
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,095
Frankfurt
Capital is the initial capital, so subtracting from it has probably no effect. Subtract from Balance.

Re: Simulate complex commission costs [Test] [Re: AndrewAMD] #478755
12/09/19 13:52
12/09/19 13:52
Joined: Feb 2017
Posts: 835
Chicago
AndrewAMD Online OP
User
AndrewAMD  Online OP
User

Joined: Feb 2017
Posts: 835
Chicago
Thanks!

Re: Simulate complex commission costs [Test] [Re: AndrewAMD] #478939
01/22/20 02:21
01/22/20 02:21
Joined: Feb 2017
Posts: 835
Chicago
AndrewAMD Online OP
User
AndrewAMD  Online OP
User

Joined: Feb 2017
Posts: 835
Chicago
For those interested, none of the above worked!

However, this below script did the job. The fee simulator is the incur_fee() function. Note that Zorro is being conservative in the simulation and assumes you lose at least one penny on a break-even trade.

The below script makes your money disappear. ( ͡° ͜ʖ ͡°)

Code
#include<default.c>

#define ASSET_FEE "DUMMY"
#define ALGO_FEE "FEE"

void incur_fee(var amt){
	if(amt<=0) return;
	if(Live) return;
	algo(ALGO_FEE);
	asset(ASSET_FEE);
	Commission = amt - 0.01;
	enterLong(1);
	exitLong();
}


void run(){
	if(!Test){
		print(TO_ANY,"\nOnly [Test] mode supported.");
		quit("#Quitting...");
		return;
	}
	
	if(Init){
		set(LOGFILE);
		Verbose = 3;
		Capital = 100000;
		BarPeriod = 1440;
		LookBack = 0;
		BarMode = BR_FLAT|BR_WEEKEND;
		StartDate = 2017;
		EndDate = 2019;
		printf("\nloading dummy asset list...");
		assetList("AssetsFix");
		printf("\nsetting up dummy asset...");
		assetAdd(ASSET_FEE,0.01,0.00,0,0,0.00,0.00,0,2,1,0.00,ASSET_FEE);
		algo(ALGO_FEE);
		asset(ASSET_FEE);
	}
	
	if(!Init && !is(LOOKBACK) && ((int)Equity)>0){
		printf("\nEquity: %0.2f",Equity);
		var fee = roundto(random(1000.0),50.0);
		printf("\nfee = %0.2f",fee);
		incur_fee(fee);
	}
	
	if(is(EXITRUN)){
		printf("\nFinal equity is: %0.2f",Equity);
	}
}

Attached Files
img.PNG (24 downloads)
Re: Simulate complex commission costs [Test] [Re: AndrewAMD] #478943
01/22/20 13:05
01/22/20 13:05
Joined: Feb 2017
Posts: 835
Chicago
AndrewAMD Online OP
User
AndrewAMD  Online OP
User

Joined: Feb 2017
Posts: 835
Chicago
Follow up: if you need to use Virtual Hedging, you will notice that the above method does not work. This is because if virtual trades are placed during run(), then pool trades are not placed until the end of run(). This means that if you enter long and exit long in the same run() call, no actual pool trade is placed.

Whereas if you place any trades outside of run(), pool trades are placed instantly. So the fix is to use call() to place the "fee" trades, like so:

Code
#include<default.c>

#define ASSET_FEE "DUMMY"
#define ALGO_FEE "FEE"

#define ASSET_TRADING "EUR/USD"
#define ALGO_TRADING "TRADING"

void incur_fee(int flags, var amt){
	if(amt<=0) return;
	if(Live) return;
	printf("#\nIncurring fee of %0.2f",amt);
	algo(ALGO_FEE);
	asset(ASSET_FEE);
	Commission = amt - 0.01;
	enterLong(1);
	exitLong();
}


void run(){
	if(!Test){
		print(TO_ANY,"\nOnly [Test] mode supported.");
		quit("#Quitting...");
		return;
	}
	
	if(Init){
		set(LOGFILE);
		Hedge = 5;
		Verbose = 7|DIAG;
		Capital = 100000;
		BarPeriod = 1440;
		LookBack = 10;
		BarMode = BR_FLAT|BR_WEEKEND;
		StartDate = 2017;
		EndDate = 2019;
		assetList("AssetsFix");
		
		printf("\nsetting up dummy asset...");
		assetAdd(ASSET_FEE,0.01,0.00,0,0,0.00,0.00,0,2,1,0.00,ASSET_FEE);
		algo(ALGO_FEE);
		asset(ASSET_FEE);
		algo(ALGO_TRADING);
		asset(ASSET_TRADING);
		
	}
	
	if(!Init && !is(LOOKBACK) && ((int)Equity)>0){
		algo(ALGO_TRADING);
		asset(ASSET_TRADING);
		if(Bar%5){
			if(Bar%2){
				enterLong(100);
			}
			else{
				exitLong();
				printf("#\nEquity: %0.2f",Equity);
				var fee = roundto(random(10.00),0.01);
				printf("#\nfee = %0.2f",fee);
				call(1,incur_fee,0,fee);
			}
		}
	}
	
	if(is(EXITRUN)){
		printf("#\nFinal equity is: %0.2f",Equity);
	}
}
Note: the above code requires the latest Zorro beta.


Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1