It's a algorithm, it's a strategy, it's BOTH an algorithm and a strategy

Discussion in 'Automated Trading' started by Artfldgr, Jan 25, 2020.

  1. Artfldgr

    Artfldgr

    Sometimes it’s hard to figure out what the title should be, sometimes its hard to figure out what category something should go under… This is one of those times (and I am sure there will be more of them in my future)

    Ultimately what I have is an algorithm that encapsulates a strategy. The major difference from some technical analysis or chartist artwork is that this does not put up anything but buy and sell orders. That is, it tells you when to buy, and tells you when to sell, and its FAR from finished as its in it’s first iterations, and since I discovered it, I still have a long way to go to understand how and why it works, and from that improve it.

    Before I move on, the title is a hat tip to an old SNL skit from the days of the original players called “Shimmer”. It’s a desert topping it’s a floor wax skit, where Chevy Chase steps in on a husband and wife arguing as in old B&W commercials and fixes their lives by informing them, it’s both, a dessert topping AND a floor wax.

    Those wishing to go back in time and see Shimmer skit can go here:
    https://www.nbc.com/saturday-night-live/video/shimmer-floor-wax/n8625

    I recently posted in this thread an example of my recent work:
    https://www.elitetrader.com/et/threads/a-strategy-that-is-a-secret.339655/

    But soon after thought that i needed my own thread... so here we are.

    As with anyone trading (as opposed to investing), we are all looking for signals to buy, signals to sell, ways of knowing how long to stay in, and all manner of strategies and all manner of methodologies we try to stick to.

    Recently i was on Quantopian, and now moved over to Quantiacs, as I wanted to learn Python, and why not kill two birds with one stone? I had more recently been experimenting with various strategies on ThinkOrSwim... (and am looking for a platform where a strategy can be used to trade as that was the original intent).

    Now before i go on and on, and get into the results, I need to point out that ThinkOrSwim has no automated trading (though i hear it used to, which now is nice trivia). Also, it really does not do great back testing of ideas or strategies (good enough is good enough), and its methods for making trades in strategies has a lot to be said negatively. So understand that what i will be putting up is kind of loose, in terms of implementation. Its buy and sell signals are slightly off, and only within how that programs methods work. BUT also note that given the results, being a tiny bit off is not a show stopper killer... if something goes up five points and your off by 5 cents on entry or exit, it may not be accurate, but its also not so far off what your looking at is not worth looking at.

    I am also coding things for Quantiacs so that i can do a richer more accurate back test, and its current incarnation is good enough as a means to manually trade on the ThinkOrSwim platform.

    Also, do not ask for the code, it will not be provided... but you CAN ask me to run the code against some stock, future, etc, as a back test to see how it would perform, and if there isn't too many of them, i will be glad to do that. This is to avoid the claim that what i did was cherry pick.

    Note that this came out of experimenting to find some niche trading algorithm that would boost returns, and that starting next week i will be forward testing it manually for day trading, and for swing trading. Not all funds use software to automatically trade. ALSO, many of them take the signal, then manually trade with it, because their positions are so large that they need to do so. They are never going to get perfectly accurate entry and perfectly accurate exits either.

    Other than trade this one myself, my wife and i really dont know what to do...
    When i first got results i was gobsmacked and still am, and still do NOT believe it.

    The method does NOT look ahead at all, and its not complicated with lots of various averages, stochastic points, etc... so its not possible it's fitting to the past.

    let me state this clearly for the sake of honesty:
    It was mostly dumb freaking luck that what i tried and was playing with turned out the way it did, it was just an odd look at it and some playing and then gob-smack city where i have to share it, just cause i dont believe it yet myself.

    Ok... so with all those caveats hoping to negate the most common criticisms i wish to share my results... so far (and welcome some targets to test against).

    First a post to show how things can be off a bit... and that i know this, and that it doesnt really matter as much as one may think. Even less so going forward given that it isnt software that is trading it, and that limit and market orders and other kinds of entries are possible in real life.

    below is one of the kind of oddities...
    And it shows that the graph vs the entry is a bit off.
    The computations are done on the close of the prior candle to the display
    and the buy is at the open price of the next candle...
    TTD-b-example.png

    Given that this algo is great at capturing the long runs, and by best guess is only in about 7% to 10% of the time, its not a huge deal. Even less so if one thinks that one sees the signal, and then enters manually (at least in TOS). AND it matters even less if one divides the results in half just to give it a negative 50% error rate in its consideration!!!!!!!!

    This particular example was pseudo randomly picked. I never heard of the company, dont know what they do, and they came up on a search. TD does not let you batch your back tests or lets you build a portfolio and do so. that will have to wait till i finish implementation on another system that will give metrics on top of just graphic results and sheets records of the trades. Well call it something to look forwards to.

    in this case i was looking to see how it did to see if i could use it to day trade for enough to live on (since i have this time that i am now out of work after 15 years of writing software applications for medical research and a college, and am learning python,and so on and so on).

    After i put these next two images up, i will start another post, as i dont want them to get uncomfortably long.

    This test was a day test set to 1 minute periods, long buying only, and with 100 shares. my live paper test will be the same, but maybe i might do it with 500 shares as a bit more realistic.

    TTDBull.png
    TTD-record.png

    Given enough of a time period, the method so far has not lost money...
    this is why i dont trust it... it HAS lost money in its trading period, but not in terms of the whole. this is why i dont trust it, but am willing to try it. Weirder things have happened in the world...

    next post... 10 year results for a few stock, futures, Forex, and an index (NASDAQ bank). to make sure they are accurate, i will rerun them just for these posts, in case i mixed something up or some such.

    10 year, daily chart, 1000 units (whatever that comes to), and the result side of the charts if they are too long to fit on screen... which if 10 year and daily, will be too long to fit...
     
  2. Artfldgr

    Artfldgr

    the first will be .

    SIGNET (SIG) 10 year back test on TD, 100 shares, Bull (long)
    [i forgot to reset the number of shares... arrrgghhhh!!!!]

    SIG-10yrs-1000shrs-backtest-bull.png

    Max trade P/L: $1,938.00
    Total P/L: $23,181.50
    Total order(s): 140

    note that it only made 140 trades... so it would have been nice when commissions existed
    and one could make up for that low participation rate by diversifying or trading more than one stock at a time.

    here is the trades list...
    Screenshot_2020-01-25 Screenshot.png

    SIGNET (SIG) 10 year back test on TD, 1000 shares, Bear (shorts)
    This time i didnt forget to reset the number of shares...

    SIG-10yrs-1000shrs-backtest-bear.png

    Doesnt take much to see if one looks closely at the image that there is room for improvement.. while the code does great on entry... it can give back a lot on exit..
    but this is my first iteration of the code, and that is something a stop loss or trailing stop loss can handle, which the back test in TD does not have (as far as i know)

    Max trade P/L: $23,440.00
    Total P/L: $238,545.00
    Total order(s): 140

    140 trades in 10 years is not a lot..
    but if you combine both results... and both are 1000 shares.

    $238,135 (long)
    $238,545 (short)
    ----------------------
    $476,680

    Which isnt bad for a initial investment of $5,655

    NOW its clear why i dont believe it, and have a lot of testing and validating to do


    sig-initial-investment.png


    Its Chinese new year, and my wife is Asian, so i have to get going..

    IF someone wants to cherry pick a stock, forex, or future to run, i will be glad to make it my next example... and will still be gobsmacked at the results...

    not believable so far..
    i am wondering how my forward paper tests will go over the next two weeks...
     
  3. your gonna lose your ass, but go ahead and give your money to someone else
     
  4. schizo

    schizo

    I too use TOS and their backtest is pretty abysmal. In your code, allow 1 tick slippage to entry/exit. That alone will likely cut your profit by more than half. Moreover, if you happen to use "displacement" among any of your indicators, it will give you an erroneous result. I suggest you run the OnDemand and see if all the trades line up with your code.
     
  5. Artfldgr

    Artfldgr

    oh, i agree... but the amounts its off is not a lot. not any worse than a human reading it and entering the trade... i am in the process of getting the code in python..

    no harm in paper trading it to see..
    we did find losers eventually, but only in day trading..
    I am confident in it due to knowing the math behind it and its complexity is low
    its not predictive... think of it as being able to tell its current state...
    it oscillates so its in 100% of the time, once your in, there is no reason out
    so far it loses when things are choppy, but not a lot, and the gains from staying in for the longer runs is more than enough to erase it... its open is much better than its close signal... which makes sense given its math.. and given that whats happens before you open a position is not part of that positions performance, but the close is at the end and is part of it.

    i am finding that this is fascinating as i have never seen anything perform this well
    to the point i can believe Stochastix not believing it and being, shall we say, dismissive out of hand...

    no displacement... and given the long runs is where the lucre is, it can miss two ticks and still does very well... and a better platform with more realistic entry and such will just tighten up the estimates, not change the basis of its outcome...

    i have run on demand, and they mostly line up... what doesnt line up is the entry price as there is no way to say buy during the actual tick your in... most do ok, but a few are off which is why i showed it... but they are not off by any serious amount or more than what it would be off if a human was making the orders from watching...

    the forward manual testing is going to be interesting...
    the on demand output is exactly the same as the backtest...

    if i knew a good trading broker that i could run it forwards on, even if just paper, i would.
    same for real trades... given low to no commissions, starting with a really small amount of shares is not all that much an issue...

    regardless. its going to be interesting to see what happens, and what improvements i can add over time... though at this point, i am unsure what the will be given that it goes from a bull trade to a bear trade with no gaps in between... maybe its just going to be how it is, at least for now

    thanks for the reply!
     
  6. d08

    d08

    Individual stock backtests on daily data are basically worthless. Run it across the whole market (or at least most sectors not preselected) and show the results.
     
  7. Artfldgr

    Artfldgr

    Thats why i am working on getting it going in quantopian or quantiacs..
    TD doesnt have that capability.. and thats why i am at least cautious
    not claiming whoo hoo ya ya... though its worth paper trading manually to see
    as i work on python code and mastering how their system works...

    the problem i am having testing a market as a whole is that there is no exit
    once your in something, what is the reason to leave?
    there are better quality choices, and lesser choices, but all stock goes up and down
    and this tracks the ups and downs, with the better performances in things that make longer runs in one direction...

    so you can select a pool, lets say 100, but if you do a market your trading the whole thing and are 100% in without any way to re-balance the portfolio...

    i didn't realize that when it first showed its head
    the past week after discovery of the item, is to master its workings
    ie. why something that is this simple is doing this well
    its not fitting... not enough terms to do so
    its not predicting... it does not look ahead at all
    it loves longer runs and doesn't get faked out easy
    it hates quick turns, which it tends to give back too much (ergo needs improvement)

    its kind of assessing where its standing in terms of itself
    took me a while to realize what its doing but once i did, i believed in it more
    it lose mostly in choppy periods, but you cant predict choppy
    you can only get through them as you dont know when they start
    and you dont know when they end, and often when they do, there is that great longer run

    in searching stock by hand picking it psuedo randomly from looking at all stock on a scan
    the frustrating yet meaningless thing to see is how often its saying to buy before something pops... hindsight is frustrating and its not useful in this case..

    gonna take me a while to get that larger market test...
    quantopian has its quirks
    and i am just starting with quantiacs
    and this is my third week on python
    (though i been programming professionally over 30 years so its not as bad as that sounds)
     
  8. Artfldgr

    Artfldgr

    FORGOT to mention...
    i have done the daily back tests on single companies spanning 15 years...
    they all come out... i am hunting for failures, but quality companies all come out
    even the ones that got stuck for ages, as this is balanced in doing long and short
     
  9. Artfldgr

    Artfldgr

    A Duo of Underperforming Stocks to Ease
    https://finance.yahoo.com/news/duo-underperforming-stocks-ease-174822056.html

    These stocks have underperformed the U.S. market heavily over the past several years. Additionally, they have both stopped distributing dividends. These two stocks have also received moderate sell recommendation ratings from Wall Street sell-side analysts, reducing the hope of a rebound.

    VIVO
    TMST

    So lets see what 15 years back test gives on these
    (im looking to spot test bad performing companies)
    This was why i asked for a few tests, so as not to be said to be cherry picking to show off.

    This will be 15 year runs, 100 share start, daily charts

    Starting with VIVO

    VIVO-BULL-15-yrs-100shr.png

    BULL_2020-01-26 Screenshot.png

    VIVO-BEAR-15-yrs-100shr.png

    BEAR_2020-01-26 Screenshot(1).png


    now TMST
    this is more the kind of stock that this doesnt like
    its choppy, and doesnt make long runs, so there are lots of small trades

    TMST-BULL-15yrs-100shrs.png

    TMST BULL Screenshot(2).png

    TMST-BEAR-15yrs-100shrs.png



    TMST BEARScreenshot(3).png
     
  10. If you use TOS you are just making the market makers that pay for order flow richer. for instance.
     
    #10     Jan 26, 2020