Fully automated futures trading

Hi,

does anyone know why actual positions are really wild at the beginning of historical period? (See JPY below)
I wouldn't want to hold 100 contracts when trading a new instrument, so am trying to understand this effect.

Graphed using system.accounts.get_actual_position(instr).plot(title=instr)

corn.PNG


wild jpy.png

Code to replicate, note I added JPY to my system...

from systems.provided.futures_chapter15.basesystem import futures_system
from matplotlib.pyplot import show

system = futures_system(log_level="on")
print(system.accounts.portfolio().sharpe())
#system.accounts.portfolio().curve().plot()




instr = system.get_instrument_list()[1]
instr = "JPY"
system.accounts.get_actual_position(instr).plot(title=instr)


show()
 
Hi,

does anyone know why actual positions are really wild at the beginning of historical period? (See JPY below)
I wouldn't want to hold 100 contracts when trading a new instrument, so am trying to understand this effect.

Graphed using system.accounts.get_actual_position(instr).plot(title=instr)

View attachment 186277

View attachment 186278
Code to replicate, note I added JPY to my system...

from systems.provided.futures_chapter15.basesystem import futures_system
from matplotlib.pyplot import show

system = futures_system(log_level="on")
print(system.accounts.portfolio().sharpe())
#system.accounts.portfolio().curve().plot()




instr = system.get_instrument_list()[1]
instr = "JPY"
system.accounts.get_actual_position(instr).plot(title=instr)


show()

Try plotting the intermediate diagnostics to see where the wildness is coming from. This is also good to understand better what you are doing.

GAT
 
I checked intermediate stages for JPY and realised a couple of things:

There isn't carry data at the beginning so forecast weight is set to 0 for carry

Weights are unstable at beginning even though config is using fixed weights. This is probably due to exponential smoothing of weights. Not sure if this is meant to be as the weight plot was a surprise.
 

Attachments

  • weights.PNG
    weights.PNG
    46.4 KB · Views: 40
I checked intermediate stages for JPY and realised a couple of things:

There isn't carry data at the beginning so forecast weight is set to 0 for carry

Weights are unstable at beginning even though config is using fixed weights. This is probably due to exponential smoothing of weights. Not sure if this is meant to be as the weight plot was a surprise.

Yes, but that's probably not whats causing it though. Step backwards from the position rather than forwards.

GAT
 
Yes, but that's probably not whats causing it though. Step backwards from the position rather than forwards.

GAT

System position is calculated from formula in book, instrument weight being one of the variables.
LxMxN

It's primarily because of volatility scalar (JPY extreme low vol early on)
Less influence but still a factor is the instrument weighting.
There is no data for other instruments that early, so JPY weight is entire portfolio.
instr_weights.PNG
vol scalar.PNG
volatility.PNG
 
Hi

The carry2 signal in the system doesn't seem to have been scaled by the stdev

def carry2(raw_carry, smooth_days=90):

smooth_carry = raw_carry.ewm(smooth_days).mean()

return smooth_carry


For JPY,
JPY raw carry
2018-05-10 -0.000215
2018-05-11 -0.000215
2018-05-14 -0.000216
2018-05-15 -0.000216
2018-05-16 -0.000216

CORN raw carry
2018-05-10 -37.133632
2018-05-11 -36.904800
2018-05-14 -36.638590
2018-05-15 -36.470717
2018-05-16 -36.264224


Not sure if I'm missing something obvious...
 
Hi

The carry2 signal in the system doesn't seem to have been scaled by the stdev

def carry2(raw_carry, smooth_days=90):

smooth_carry = raw_carry.ewm(smooth_days).mean()

return smooth_carry


For JPY,
JPY raw carry
2018-05-10 -0.000215
2018-05-11 -0.000215
2018-05-14 -0.000216
2018-05-15 -0.000216
2018-05-16 -0.000216

CORN raw carry
2018-05-10 -37.133632
2018-05-11 -36.904800
2018-05-14 -36.638590
2018-05-15 -36.470717
2018-05-16 -36.264224


Not sure if I'm missing something obvious...

The normalisation is done at an earlier stage

https://github.com/robcarver17/pysystemtrade/blob/master/systems/futures/rawdata.py#L172

GAT
 

I traced the method, it seems that raw_carry isn't called by the carry rule in futuresconfig.yaml due to the way it is defined
carry2 calls only rawdata.daily_annualised_roll()

futuresconfig.yaml
carry:
function: systems.provided.futures_chapter15.rules.carry2
data:
- "rawdata.daily_annualised_roll"


When I changed the config to

data:
- "rawdata.raw_carry"

the raw carry forecasts look more correct (ie comparable across instruments)
 
I traced the method, it seems that raw_carry isn't called by the carry rule in futuresconfig.yaml due to the way it is defined
carry2 calls only rawdata.daily_annualised_roll()

futuresconfig.yaml
carry:
function: systems.provided.futures_chapter15.rules.carry2
data:
- "rawdata.daily_annualised_roll"


When I changed the config to

data:
- "rawdata.raw_carry"

the raw carry forecasts look more correct (ie comparable across instruments)

Now fixed on github. Thanks for finding the error.

GAT
 
Back
Top