kzhdev / gdax_zorro_plugin

CoinbasePro (Gdax) Zorro plugin
MIT License
3 stars 0 forks source link

LotAmount/PIPCost issues #1

Open loopiezlol opened 2 years ago

loopiezlol commented 2 years ago

I was trying to follow the snippet in the README:

function run() 
{
        // For example,the base_increment of BTC/USD is 0.00000001, the base_min_size of BTC/USD is 0.0001.
        // Following code buys 0.0001 BTC at market price

        asset("BTC/USD");
    Lots = 10000;     // order size is Lots * base_increment, 10000 * 0.00000001
    MaxLong = 1;
    enterLong();

    set(PLOTNOW,LOGFILE);
}

With the mention that by Accounts entry was generated by the plugin:

Name,Price,Spread,RollLong,RollShort,PIP,PIPCost,MarginCost,Leverage,LotAmount,Commission,Symbol
BTC/USD,44267.07000000,0.01000000,0.0,0.0,0.01000000,0.01000000,0.0,1,0.00000001,0.000,BTC-USD

However, in the simulations I'm getting values that make me think it actually purchases 10k full BTC at once:

End of lookback period

[80: Tue 20-01-07 11:00] (7885.78)
[BTC/USD::L08006] Long 10000@7892.48  at 11:00:00

[81: Tue 20-01-07 12:00] 11218 +11218 1/0 (7893.61)
[82: Tue 20-01-07 13:00] -213982 -213982 0/1 (7871.09)
[83: Tue 20-01-07 14:00] -447082 -447082 0/1 (7847.78)
[84: Tue 20-01-07 15:00] -424880 -424880 0/1 (7850.00)
[85: Tue 20-01-07 16:00] -1264280 -1264280 0/1 (7766.06)
[86: Tue 20-01-07 17:00] 225120 +225120 1/0 (7915.00)
[87: Tue 20-01-07 18:00] 500921 +500921 1/0 (7942.58)

This is also reflected in the strategy result too:

Test TestLotSize BTC/USD, Zorro 2.444

Simulated account   AssetsFix 
Bar period          1 hour (avg 88 min)
Total processed     18659 bars
Test period         2020-01-07..2022-02-16 (12505 bars)
Lookback period     80 bars (4 days)
Montecarlo cycles   200
Simulation mode     Realistic (slippage 5.0 sec)
Avg bar             39460.3 pips range
Spread              1.0 pips (roll 0.00/0.00)
Contracts per lot   0.0

Gross win/loss      362925504$-0$, +3629255.1p, lr 579557845$
Average profit      171939958$/year, 14328330$/month, 661308$/day
Max drawdown        -36829784$ 10.1% (MAE -355328224$ 97.9%)
Total down time     6% (TAE 97%)
Max down time       37 hours from Mar 2020
Max open margin     78857798$
Max open risk       789348$
Trade volume        78924780$ (37391485$/year)
Transaction costs   -100.00$ spr, -119601$ slp, 0$ rol
Capital required    78857800$

Any thoughts how to work with fractional amounts of BTC or other crypto?

loopiezlol commented 2 years ago

Seems that playing with the PIP together with the LotAmount variable in the assets list changes the behaviour.

However I think the default PIP value (0.01) is correct and shouldn't be changed.

loopiezlol commented 2 years ago

I think the culprit is PIPCost which defaults to 0.01 (like PIP).

Zorro docs say this:

or calculating it manually, multiply LotAmount with PIP;

With LotAmount = 0.00000001 and PIP = 0.01, we get PIPCost = 10^-10 = 0.0000000001

Plugging that in the script with Lots = 100000000:

function run() 
{
    asset("BTC/USD");
    Lots = 100000000;
    MaxLong = 1;
    enterLong();

    PlotBorder = 100;

    set(PLOTNOW,LOGFILE);
}

purchases 1 BTC

loopiezlol commented 2 years ago

I think this would be fixed by modifying the logic here: https://github.com/kzhdev/gdax_zorro_plugin/blob/796e15cf57662ec05a854ca24de80d37565dac6d/gdax_zorro_plugin/gdax_zorro_plugin.cpp#L508

fprintf(f, "%s,%.8f,%.8f,0.0,0.0,%.8f,%.8f,0.0,1,%.8f,0.000,%s\n",
   prod.display_name.c_str(), ticker.ask, (ticker.ask - ticker.bid), prod.quote_increment,
   prod.quote_increment, prod.base_increment, prod.id.c_str());

becoming

fprintf(f, "%s,%.8f,%.8f,0.0,0.0,%.8f,%.8f,0.0,1,%.8f,0.000,%s\n",
   prod.display_name.c_str(), ticker.ask, (ticker.ask - ticker.bid), prod.quote_increment,
   prod.quote_increment * prod.base_increment, prod.base_increment, prod.id.c_str());

but this may be wrong when using non-USD symbols ?

if the counter currency is different to the account currency, multiply the result with the counter currency exchange rate. Example 1: AUD/USD on a micro lot EUR account has PipCost of 1000 0.0001 0.9 (current USD price in EUR) = 0.09 EUR. Example 2: AAPL stock on a USD account has PipCost of 1 * 0.01 = 0.01 USD = 1 cent.