gekkowarez / gekkoga

Genetic Algorithm for solving optimization of trading strategies using Gekko
313 stars 104 forks source link

"Global maximum" not persistent when profits are negative #59

Open WilbertNL opened 5 years ago

WilbertNL commented 5 years ago

Hi all,

As the title states, the Global Maximum is not persistent when GA testing with only negative profits as result. Global Maximum is always the last epoch's result:

    Epoch number: 31
..
Other metrics:
     { balance: 8008.66585108,
..

    Global Maximums:
..
     { balance: 8008.66585108,

but then, some epochs later:

Epoch number: 35
..
    Other metrics:
     { balance: 6607.4022642528,
..
    Global maximum so far:
     { balance: 6607.4022642528,

Full epoch:

  --------------------------------------------------------------
    Epoch number: 35
    Time it took (seconds): 173.573
    Max score: 0
    Max profit: 0 USDT
    Max sharpe: 0
    Max profit position: 0
    Max parameters:
     { ADX: 2,
  ADX_low: 49,
  BULL_RSI: 12,
  ADX_high: 76,
  BEAR_RSI: 17,
  SMA_long: 1200,
  SMA_short: 64,
  candleSize: 15,
  historySize: 1500,
  BULL_MOD_low: -4,
  BEAR_MOD_low: -3,
  BULL_RSI_low: 54,
  BEAR_RSI_low: 24,
  BULL_MOD_high: 5,
  BEAR_MOD_high: 14,
  BEAR_RSI_high: 61,
  BULL_RSI_high: 86 } 
    Other metrics:
     { balance: 6607.4022642528,
  profit: -3143.5977357472,
  sharpe: -36.606280564530586,
  market: -31.908615384615388,
  relativeProfit: -32.23872152340478,
  yearlyProfit: -27336.607821137713,
  relativeYearlyProfit: -280.34671132332795,
  startPrice: 9750,
  endPrice: 6638.91,
  trades: 7 }

    --------------------------------------------------------------
    Global Maximums:
    Score: 0
    Profit: 0 USDT
    Sharpe: 0
    parameters: 
 { ADX: 2,
  ADX_low: 49,
  BULL_RSI: 12,
  ADX_high: 76,
  BEAR_RSI: 17,
  SMA_long: 1200,
  SMA_short: 64,
  candleSize: 15,
  historySize: 1500,
  BULL_MOD_low: -4,
  BEAR_MOD_low: -3,
  BULL_RSI_low: 54,
  BEAR_RSI_low: 24,
  BULL_MOD_high: 5,
  BEAR_MOD_high: 14,
  BEAR_RSI_high: 61,
  BULL_RSI_high: 86 } 
    Global maximum so far:
     { balance: 6607.4022642528,
  profit: -3143.5977357472,
  sharpe: -36.606280564530586,
  market: -31.908615384615388,
  relativeProfit: -32.23872152340478,
  yearlyProfit: -27336.607821137713,
  relativeYearlyProfit: -280.34671132332795,
  startPrice: 9750,
  endPrice: 6638.91,
  trades: 7 } 
    --------------------------------------------------------------

So yes, it doesn't make any profits with regards to the endPrice, but losses are still a lot less when your end balance is 8008 instead of 6607. So I would assume the Global Maximum actually shows the global maximum even with negative profits.

My config:

const randomExt = require('random-ext');

const config = {
  stratName: 'RSI_BULL_BEAR_ADX',
  gekkoConfig: {
    watch: {
      exchange: 'binance',
      currency: 'USDT',
      asset: 'BTC'
    },

//    daterange: 'scan',

    daterange: {
      from: '2018-04-18 09:00',
      to: '2018-06-15 00:00'
    },

    simulationBalance: {
      'asset': 1,
      'currency': 1
    },

    slippage: 0.05,
    feeTaker: 0.05,
    feeMaker: 0.05,
    feeUsing: 'taker', // maker || taker

  },
  apiUrl: 'http://192.168.190.158:3000',

  // Population size, better reduce this for larger data
  populationAmt: 20,

  // How many completely new units will be added to the population (populationAmt * variation must be a whole number!!)
  variation: 0.5,

  // How many components maximum to mutate at once
  mutateElements: 7,

  // How many parallel queries to run at once
  parallelqueries: 3,

  // Min sharpe to consider in the profitForMinSharpe main objective
  minSharpe: 0.5,

  // profit || score || profitForMinSharpe
  // score = ideas? feedback?
  // profit = recommended!
  // profitForMinSharpe = same as profit but sharpe will never be lower than minSharpe
  // mainObjective: 'profitForMinSharpe',
  mainObjective: 'profit',

  // optionally recieve and archive new all time high every new all time high
  notifications: {
    email: {
      enabled: false,
      receiver: 'destination@some.com',
      senderservice: 'gmail',
      sender: 'origin@gmail.com',
      senderpass: 'password',
    },
  },

  candleValues: [15],
  getProperties: () => ({

    historySize: 1500,

    SMA_long: randomExt.integer(15,5) * 100,
    SMA_short: randomExt.integer(70,30),

    BULL_RSI: randomExt.integer(15,5),
    BULL_RSI_high: randomExt.integer(90,70),
    BULL_RSI_low: randomExt.integer(70,40),

    BEAR_RSI: randomExt.integer(20,10),
    BEAR_RSI_high: randomExt.integer(70,30),
    BEAR_RSI_low: randomExt.integer(30,10),

    BULL_MOD_high: randomExt.integer(7,3),
    BULL_MOD_low: randomExt.integer(-3,-7),
    BEAR_MOD_high: randomExt.integer(20,10),
    BEAR_MOD_low: randomExt.integer(-3,-7),

    ADX: randomExt.integer(5, 2),
    ADX_high: randomExt.integer(80, 60),
    ADX_low: randomExt.integer(60, 40),

    candleSize: randomExt.pick(config.candleValues)
  })
};

module.exports = config;

May I assume this is a bug or is this by design?