Oh no, not another python backtester...

Discussion in 'Programming' started by globalarbtrader, Dec 18, 2015.

  1. Don't roll ED contracts on volume, roll by date. Volume shifts back and forth, often on a daily basis.
     
    #31     Dec 27, 2016

  2. The carry data file gives the current contracts being used for prices

    So for example in here:

    https://github.com/robcarver17/pysystemtrade/blob/master/sysdata/legacycsv/EDOLLAR_carrydata.csv

    The final row (#8646) has a price contract of 201909 and a price of 98.1175. The carry contract is 201906.

    Then in the price file there is the same price (at the end of these files the current adjusted price will always ). That price will be the closing price from IB on that day, which should be the same as quandl although obviously no guarantee.

    The rolling is done on a constant maturity basis, adjusted in earlier years if there isn't liquidity far enough out on the curve.

    I'm hoping to publish an extension to pysysystemtrade that creates this data, after pulling individual contracts from quandl, plus explanatory blogpost.

    GAT
     
    #32     Jan 1, 2017
  3. I've looked into this and I can't repeat the problem, nor can I see any obvious bugs that might be the cause. For example with USD and GBP I get sharpe ratios within 0.02 of each other. There are still some small differences as you'd expect for the following reasons:

    The main difference is with euros as the base currency you only have the FX history since 1999 so a lot of the earlier back test vanishes.

    The concept of "cash" is irrelevant since the backtest doesn't know about margin. Obviously if you have £1,000,000 that will give you different positions to having $1,000,000; and the difference will vary over time as those amounts are different. Plus profits will be daily marked to market into the base currency and so will be different.

    The differences are smaller if you use roundpositions=False when doing accounting or turn off buffering (config.buffer_size=0.0)

    Small amounts of capital and rounded positions combined with buffering may lead to weird non linearities where you have a position in one currency but not in another which could be a cause of lower vol.


    GAT.
     
    #33     Jan 2, 2017
  4. djames

    djames

    I look forward to the extension (and blogpost). Would be reassuringly complete to have the stitching code for the example data files. Thanks
     
    #34     Jan 2, 2017
  5. wind_

    wind_

    Hi GAT,

    I notice a bug(?) in pysystemtrade.

    Code:
    system.accounts.portfolio(roundpositions=False,delayfill=False)
    
    >>> system.data.daily_prices("GBP").tail(10)
    Loading csv data for GBP
    2017-01-05    1.2427
    2017-01-06    1.2293
    2017-01-09    1.2178
    2017-01-10    1.2179
    2017-01-11    1.2223
    2017-01-12    1.2178
    2017-01-13    1.2200
    2017-01-16       NaN <-------- Holiday
    2017-01-17    1.2411
    2017-01-18    1.2352
    
    >>> system.accounts.get_notional_position("GBP").tail(10)
    2017-01-05   -84.629566
    2017-01-06   -77.148345
    2017-01-09   -75.307283
    2017-01-10   -78.993038
    2017-01-11   -81.460877
    2017-01-12   -85.617533
    2017-01-13   -88.694337
    2017-01-16   -88.694339
    2017-01-17   -86.485507
    2017-01-18   -88.339476
    
    >>> system.accounts.pandl_for_instrument("GBP").tail(10)
    2017-01-05    -7555.350031
    2017-01-06    10596.153621
    2017-01-09     8760.748599
    2017-01-10      -72.328423
    2017-01-11    -2942.568750
    2017-01-12     3170.171272
    2017-01-13    -1588.764330
    2017-01-16        0.000000
    2017-01-17        0.000000 <-------- not supposed to be zero
    2017-01-18     4656.453583
    
     
    #35     Jan 18, 2017
  6. Probably a subtle date / time alignment; I've raised an issue

    https://github.com/robcarver17/pysystemtrade/issues/48

    Thanks
    GAT
     
    #36     Jan 18, 2017
  7. djames

    djames

    Thanks for the reply (in Jan), I'm starting with recreating the carry data as this seems simpler.

    If I remember correctly, you said that you are not rolling with fixed rules, that there is some discretion applied as to when contracts are rolled.

    Does this mean that the carry data files provided in pysystemtrade show the
    dates of when each of your active instruments were rolled? Meaning you are recording the date when the roll is initiated for use in constructing backtest data.

    For data which is outside of the date range your system has been live and rolling, how did you come up with the roll dates? Are these roll dates volume based or bid ask spread based?

    Regarding this reply:

    Do the change in carry pair dates indicate points in the price file where panama adjustment is applied?
     
    Last edited: Feb 8, 2017
    #37     Feb 8, 2017
  8. Yes since around January 2014 these are actual roll dates.

    They are based on a fixed time before the expiry date, with adjustments to those dates when there isn't a sychronous price between the current and new contracts.

    Yes

    GAT
     
    #38     Feb 8, 2017
  9. Hi GAT,
    I was wondering if there is a feature in pysystemtrade to be able to conduct portfolio attributions?
    Also, have you ever experimented with 'value' rules in futures markets?
    Thanks!
     
    #39     Apr 11, 2017
  10. Depends what you mean by 'attributions'. There is a lot of diagnostics in the accounting stage but if you mean something distinct perhaps you could give an example?

    'Value' as distinct from carry I'm not sure what that means in futures. If you mean the definition used by Anti Illmanen, which is a long run mean reversion to an equilibrium, then:

    a) for absolute value (reversion to the univariate equilibrium for that instrument) I haven't looked at it because the time scales involved mean it isn't statistically significant
    b) for relative value (say within asset class) then yes, I actually use this myself

    GAT
     
    #40     Apr 12, 2017