Seasonality or just the ultimate curve fit?

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #163370 quote
    Vonasi
    Moderator
    Master

    I got to thinking about seasonality again and this got me thinking that I should test to see if there are any sections of a year that if you had been long or short in every year would have returned good results and a nice equity curve. So I coded two very simple strategies that count week numbers and and buy on one week number and sell on another week number. Optimise the two strategies with the variables startweek and endweek with values between 1 and 53 and it will tell you which blocks of weeks have given the best return during the historical data.

    Then I created a third strategy that you can enter the best returned values as startweeklong, endweeklong, startweekshort and endweekshort so as to see what the equity curve would have looked like had you been short during the best weeks and long during the best weeks. On my tests I found that the best long weeks rarely clashed with the best short weeks but if you find an instrument where they do then you can’t put those values in the ‘Both’ strategy.

    The strategies only work on the weekly chart.

    The question up for general discussion is….. is this seasonality or is it just the ultimate curve fit?

    I have attached images of Live Cattle and Soybeans. No spread was used in the tests.

    defparam cumulateorders = false
    
    if openyear <> openyear[1] then
    wn = 0
    endif
    
    wn = wn + 1
    
    if wn = startweek then
    buy 1 contract at market
    endif
    
    if onmarket and wn = endweek then
    sell at market
    endif
    
    defparam cumulateorders = false
    
    if openyear <> openyear[1] then
    wn = 0
    endif
    
    wn = wn + 1
    
    if wn = startweek then
    sellshort 1 contract at market
    endif
    
    if onmarket and wn = endweek then
    exitshort at market
    endif
    
    
    defparam cumulateorders = false
    
    startweekshort = 17
    endweekshort = 39
    startweeklong = 39
    endweeklong = 17
    
    if openyear <> openyear[1] then
    wn = 0
    endif
    
    wn = wn + 1
    
    if wn = startweeklong then
    buy 1 contract at market
    endif
    
    if onmarket and wn = endweeklong then
    sell at market
    endif
    
    if wn = startweekshort then
    sellshort 1 contract at market
    endif
    
    if onmarket and wn = endweekshort then
    exitshort at market
    endif
    
    
    GraHal and Paul thanked this post
    Live-Cattle.png Live-Cattle.png Soyabeans.png Soyabeans.png Seasonality-Long.itf Seasonality-Short.itf Seasonality-Both.itf
    #163376 quote
    Vonasi
    Moderator
    Master

    Here is another example. This time it is Heating Oil.

    Heating-Oil.png Heating-Oil.png
    #163392 quote
    Paul
    Participant
    Master

    interesting. I put it also on a few.

    maybe a month is interesting too and you can expand parameters to enter again long after short i.e. more easily. Not sure yet if usefull.

    Here are a few pics with use long&short

    Screenshot-2021-03-08-at-00.24.22.jpg Screenshot-2021-03-08-at-00.24.22.jpg Screenshot-2021-03-08-at-00.23.03.jpg Screenshot-2021-03-08-at-00.23.03.jpg Screenshot-2021-03-08-at-00.19.31.jpg Screenshot-2021-03-08-at-00.19.31.jpg Screenshot-2021-03-08-at-00.18.09.jpg Screenshot-2021-03-08-at-00.18.09.jpg
    #163400 quote
    Paul
    Participant
    Master

    It’s is just more curvefitting and defeats the goal of the code. This is a bit what I had in mind.

    now i.e. 4 turnarounds a year are possible, or long only twice a year certain periods.

    monthy bars, 25 units

    defparam cumulateorders = false
    
    //batchtype=1 then set a3 & a4 not to optimise
    //batchtype=2 can comment out the buy/sellshort rows as variation in batch2?
    //optimise a1 t/m a4 range 1-12
    
    once tradetype=1 //1 both, 2 long, 3 short
    once batchtype=2 //batchtyp 1 solo with only parameters a1,a2
    
    //first batch
    startweeklong  = a1
    endweeklong    = a2
    
    startweekshort = a2
    endweekshort   = a1
    
    // second batch
    startweeklong2  = a3
    endweeklong2    = a4
    
    startweekshort2 = a4
    endweekshort2   = a3
    
    if openyear <> openyear[1] then
    wn = 0
    wn2 =0
    endif
    
    wn = wn + 1
    wn2= wn2+ 1
    
    // BATCH1
    if batchtype=1 or batchtype=2 then
    
    if tradetype=1 or tradetype=2 then
    
    if wn = startweeklong  then
    buy 1 contract at market
    endif
    
    if onmarket and wn = endweeklong then
    sell at market
    endif
    endif
    
    if tradetype=1 or tradetype=3 then
    
    if wn = startweekshort then
    sellshort 1 contract at market
    endif
    
    if onmarket and wn = endweekshort then
    exitshort at market
    endif
    
    endif
    endif
    
    // BATCH2
    if batchtype=2 then
    
    if tradetype=1 or tradetype=2 then
    
    if wn2 = startweeklong2 then
    buy 1 contract at market
    endif
    
    if onmarket and wn2 = endweeklong2 then
    sell at market
    endif
    endif
    
    if tradetype=1 or tradetype=3 then
    
    if wn2 = startweekshort2 then
    sellshort 1 contract at market
    endif
    
    if onmarket and wn2 = endweekshort2 then
    exitshort at market
    endif
    endif
    endif
    
    Vonasi thanked this post
    Screenshot-2021-03-08-at-02.37.07.jpg Screenshot-2021-03-08-at-02.37.07.jpg
    #163451 quote
    Vonasi
    Moderator
    Master

    Thanks for that code Paul. I had considered something similar but decided that (as you suggest) it was just increased curve fitting. I also felt that if a commodity was to be seasonal then it was likely to only have two periods – one where being short the commodity was wise and the other where being long the commodity was wise due to seasonal supply and demand caused by weather and/or crop growing seasons.

    I think that on some truly seasonal commodities the equity curves highlight nicely what a good return one could have got just by being long and short in time with the seasons. What I don’t like the look of is the fact that a lot of the equity curves seem to have negative dips on the most recent data which makes me think that perhaps seasonality as a market force is declining and also that perhaps the nice previous equity curves are just quite simply a lovely curve fit.

    Still if one was to be trading a commodity that the test shows to produce a nice equity curve then having only long strategies at one part of the year and only short on another part of the year seems like a sensible filter that should improve win rates and performance/returns.

    #163460 quote
    Paul
    Participant
    Master

    Yes, but even with a nice equitycurve as you describe in you lowest part, there are not many trades to have it rely on.  Long one part of the year, short the other had me make this variation because sometimes it just holds to a position while the market is trending against it, perhaps eventually becoming winning.

    I took another approach.  I changed it to a daily reset, mainly to have more trades.

    Now the focus is 2-3-4 hour charts and optimising starts now in range at 0 if i’am correct.

    As example I took the nasdaq. Added spread 2 & tickbytick.

    There are always dips in the market and here’s a way to minimise the effect it seems.

    I.e. buys if the high>high[1] next bar at market, else it exit’s shorts, which is still a buy but not holding a new position against the trend.

    Results are pretty good.

    Screenshot-2021-03-08-at-15.31.11.jpg Screenshot-2021-03-08-at-15.31.11.jpg Screenshot-2021-03-08-at-15.31.24.jpg Screenshot-2021-03-08-at-15.31.24.jpg Screenshot-2021-03-08-at-15.31.35.jpg Screenshot-2021-03-08-at-15.31.35.jpg Screenshot-2021-03-08-at-15.32.49.jpg Screenshot-2021-03-08-at-15.32.49.jpg
    #163465 quote
    Vonasi
    Moderator
    Master

    I’m struggling a little to fully understand what you are now doing and see that you have switched to the Nasdaq which is a market that has not a lot to do with seasonality. Is it possible to post the code so that I can try to understand more easily what you mean?

    #163466 quote
    Paul
    Participant
    Master

    here’s eurusd with spread

    defparam cumulateorders = false
    //defparam flatbefore =080000
    //defparam flatafter  =200000
    
    //batchtype=1 then set a3 & a4 not to optimise
    //batchtype=2 can comment out the buy/sellshort rows as variation?
    //optimise a1 t/m a4 range 1-12
    
    once tradetype=1 //1 both, 2 long, 3 short
    once batchtype=2 //batchtyp 1 solo with only parameters a1,a2
    
    //first batch
    startweeklong  = a1
    endweeklong    = a2
    
    startweekshort = a2
    endweekshort   = a1
    
    // second batch
    startweeklong2  = a3
    endweeklong2    = a4
    
    startweekshort2 = a4
    endweekshort2   = a3
    
    //if openyear <> openyear[1] then
    if openday<>openday[1] then
    wn = 0
    wn2 =0
    endif
    
    wn = wn + 1
    wn2= wn2+ 1
    
    // BATCH 1
    if batchtype=1 or batchtype=2 then
    
    if tradetype=1 or tradetype=2 then
    
    if wn = startweeklong then
    if high>high[1] then
    buy 1 contract at market
    else
    exitshort at market
    endif
    endif
    
    if onmarket and wn = endweeklong then
    sell at market
    endif
    endif
    
    if tradetype=1 or tradetype=3 then
    
    if wn = startweekshort then
    if low<low[1] then
    sellshort 1 contract at market
    else
    sell at market
    endif
    endif
    
    if onmarket and wn = endweekshort then
    exitshort at market
    endif
    
    endif
    endif
    
    // BATCH2
    if batchtype=2 then
    
    if tradetype=1 or tradetype=2 then
    
    if wn2 = startweeklong2 then
    if high>high[1] then
    buy 1 contract at market
    else
    exitshort at market
    endif
    endif
    
    if onmarket and wn2 = endweeklong2 then
    sell at market
    endif
    endif
    
    if tradetype=1 or tradetype=3 then
    
    if wn2 = startweekshort2 then
    if low<low[1] then
    sellshort 1 contract at market
    else
    sell at market
    endif
    endif
    
    if onmarket and wn2 = endweekshort2 then
    exitshort at market
    endif
    endif
    endif
    
    //set stop %loss 10
    //set target pprofit 250
    
    Screenshot-2021-03-08-at-15.59.06.jpg Screenshot-2021-03-08-at-15.59.06.jpg Screenshot-2021-03-08-at-15.59.20.jpg Screenshot-2021-03-08-at-15.59.20.jpg
    #163474 quote
    Vonasi
    Moderator
    Master

    OK but now seasonality has completely gone out of the window and because we are on faster time frame charts we truly have entered the world of finding the best possible curve fit to the data that we have.

    #163485 quote
    Paul
    Participant
    Master

    haha, yeah seasonality is not longer the target. One thing let to another.

    This code analyses the market and decides based on a lot of data if it’s best to go long, short or both.

    Having 1-2k trades and a curve like that on different markets with spread is intriguing. It’s also on the dow, nikkei btw in lesser extend.

    Here’s eur/zar. Spread 1. Don’t know if that’s correct spread

    Al what we try is curvefitting. you can have 2 parameters for 50 trades in say 8 years, or 4 parameters for 2000 trades in 8 years. I’am leaning then to 4 parameters.

    I’ve to look into it a bit more. Thnx for posting the original idea. It gives a lot of new options!

    Screenshot-2021-03-08-at-16.45.01.jpg Screenshot-2021-03-08-at-16.45.01.jpg Screenshot-2021-03-08-at-16.44.52.jpg Screenshot-2021-03-08-at-16.44.52.jpg
    #163491 quote
    Vonasi
    Moderator
    Master

    I think the only thing these curve fitted equity curves do is give us a best performance datum against which to compare other strategies to get some sort of idea of how good or bad they are. We can compare them to ‘buy only the best bits’ as well as ‘buy and hold now’!

    #163497 quote
    Nicolas
    Keymaster
    Master
    #163500 quote
    Vonasi
    Moderator
    Master

    Yes that used historical seasonality as a filter for future trades I seem to recall. I also believe that it didn’t work out too well as the future refused to do the same as the past even if the in sample equity curves looked great!

    #163589 quote
    snucke
    Participant
    Veteran

    ive been dabbeling alot with seasonality later too.

    i have been using the pathfinder as a basecode and ive been using this site https://charts.equityclock.com/live-cattle-futures-lc-seasonal-chart

    to look for seasonality patterns.

     

    but as you say, it might just be a little bit to curvefit..

    #163627 quote
    Vonasi
    Moderator
    Master

    You might also be interested in this indicator that I coded a while back then:

    Seasonality Curve

    snucke thanked this post
Viewing 15 posts - 1 through 15 (of 18 total)
  • You must be logged in to reply to this topic.

Seasonality or just the ultimate curve fit?


General Trading: Market Analysis & Manual Trading

New Reply
Author
author-avatar
Vonasi @vonasi Moderator
Summary

This topic contains 17 replies,
has 4 voices, and was last updated by snucke
4 years, 7 months ago.

Topic Details
Forum: General Trading: Market Analysis & Manual Trading
Language: English
Started: 03/07/2021
Status: Active
Attachments: 19 files
Logo Logo
Loading...