Gamestudio Links
Zorro Links
Newest Posts
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
LPDIRECT3DCUBETEXTUR
E9

by Ayumi. 04/12/24 11:00
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 04/11/24 14:56
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Quad, AndrewAMD), 410 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
11honza11, ccorrea, sakolin, rajesh7827, juergen_wue
19045 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: 1,725
Chicago
AndrewAMD Online OP
Serious User
AndrewAMD  Online OP
Serious User

Joined: Feb 2017
Posts: 1,725
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,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
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: 1,725
Chicago
AndrewAMD Online OP
Serious User
AndrewAMD  Online OP
Serious User

Joined: Feb 2017
Posts: 1,725
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: 1,725
Chicago
AndrewAMD Online OP
Serious User
AndrewAMD  Online OP
Serious User

Joined: Feb 2017
Posts: 1,725
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 (37 downloads)
Re: Simulate complex commission costs [Test] [Re: AndrewAMD] #478943
01/22/20 13:05
01/22/20 13:05
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online OP
Serious User
AndrewAMD  Online OP
Serious User

Joined: Feb 2017
Posts: 1,725
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.


Moderated by  Petra 

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