Back to Community
The SPY who loved WVF (or Just another Volatility SPY strategy)

Yes I cannot help myself: we must be able to conquer this beast called Vola

Economic thesis, loosely defined:
1) there is information in the synthetic VIX versus the real VIX or VXX,
2) the Volatility of the VXX says something about the underlying and therefore the real market (Kory)
3) by assigning a low amount of capital to a high volatility strategy you prevent being taken to the cleaners but profit from upside (Alvarez)

Thanks to Kory and Cezar Alvarez, I present a strategy that one could trade, but looking at the tear sheet and the equity curve I suspect that this strategy is its current form and the current market does not perform.

For equity curve jockeys: none of the parameters are optimised, the use of cash is not optimised
For Contest Jockeys: easy to isolate the Alpha with hedging, I can't be bothered with the contests

Further dev:
Alvarez has some more "anti-cleaners" strategies that I didn't implement, one could test them out
Pull in VIX and see whether the VIX and WVF can play nicely

Disclaimer:
I'm not trading this strategy, needs more time and trading guards and I would wait to see whether the strategy is going back to older levels of volatility as the DD in the last 2 years is double from the years before.

Clone Algorithm
820
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 57fa07ae61aee0105968a16e
There was a runtime error.
231 responses

Hi Peter,
Just have to say your previous volatillity algo was so precious for me! I have implemented it in IB and it was great!
Why you think this isn't compatible for LIVE? The rationale I see here is very similar to JAVOLS..

you could trade it, I haven't put enough time in it to say it's robust. I thought I release it to the community and see how others can improve it. The things that I see in the tear sheet looks like the behavior as changed from 2014 to 2016. There is a big difference in returns and beta and that worries me a bit. With a few more guard rails and cash usage it could be traded, but be careful...

Peter, i borrowed your codes and put this together. I got this. It is looking good. So wanted to give it a run in IB. I so new to Python and Q so hope you dont mind .

Clone Algorithm
240
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5806415821d2301059e514f0
There was a runtime error.

Here the TearSheat for it.

Loading notebook preview...
Notebook previews are currently unavailable.

The equity curve of the modified algo looks really nice. What are the main logic differences between the modified and original algos?

looks good indeed, I'll play with it and see how I can break it ;)

Peter, from my observation as the same as the note you put on top of MVP algo. As the algo MVP, Return is a function of look back period (1-20 ) and eps_factor. i was able to do an optimize these parameters( every 2 month period) in AmiBroker and it delivers good result. Im not sure how can i do it in Python(since im so new as this). Also here is the version that aggressive tilt and using your Vol ago to control the portion of xiv and increase or decrease portion of spy and edv..

Clone Algorithm
265
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5808d095ea03a3136cb572f4
There was a runtime error.

Wow, this is awesome. Thank you Peter for starting this thread.

Cesar and I actually live near each other and I recently presented my volatility trading strategies at a Northwest Traders & Technical Analysts meeting (Cesar attended as well). I've shared my volatility strategies with Cesar and we're both working on improving them. Here's our Meetup group if anyone in the Seattle area is interested in joining: http://www.meetup.com/Northwest-Traders-and-Technical-Analysts-NWTTA/

Please message or email me in private if you would like to collaborate with me on coding volatility strategies. I'm a TradeStation user and all my stuff are coded in TradeStation's EasyLanguage. I would love to have them ported over to Python for Quantopian.

Currently I have 5 different strategies that strictly trade VXX and XIV:
- Three of them are long XIV only (50-80% CAGR and 15-35% Max DD)
- One is short VXX only, similar to the ones presented here but has more variables (60% CAGR and 15% Max DD; http://imgur.com/a/w4blx)
- One is long VXX only (15% CAGR and 10% Max DD)

I have everything coded in EasyLanguage so it would be pretty easy for a programmer to port everything over. Unfortunately I'm not a programmer.

Email: [email protected]

Only issue is that the last ago does have some leverage. Any way to ensure there is no negative cash - for Robinhood trading?

A small remark , if you want to trade the last ago live, this line should be changed :

:135: FutureWarning: pd.rolling_max is deprecated for Series
and will be removed in a future version, replace with
Series.rolling(window=28,center=False).max()

not plug and play - you need to define the series.

Is there any way to get help with these changes? Like examples?

For anyone considering live trading NHAT NGUYEN's algo, keep in mind that it's highly dependent on day of the week, this is a form of overfitting and there's no guarantee that it's performance in the future will be as good.

@ Luke, you are right "there's no guarantee that it's performance in the future will be as good". Im using the idea from Grant's algo (which is MVP ) and do a conversion to lite C (Zorro platform ) where i can do optimization and walk forward analysis, Amibroker gave almost the same volatility but about 2% less returns. These are best parameters which deliver the highest return. i did 10 WFA cycles so i think it is stable parameters for next couple of years, algo will perform closely but past is not the future where it is a unknown . For live trading, we may need some nice Python expert in the forum to double iron some bugs in order management, keep track trades, and money management part. Or lower the allocation and watch it like a hawk for couple of months.

Just a word of caution: the algos in this thread so far all use a fixed value for the WVF trigger. That might potentially be dangerous in the future. I don't use a fixed trigger in my VXX/XIV algo but I use a variable trigger that's an EMA of the WVF.

Kory, that's a great idea. If you don't mind, could you share a code-snippet showing how you get the EMA of the WVF? If I tried I think could get a value but it wouldn't be a true historical EMA, only an EMA of the WVF as far as it shows up in my algo using .append(WVF). This wouldn't work well for live trading until after some time had passed

Here is the correction of the depretiation warning line #135
:135: FutureWarning: pd.rolling_max is deprecated for Series and will be removed in a future version, replace with
Series.rolling(window=28,center=False).max()

Clone Algorithm
263
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 580e165cf904011041cc613f
There was a runtime error.

I would like to say it seems no body has done a back testing which covers the time period 2008 where there was big crash bcz. Lehmann. If you do a back testing covers this period, you will find the return is quite different.

Some of the ETFs used in this algo have no data before 2011. This could be the reason why no back testing did which covers the year of 2008.

very insightful Mr Chang

Given "Some of the ETFs used in this algo have no data before 2011", therefore, "no body was able to do a back testing which covers the time period 2008".
This is already True statement. What are you saying ? ......

Maybe - put another way - the concern is that the specifics of this strategy dictate that the backtesting and subsequent walk-forward analysis have only been done in the relatively known and predictable post-2011 market conditions. That certainly is a concern I would have prior to launching a long-term based strategy - how would it have performed during a major market turndown when correlations change dramatically between the ETFs it uses?

My thought? If you need absolute certainty, the stock market isn't a good place to play.

My first objective was reduce the volatility of over all portfollio when i combined these 2 strategies and it accomplished.
Second objective, was optimized and get the backtest results so i can have a relative reference point of results so i can work with when moving forwad ( that was the stage that i publish the backtest).
Third objective, given objective 1 and 2 met and return slightly above benchmark, can i add another strategy to reduce further beta, increase alpha and reduce volatility ( This is the current state that im in )
Fourth objective, if 1,2,3 met, moving to asset allocation models selection and various optimization techniques (parameters, time reference point etc) for over all portfolio and all the strategies combined.

That is usually, my route of designing a new portfolio.

My questions to you is ? Why do you want to put your money at risk when you are clearly not putting enough time to understand how things work.
"This game is long, hard and scary. Risk + Uncertainty = Probability (pulling your hairs off + lack of sleep )= 95%

@Eric:

A absolute certainty can't you never get. Maybe the god could give you . :-)

But what's the sense you do back testing?

@Nguyen,

You wrote a lot here. Why not simply back test your algo in bear phase? For example include the year 2008 and 2009?

In 2008 there was a big crash bcz. Lehmann. After that, exactly to say since 2011 the market goes up continuously. It's a bull market. Why not back test your algo in a bear market?

@Thomas

Everyone trades differently. Different strategies. Different time frames. I'm a very (very) short term trader, so if it works this year, it's good enough for me to use. I don't hold any positions overnight.

I'm aware that because of this my opinion in the matter is moot to most if not all of you guys in the forum because you trade much longer time frames. But since I was hanging around I just threw my hat into the ring.

Also, asking why no one backtests this prior to 2011 almost seems like a rhetorical question, as some of the components didn't exist before then. This too, is moot.

This is Peter's thread so i dont want to post something which doesnt add any value here. And this is will be my last post here.

For Mr, Chang.
First, These are not mine algos, i saw some great things in Grant and Peter' algo so i try to build a something out of it to see how much volatility it can reduce.
Second. I think your logic does have serious problems. Lets me point it out for you.
2 of your posts are have the same question ? and both your questions are already answered by your self.
You said " Some of the ETFs used in this algo have no data before 2011".This is True statement because " XIV and TMF " intercepted date is 2009 and 2011, and this is your Conclusion: "no body was able to do a back testing which covers the time period 2008".
So your declaring statemnt is TRUE .< =>your conclusion is also TRUE. ( You see Mr Chang, your opening statement and your conclusion can go both ways (backward and forward).
Is it right Mr Cheng ? Can you see it. ?
Good luck

Could someone explain to me the basis of the algo, i am new to quant and would like to understand what the parameters are and the rationale behind this algo.

Sorry for being a NOOB

Here is my understanding of this strategy:
Function “Allocate” - The strategy allocates between 5 stocks SSO (2x S&P), TMF (3x 20-year treasury), IJR (small caps), IJH (mid cap) and XIV (inverse volatility) based on highest momentum for the last 6,630 minutes. Not sure why this number used?
Function “allocVol: Closes XIV position if WVF index (based on VXX) crosses below 14. But does nothing if the WVF under 14.
Function “allocSPY”: Opens SSO position if WVF spy uptrending and closes SSO position and opens EDV (long term treasuries) position if SPY in downtrend.

Also, if someone considers trading this strategy , i would consider replacing EDV with some Short S&P ETF (e.g. SDS) and TMF with TLT (due to lower spread and higher liquidity). Because the algo over-allocates to the treasuries, and the reliance on treasuries as safe haven asset that might be wrong during the tightening economic cycle

Here is the version that uses Short S&P ETF (e.g. SDS) instead of EDV and TLT instead of TMF. It should be a safer bet in case of the bonds bear market

Clone Algorithm
198
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 581bef6d6ffc9b0f2472057f
There was a runtime error.

Maxim, that is a good idea. I can wait to play with this idea. im working on my v3 of this algo and trying to put pieces together in C. It is quite interesting and it looks promising by showing low draw-down with high Sharp. Here the idea for you to play, get 1 more strategy that playing stock market like Value investing or momentum that re-balance monthly, then allocate about 40%, Keep the MV algo, which is driving the rest of allocation and also driving the whole portfolio when stock market in trouble.
if market in trouble, put all the allocation of the stock strategy to 1 of safe haven assets and lets the MV algo allocate it weekly until the stock market is trade able again.
My idea is having a diversify portfolio of strategies (between 2 and 4) with continuous allocation between assets. Safer and better returns.
Have fun and good luck.

Very good improvement indeed, let me play with it further as well!

PB

Hi Maxim,

It's realy well done!

But a question: After I run the back testing I found in "Transaction Details" that it happens very often that an ETF is bought but several hours later (at the same day) it is sold again. Is this what you want?

Cheers

Thank you guys, I am really glad that I could make a little contribution to this thread.
@Nguyen. Thank you for your suggestion on how to combine the strategies and use the MVP algo to drive the allocations between them. I will be investigating it…
@Thomas, you are right that the algo can open and close the positions in the same ETFs during the day.
It happens, because there are 2 different processes (functions) used to place the orders for SPY (SSO and SDS) and XIV :
1. @ 10.30 AM - “allocate” function (based on scipy.optimize.minimize function) allocates capital to SSO and XIV positions
2. @15.45 - “allocVol” function closes VIX position if it WVF crosses 14 (based on VXX)
3. @15.45 - “allocSpy” function opens/closes SSO or SDS based on WVF (based on SPY)
In my view, this is a weakness because it leads to overtrading and confusing signals. The possible improvements are: combining the 2 signals (WVF and regression/optimization) or using only one of two signals for signal generation.

Would this algo still be valid if i were to set long_only as my trading settings?

@ Seungmin. Should work for long only, it doesn't short anything but using Short ETF instead.

My contribution:
Change the TMF to the TLT only and get even better!!!

Returns
494.2%
Alpha
0.28
Beta
0.31
Sharpe
2.00
Drawdown
-10.8%

@Michele: Your contribution to Peter's original code or to Maxim's? I found both of them haven't used TMF but TLT. Or maybe you want to write "change the TLT to TMF"? :-)

Cheers

I may apologize for my poor english..
I mean, instead to change both etf EDV and TMF, change TMF with TLT only in the last Maxim's algo and you get sharpe=2.

The issue still remains that there is a fixed value for the WVF trigger - using the best # historically from 2011 forward. Seems like overfitting as this number can change walking forward.

I could change, but remember volatility is not a stock price or so, if the volatility structure changes permanently, othe very base assumptions in the amrket must have changed as well. There could be periods where we have elevated or depressed volatility, but a high vix/wvf value to revert from is pretty safe in my mind. I haven't found a adaptive measure that improves the algo.

First thanks to Peter & Nguyen and everyone else for sharing your ideas. I loved the performance & have spent some time experimenting. Here's my experimentation observations:

  • In a similar to 2008 scenario, the algo will probably lose money, you just have to stay alert. I tried to simulate this by trading a portfolio that didn't include XIV, and had TLT instead of TMF (poor man's simulation) and that portfolio was losing big in 2008. Nevertheless, I think omitting XIV for that period would not materially impact the simulation validity. Next, I built a bullish market filter that only invested when SPY was above of either 100 or 200 day SMA. It protected against the 2008 market but it was impacting the total performance. Even when I was running the full (with XIV & TMF ETFs) version past 2011, the overall performance was being impacted and the 2016 YTD perf was terrible. So, I decided against it & removed the SPY bullish filter.
  • The allocSPY function in some algo versions uses EDV and some versions uses SDS. In my experimentations it appeared that using EDV in momentum markets performs better and using SH in sideways markets performs better. Currently, I am using a linear regression filter to decide when the market is in momentum or is choppy. Momentum means that the R square of a linear regression of 126 days of SPY is above 70%. 70% is a result of instinct and very limited experimentation.
  • I chose SH instead of SDS for the allocSPY because it appears that the algo is in SDS for long periods & SDS has terrible decay. It appears that it is less offen in SSO, so I didn't spend any time with that.
  • I am allocating only 20% to the allocSPY scheme leaving 10% in cash. In backtesting, the code seems to be going into leverage above 1.0 resulting from partial executions. It would perform better with the original 30% allocation, but as a first step I want to make sure I don't go into margin and this seemed the easiest way programmatically to do it. I also moved the spyAlloc 15 minutes earlier to have more time for execution.
  • I added a filter for the daily allocSPY rebalance to only execute trades when they exceed a threshold. In the included test, it is set to $500. This removes a lot of small 1s and 2 shares rebalance transactions for a small capital test.

I would be very interested if anyone has any analysis on how events like Brexit, US elections, FED meetings impact the performance of the algo.

Cheers

Clone Algorithm
165
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 58310297ddb07b6407d1a3f6
There was a runtime error.

Anybody trading this live? I added it to Robinhood, and seems something is wrong, yesterday it sent an order for TLT only and not TMF and XIV.

I'm trading a variant of this live in IB. As there are so many versions here, which version did you put live?

Using Maxims Version, actually I think it is behaving fine, it matched the order, I just thought it was going to sync the current positions, but it just waits for the orders to add up. Also, for 2008 if there isn't a bond market collapse/stock collapse at the same exact time, wouldn't this perform well as it would jump into Bonds?

@Takis
Did you try lowering the MA period say 20, 50?

I am also using Maxim's latest version in live trading.Since 7th November, it has made 11.39%, so I am very happy.Most of the profit has come from XIV positions, which I assume was the original intention.Sharpe ratio of 5.27 and Max Drawdown of 2% is impressive.

Anybody else try to rework this to test past 2008? I guess even 40% DD wouldn't be bad with like 50%CAGR and the low DD during normal market conditions.

Hi Elsid,

See the post above. I've asked the similar question before. But it seems my question was taken as "stupid". :-)

Hi Elsid,

Is there any argument to support your "guess"? :-)

Hey Thomas, I mean I completely messed around with all the symbols turning them into SPY and TLT as a "short" so probably messed something up, given that TLT isn't a short anyway but thought would perform well given that bonds rallied, and TLT was the best performing ETF at the time, but with doing that the drawdowns were about 40% or so, just as much as the market.

Given that in good years like recently the DD has not been more than like 15%, I guess you can kind of gauge an 08' type scenario by stopping the Algo at a 20-25% DD, then you know something might be up. Given that it has amazing DD the last 7 years including, all the craziness of Flash Crashes, BREXITs, ect.it seems pretty robust, and might of possibly held up in 08'

But somebody needs to rework the Algo even just as a backtest algo, maybe just use funds like TLT SPY and instead of long XIV go short SPY, just to see how it would of held up in 08'

"I guess you can kind of gauge an 08' type scenario by stopping the Algo at a 20-25% DD, then you know something might be up.". Yes, this is 1 way to do it, i would take it offline when it reach 15 % DD, which is my tolerance level. I have been running my the first version i posted but re-balance every 2 weeks => performance is outstanding. (since October)
Since Nov i put 2 of variations that included value growth stocks algo in my IRAs => Never happier with the performance.
In fact all my fund is running this algo with different risk parameters ( different allocations).

Good luck.

@Mark Varney, i agreed it is doing quite well, my return is little bit more for that version. Just sit back, enjoy the ride and wait until some not normal event then react.

For those that are trading this live, watch you leverage. In running a PvR routine there is unforeseen leverage in the backtest. IE, where there are sells and buys on the same day you may encounter leverage.

We need to build in a check to see if there is available cash to purchase - otherwise the algo, as of today - will issue a buy as soon as the sell is issued and puts the account in margin.

@Nhat

Where is the code for rebalancing? Also, have you noticed a performance gain from the original with the 2 week rebalancing? Also, about how long does it take for all the positions to catch up and match the Algo, given that it doesn't sync current positions.

1/ "Where is the code for rebalancing? " i do not have in this platform. i use different trading platform and it is in C. but you can add it in yourself with an if statement or someone in the forum will help you
2/ " Also, have you noticed a performance gain from the original with the 2 week rebalancing? ". slightly better for this period ( i do not have backtest and stats to conclude that it will perform better in long run).
2 weeks because XIV keep up trend so i get in XIV cheaper and hold longer => slightly better results.
3/ about how long does it take for all the positions to catch up and match the Algo, given that it doesn't sync current positions. <= do not understand the question.

Any ideas on how to ensure the sells happen before the buys? I ran a backtest from Nov 7th and so far the cash hasn't run out for most, but trust me you will encounter negative cash during a rebalance.

How long does the negative cash balance last? Permanently, or until everything gets rebalanced?

In the versions with both Allocate and allocSPY functions I notice that it buys SSO in the morning (Allocate function) and closes the position in the afternoon (allocSPY function). Is that by design?

Cash low hits the day of the rebalance and slowly claws back throughout the day while the other positions sell

I guess that would be an issue with RobinHood if you aren't subscribed to Robinhood Gold and have Margin, even then i don't know how big of an account i would hold with Robinhood given their financial stability, I guess safest bet is trade on IB.

hopefully you have above $25,000 in margin. The cash low grows when the algo makes more money as more shares are being rebalanced.

I think a permanent fix would be to ensure the sells happen before the buys, which I also believe will significantly reduce the gains the last 3 algos generate.

Yeah I just had Robinhood reject my XIV order. So how much margin do you need just $25,000? Or pretty much double the account? Which pretty much every broker gives you, so you shouldn't really run into problems. During the backtests I only see it go above 1 every so often and only like 1.01 1.03 ect.

I found that the record leverage takes the average of the day or the leverage at the close of the day and ultimately week.

The PvR routine captures the cash low/max leverage as of the minute. It does not specifically double the account I just saw at one point the cash low was -$25,000 and I stopped the backtest.

@Tyler, yeah that shouldn't be an issue at least for myself, also what was the account size when you saw that leverage number?

Actually thinking further about this, the strategy would of probably performed well in 08 also, maybe a bit larger drawdowns, I think Takis's poor mans backtest for 08 is flawed, because the function allocVOL uses VXX/ZIV to calculate WVF, unless he fed it custom data there is no way to get this data prior to the funds inception dates.

But given the significant events we have had since 08+, with flash crashes, brexit, euro crises, and given it takes a high exposure to bonds i can see it performing well in 08' also, i guess the only time you would have significant losses would be if both VIX Spike and bonds crash also. Also, in 2011 VIX spiked to about 50% and this only had a DD of about 13%, so in 08' when you spiked to around 80-90, if you double DD, which probably wouldn't happen you would still be looking at 28% or so which is still great for about 50% Annual returns.

The algo above is some good code, just that the leverage goes to 1.43 so returns are lower than they appear.
Try https://www.quantopian.com/posts/max-intraday-leverage to keep an eye on that, it will give you a better chance of doing the best possible.

I looked into the leverage and the overtrading and in the version of Takis Mercouris Nov 20, 2016 I still see a lot of overtrading: SSO gets opened and closed on the same day which can be interpreted as sponsoring Interactive Brokers or other trading partners. The p[erformance will increase if one published that version without the double trading: probably the signal or trade generation should be handled in one function so conflicting signals can be weeded out.

Thank you all for sharing and adding to what looks like solid system system. Is there any explanation of the system anywhere?
Regards,
Douglas

Here is the backtest with PvR Routine: max leverage 1.54 cash low reaches - $37,577

This is the algo from Nov 3rd 2016

Clone Algorithm
42
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 58861d0ca15a745df78df0ff
There was a runtime error.

After digging in a little further, it looks like it only due to the allocation code - Is there a way to ensure the sales in the allocation are performed before the buys? Looks like all the purchases happen before XIV is sold.

Yeah I think the allocation code needs to be reworked a bit, especially for brokers that charge commissions, for example all the 1 share orders, would also be great to use with Robinhood without running into Margin issues.

I added an EMA (seeded with original 14 value) for the WFV limit. Source of this one is from Takis Mercouris Nov,19.

Question for those running versions of this in Robinhood: How are you avoiding free-riding on unsettled cash? From what I read in the docs it doesn't look like Robinhood's margin (Gold) accounts are fully supported.

Disclaimer: I've never written anything in python and this is also my first exposure

Clone Algorithm
34
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5888c457f5674e5e39e02940
There was a runtime error.

@Doug

Just messed around with your algo a bit, the past ones perform much better and slightly lower DD, don't know if it's the EMA or the slight leverage. Anyway I think the focus for this Algo should be to somehow get synthetic data loaded to backtest it past 08 and even farther if possible, and fix some of the order logic.

Quick question, given that I'm new here if i change the code and re-deploy the algo with current open positions I'm assuming the algo will be able to pick them up and rebalance correct?

@Elsid -- I'm live trading a version of this algo at IB, and sometimes I'll stop/start the algo when I add more funds. Otherwise the metrics on the website are off, FWIW.

It seemed to have no problem rebalancing with the new account value. I have only done this once, but it worked as expected.

Did anyone come up with a solution to eliminate those pesky 1 share orders? The algo also sometimes tries to order more than the available cash balance. I've been manually handling it for now.

@John

Hey John, do you use a 2nd IB login to login into your account and check up on it?

That's good to know, also when it goes into leverage is it permanent or temporarily while it's rebalancing?

Yeah those 1 share orders eat up like $2 in commissions, have to check IB commissions and see the options again I remember there was a per share rate too without that $1 minimum in commissions.

Thanks

@Elsid -- yup, I have a login specifically for the algo and another for manual use.

Since my account is an IRA - no real margin - the algo can't go beyond leverage of 1. IB will reject the order.

I just looked at my account statement, and those 1 share trades ate up about $15 in commissions over the course of a month.

I don't remember exactly, but I thought there was $1 per trade minimum, regardless of number of shares traded.

In another algo I run, I have it filter trades based on either trade size (in dollars) or as a per cent of the overall account, e.g., don't execute the trade if the trade size < $X or less than X% of the account size. I haven't put that code in this algo yet. Probably should.

I think there were 2 options dollar minimum or per share without dollar minimum but you would end up paying higher commissions per smaller orders, I have to double check.

Also please post the order size code when you get a chance, or I guess If we fix the order logic can trade on Robinhood and not worry about commissions I just don't trust Robinhood from a financial standpoint they can go bust, assuming you trust SPIC but I remember reading that technically there was some wording that would make pretty much everyone not able to get anything from the SPIC the way it's worded.

So I'd rather put somewhat more trust in IB given the strict enforcement of margins and risk they take.

I've been tinkering with this algo for the past week and have tried to fix some of the issues I encountered along the way. I am relatively new to Python and quantitative/algorithmic trading so please be easy on me:)

Here's the main issues I found:
1. Two of the allocation methods operate on the same symbol (SSO) and can step on each other. For example "allocate" could give SSO 50% of the portfolio only to have that adjusted to 30% later in the day by "allocSpy" causing leverage issues or resulting in the portfolio not being fully invested.
2. "allocSpy" rebalances every day, often in 1 or 2 share orders, while "allocate" rebalances once a week. This can cause the leverage to get out of wack since "allocSpy" uses a hardcoded value instead of the actual amount of the portfolio it represents. Also generates a lot of extra orders
3. Majority of end of day over leverage issues were caused by using EDV which would consistently not fill orders.

Changes I made:
1. Have "allocate" work with 100% of the portfolio
2. "allocSpy" only triggers orders if bullish/bearish spy positions sized by "allocate" should be swapped. Simply swaps the sizes of the positions.
3. "allocSpy" and "allocVol" don't execute on weekly rebalance day.
4. Upped to all 3x leveraged etfs except for the small-cap since I couldn't find one that consistently filled. Going with the higher leveraged ETFs didn't really change the risk metrics much versus non-leveraged etfs.

The overall result has fairly similar or better sharpe/sortino ratios compared to the previous algorithms. The volatility is higher, as is the max dd, but not astronomically so. The one glaring difference is that beta is near one, which is much higher than the previous algos. Also cuts down on total trades by about 700 over the six year backtest period. There are four partial fills that cause end of day leverage to go above one, but those are corrected for by the next weekly rebalance at the latest.

@John I'm thinking of opening a Roth IRA with IB and running this algo on a portion of it and was hoping you could answer a few questions since it sounds like you're doing something similar:
1. Are there any restrictions on buying leveraged etfs such as TMF or UPRO?
2. Are wash sales not an issue due to the tax-free nature of an IRA?
3. Is main benefit of a margin account you get the ability to use sales proceeds immediately?

Clone Algorithm
112
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 588f979e22f46d6240403c40
There was a runtime error.

Hi Caleb --

To answer your questions --

  1. Are there any restrictions on buying leveraged etfs such as TMF or UPRO?

None that I know of. I trade UVXY, SSO, SDS, etc without complaint. IB will send you a notice letting you know you are trading a leveraged vehicle.

  1. Are wash sales not an issue due to the tax-free nature of an IRA?

Not a tax expert, but as I understand it, wash sales only pertain to your taxable account. IRAs get involved if you trade "substantially the same" security in both taxable and non-taxable accounts. Then, if you buy a security in the IRA that you sold in the taxable account, the wash sales rule applies to your taxable account. One way to avoid it is to not trade the same security in both accounts.

  1. Is main benefit of a margin account you get the ability to use sales proceeds immediately?

Yes. With a limited-margin IRA, you avoid the "free-riding" restriction in non-margin IRAs. Otherwise, you have to wait the 3 day settlement period. ou still can't exceed a leverage of 1 though.

We'll have to look further into why your modded algo now has a beta of 1. Draw down at 25% is a bit rough for me as well. In roughly the same time period, the version I'm running has a beta of close to 0, draw down of 10%, but far less return than your version. More like 380% vs your 2800%.

Hi John

Thank you very much for the info.

Regarding the beta issue, my thought is some of it has to do with the previous versions stepping on their spy allocations and taking them from high down to .3. Since it spends a lot of time in whatever spy etf you use, this could be significant. Also using the 3x etfs could be a factor:)

Here's a version that doesn't use leveraged etfs and only uses 70% of the portfolio. Returns and draw down more in line with your version and around .5 beta.

Clone Algorithm
112
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 588fc444b5b7c45e1d525dda
There was a runtime error.

Guys just reworking some of the ETF's such as using TQQQ and removing 3X small cap (biggest contributor to DD) You get this:

4750% and around 15% DD

Someone needs to verify this code because results seem mind blowing with this DD

Enjoy : )

Clone Algorithm
51
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 589002b10f30c5484283809e
There was a runtime error.

My only concern with this Algo for future proofing it seems that a tremendous amount of gains come from Treasuries, if we get into a bond bear market DD might sky rocket, and performance suffer tremendously, I have tried playing around with using inverse etfs instead of treasuries but it still doesn't compare.

It would be nice if someone did some research, or even messed around with the strategy to get it to comparable performance DD levels, with just going inverse the underlying long securities. Even if it performs a 4th of the above at 1000%, it's still around 50% Annual returns with low DD.

Hi guys,

Returns above 4000%? I would like to say you are getting more and more crazy !!! :-)

@Thomas I guess Nasdaq outperformed S&P hard lol, dem FANGS

Hi all,

I've just finished to work on a previous version of this algo. My version is a little bit different from the original one:

  1. It trades TLT instead of EDV --> the first one seems more liquid
  2. It sells on Monday and it buys on Tuesday --> in this way it avoids a leverage over 1.0
  3. alloc_spy function has been split in 2 functions: a sell one and a buy one, which work one at the beginning of the trading day and the other at the end --> in order to avoid a leverage over 1.0

Let me know if something in my version is wrong.

Clone Algorithm
41
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5889ccec626a196182f63465
There was a runtime error.

Hi Elsid,

What does S in FANGS mean? Till now I've just heard FANG.

Besides, you said the QQQ outperfomances the S&P. But in Trumps time maybe it could change? Maybe the traditional values will take over the party?

Thomas

Hi Gregorio,

Your codes look quite clean and well-formed.

Thanks Thomas.

Here I have a new version of my previous algo.
The main updates are the following:

  1. It uses different ETFs (the ones of the last algo of Elsid).
  2. AllocSpy_buy now doesn't work: if I try to enable it, the leverage goes over 1.0. I still have to work on this.
  3. Return is 100% higher than the previous, but the DD is double: from 13% to 26%.
Clone Algorithm
8
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5890776e9873655e2925a525
There was a runtime error.

@Elsid your algo ends up having a leverage - although only for a day until the sell orders happen - of over 2. I think if you get the leverage under control your returns will diminish.

Wow, I'm very impressed at how far this post has come along! The WVF indicator is quite a powerful tool for VIX ETN traders. I've been working with Cesar Alvarez on a really cool long-only XIV algo that's based on the RSI; will post updates soon! Meanwhile, here is one of my other more "conservative" VIX ETN algos that only trades XIV, Junk Bonds and Treasuries.

I combined this simple junk bond momentum algo (50%) with a newer version of this XIV algo that uses the WVF (50%). However, for the algo below, the WVF uses exponential moving averages of itself as variable triggers to trade instead of just using 14 as a fixed value for the trigger. If you wish to make it more "conservative," simply allocate less to the XIV portion. 25/75 is a pretty decent mix, too. My buddy Jacob and I actually submitted this algo for Contest 24, but only as a rough draft to feel out the Contest's requirements. Funnily enough, it's 2nd place on the un-hedged leaderboard right now. It was 1st place on the un-hedged leaderboard for all of December.

I highly recommend using variable triggers instead of fixed ones for the WVF as well as most indicators.

Author: Kory Hoang
Developer: Jacob Lower

Clone Algorithm
49
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5890a9616be9815e2af4b013
There was a runtime error.

Here's a tear sheet for the algo above.

Loading notebook preview...
Notebook previews are currently unavailable.

@elsid, @thomas...Hate to rain on the parade but I think the QQQ results are due to dozens of TMF orders being partially filled. Starting with a lower initial cash value that only generates 3 partial fills, the results are actually not as high as SPY. The risk ratios are better though, and beta and max dd is lower.

Clone Algorithm
6
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5890c24db6c47e5e40fd2db6
There was a runtime error.

@Caleb - I agree. If you backtest each year by itself returns are not as good and drawdowns increase.

This leads me to believe partial fills.

Yeah completely forgot about the partial fills, Just turn the slippage on to 0 which is more realistic given that there is hundreds of million and billion of dollars worth of volume, when I turn it to 0.

I get 3297% -21.2DD
only partial fill is some XIV shares on 12/03/13

Also, an interesting thing to think about, if it's possible to copy the logic of the partial fills on TMF, maybe lower it's allocation to get results more in line with the backtest?

Caleb, you could also try this:

Clone Algorithm
33
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5890c26892df695e24d1849c
There was a runtime error.

Guy it's the same problem partial fills uncomment this line set_slippage(slippage.FixedSlippage(spread=0)) and you will see more realistic results. Now like mentioned before i wish you could code up something to copy the random partial fills, would turn it into an amazing strategy lol, maybe try introducing random partial fills on TMF.

Caleb, just in case you wondered, there was no code change at all. Not a single character.

Only the capital was increased to $100k. That is a 58% CAGR!

2x leverage happens on rebalance days then normalizes back to ~1 maybe a little over. So you will need a margin account and pay some margin fees

Elsid, the set_slippage is commented out, therefore, the strategy reverts to its default commissions and slippage values, if I understand Q correctly. This makes it already more realistic.

Tyler, the 2x leverage is more than acceptable. You could use the following as a ballpark figure: A(0)∙(1 + r – l)^t. An estimate gives: 100,000∙(1 + 0.58 – 0.05)^t. More than enough left to pay for the margin interests. Note that currently IB charges less than 0.03 for margin.

I think their default is overkill and doesn't make any logical sense, how can you not fill a few thousand shares by end of day say a $5,000 order, for an instrument that has $1,000,000,000 in trade volume? There is no way you will have filling issues with such highly liquid ETFs unless you are trading into the millions, or a flash crash or something.

Elsid, yes. It is part of what I like about Q. They can at times give you more adverse simulation conditions than in real life. And that is good. It forces you to do better, and be better prepared for adversed trading conditions.

Is the issue how it is traded, or how much does it make?

I have not read the code yet, but now, I will. I want to know what makes it tick.

Adding a smidgen of leverage by raising the RISK_LEVEL to 1.2 would generate $2 million more in profits. It looks like a small price to pay for a 62% CAGR.

Clone Algorithm
85
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5891389e408a2561613e3935
There was a runtime error.

Word of caution, as discussed earlier we might be heading for a bond bear market - a huge portion of the returns in this algo is from treasuries. I would hate to hold a 3x Bull Treasury during a bear market.

Edit: The beta is also above .80 on the last couple algos - way to dependent on the market for me.

Tyler, your concerns are justifiable. But, even if you have an automated trading strategy, you can always shut it down at a moments notice for whatever reason. Meanwhile, for the past 6 years, the strategy would have been doing fine. During those 6 years, everyday you had news stories that the market was going down, soon, real soon. During all that time, the strategy would have prospered with an impressive CAGR. High enough to put you in the 0.1% of portfolio managers.

You must have noticed that the strategy has some built-in alpha. I still don't know exactly how it is generated, but I can see it is there. While most strategies show a small spread compared to the SPY benchmark, notice that this one has an increasing spread, not just for small period here and there, but over the entire duration. Using an equation, I would write:

A(t) = A(0)∙(1+(r+α) – l)^t = 100,000∙(1+ 0.62 – 0,05)^t , as in the previous post.

Some might not like leverage, but I see it as a matter of taste, a matter of choice.

Tyler, I would like to add concerning your last statement that in a rising market, you also want your portfolio to rise in value. It will therefore be highly correlated to the market.

One could push for more, increase the spread compared to the SPY benchmark. Doing so might increase the beta, drawdowns, and volatility.

Is pushing for a RISK_LEVEL of 1.4 worth it?

Again, it is a matter of choice. Here, the equation would give:

A(t) = A(0)∙(1+(r+α) – l)^t = 100,000∙(1+ 0.69 – 0,05)^t. A 69% CAGR!

And the backtest:

Clone Algorithm
85
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 589147cbff6bc55e289898dc
There was a runtime error.

Again Guy, you are painting a false picture with Quantopians default fill, you are getting much more performance and a much lower drawdown than you would experience in real trading, contrary to Quantopian being more realistic in backtesting, it's the complete opposite with small assets and very liquid ETFs.

You even mentioned yourself you want the worst results possible to improve from there, the worst/realistic results are getting filled completely which will most likely be the case in real life trading with such low amounts.

Raising the RISK_LEVEL of 1.6 might also be worth it? It will raise the beta, volatility and drawdown. But, will generate:

A(t) = A(0)∙(1+(r+α) – l)^t = 100,000∙(1+ 0.76 – 0,05)^t. A 76% CAGR!

Most of the time, the leverage stayed below 2.

We should note that no one could offer a 76% CAGR without taking some added risk.

Here is the backtest:

Clone Algorithm
85
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 58914f24c1075d61f0418042
There was a runtime error.

Elsid, I do not agree. The worst scenario in a rising market is not to be filled, because then you are missing on profitable opportunities. And one thing you want in a rising market, is to have your orders filled. Therefore, the partial fills, or canceled orders become adverse conditions, worse that what the market has to offer. But, like I said: I like that.

I want adverse trading conditions (partial fills, delisted stocks, outliers, black swans), whatever they have. Make it as real as possible.

However, I did not say that I wanted the worse result and go from there. I only mentioned trading conditions. But whatever the results, I will go from there. Just as the last few backtests that have been presented.

Wouldn't this be easier? Aren't the returns obviously 4000% higher?

Clone Algorithm
7
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 58915d2d7d9f4061602b5966
There was a runtime error.

Also CAGR is closer to 100-120% according to investopedia, unless their calculation is wrong.

Pushing the RISK_LEVEL to 1.8 will raise the average leverage to about 1.8. Evidently, it will raise volatility, beta, and drawdown.

This series of tests was to find some of the limits of the trading strategy. At what drawdown level would I say: enough. At 0.10, 0.15, 0.20, 0.25, 0.30 or 0.50. It is a matter of choice. One could select his acceptable drawdown level, and go from there.

Some are more risk adverse than others. But, if you do not do the test, to see how it would have done in the past, how the trading strategy would have behaved, how could one have an idea of how it might do in the future.

The game is a CAGR game, and as such one should seek the shortest doubling time. At a 10% CAGR, it will take 7.3 years to double one's trading capital. At that rate, in about 22 years, one should have reached 8 times the initial capital. While at a 60% CAGR, after 22 years, one might have reached 30,000 times the initial capital. That is what is at stake. What is your drawdown tolerance?

One thing is sure, there will be drawdowns no matter how you look at it.

The 1.8 RISK_LEVEL backtest:

Clone Algorithm
85
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 589156719c31735e492b0d15
There was a runtime error.

My point on the previous message and backtest is to try to get through to you guys.
In the GF code a little while ago showing 12000% returns, it spent almost $12 million. You could think of that as just pure leverage except Quantopian's returns calculation is done on the original $100k, ignoring the millions. Let me know if you find a broker who will loan you millions without any accounting. Keep track also of cash_low as one way to catch that, apparently watching max intraday leverage is not enough. PvR is the other route, the one I prefer.

In the GF code, the returns show that it made 12,054,048 using the 100,000 that it started with.
No, it made 12,054,048 using 11,756,331. Maybe I'm just old-fashioned, my math teacher would have said that's 103%, not 12054%.

@Blue please rephrase in more layman terms. Only Issue I see with the past leveraged backtests, including the higher drawdown from things probably filling in real life which is still only about 4-5% higher.

Is that leverage goes above 2, which broker gives you more than 2x leverage?

Also, we can all each play with backtests all day long for each risk/performance scenario, I'm more interested if someone can figure out how this would of performed during 08? Would it have dropped XIV during the largest drops of 08?

In laymans terms, in the real world you can't borrow millions and then just declare that to be profit. There's a discussion on it. If anyone is able to comprehend my point, please explain it in your own words different from mine.

@Blue,

Whatever I ignore the cumulative values anyway, and just add up starting amount to finishing amount and figure out CAGR, and go based off of that, I'm assuming DD values are off too, so add another 5% to them to be safe. I'm going to be switching to the old version before the latest updates with some leverage, don't mind the 1-2 share days per month, what's that like an extra $20 in commissions? I guess I can pay that as insurance for a lower DD.

Until then I'll wait for a reworked version that fixes those 1-2 share problems, leverage but doesn't effect performance. Unless the numbers are completely wrong according to Blue, then can't really compare different Algo versions apples to apples.

Take a look at this Backtest posted Blue, does the true performance seem accurate? Just taking ending value/starting value it should be around 26X, so the total performance is pretty close.

Clone Algorithm
130
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5891646e7b93265e2520790e
There was a runtime error.

Take a look at this Backtest posted Blue, does the true performance seem accurate?

Profited 260,356 spending 173,247 for real returns of only 150.3%

A normal person would look at returns of 2591% and conclude that returns were 2591%. That's only true to the degree that 100% of the initial capital was utilized/risked/activated and no more. For those who don't believe it, the returns calculation used by Quantopian currently can be seen at https://github.com/quantopian/zipline/blob/master/zipline/finance/performance/period.py. So the returns on amount invested (which is what every investor wants to know unless I'm mistaken) can only be obtained by keeping track of how much was invested. Thus to succeed don't be a normal person. My real money algo is up 80% after 62 days by the Quantopian calculation however since it has not yet spent all of the initial capital, return on the amount invested/risked is 104%. Use PvR and see clearly. To your wealth! :)

Ok I see what you mean, and quite don't understand why you would want to calculate returns that way lol. And no people don't want to know the returns on the amount invested, they want to know that their investment of 10K grew into 200K. It's not like you started off with 173K, you started off with 10K. The 173,000 already has an exponential return in there as it's not your money, but grew from the initial 10K.

No offense but I think we have officially entered into bizarro world here, people talking about total spent money as far as returns are considered, and thinking "proper" back-tests are the ones that have half filled data(even though quantopian specifically mentioned they made it so aggressive for the purpose of low volume stocks, not Billion dollar securities), wrong CAGR calculations.

But it's still good makes you think about backtesting, and calculations more deeply.

Hi guys,

I would like to say, the total returns is not the annually return. The total returns is really calculated from (End / Beginn) *100. But the annually return is calculated somewaht like (End of this year / Beginn of this year) * 100, right?

This means, the total returns seem very high, said more than 6000% or even higher. But the annually return could be only 150%, 100% oeven lower?

Cheers

To myself, I am more interessted in annually return.

Blue, I think the issue is that the leverage is not held the entire time. it only happens during rebalance and drops back down to ~1

Blue, going for leverage is a matter of choice.

The equation for the leverage was given, it is:
A(t) = A(0)∙(1+(r+α) – L)^t. As long as: α > 2∙L, you will be ahead. As long as your drawdown does not reach -100% as the example you provided! Since then, leverage or not, you are out of the game.

The leverage fees are pulling you down, but the (r+α) are pulling you up. And this is compounded over time.

To calculate the difference, one could say: A(t) = A(0)∙(1+r+α)^t without the leverage as Q reports it. And use: A(t) = A(0)∙(1+(r+α) – L)^t to have an estimate of the total margin cost.

IB charges less than 3% margin. So make the margin 5%∙100,000 = 5,000. On the other side, r+α could be higher than 20%: 20%∙100,000 = 20,000....

Taking the 1.4 RISK_LEVEL backtest, you get:
A(t) = A(0)∙(1+(r+α))^t = 100,000∙(1+ 0.69 )^t, as reported by Q, and
A(t) = A(0)∙(1+(r+α) – L)^t = 100,000∙(1+ 0.69 – 0,05)^t, when deducting leverage fees.
The difference between these two is: 384,166. Those were the added expenses associated with the higher return.

The added leverage resulted in a total return of: 8.677 millions – 384,166 = 8.292 million.
Probably worth the expense for some.

In payoff matrix notation, any stock trading strategy can be represented as:
A(t) = A(0) + Σ(H.ΔP). When you add a 1.4 leverage, all it does is: A(t) = A(0) + 1.4∙Σ(H.ΔP). It is not used by the price, but by the inventory holding. Meaning that the bet size increases by 1.4. There will be margin charges as illustrated above.

Some like it, some don't. I see it as a matter of choice.

However, a caveat, not all trading strategies can support leverage, some are really bad at it. On the other hand, some strategies can, and I think this one can.

@Thomas

Yes, and you also can't take the total cumulative amount and divide by 6 years for example still gives you a wrong number. You can take the starting amount and ending amount to figure out CAGR, just use a calculator online.

The other thing I can't get over is the dismal performance in 2013 compared to the market - with the high beta you would think it would have correlated more. I mean it made money, but did not outperform a simple buy/hold strategy.

With all the talk of leverage and margin I just wanted to share my latest code that attempts to not go into margin at all. Basically just breaking up buys and sells.

Max leverage never goes above 1 and cash low is -$53 and that isn't until well into the backtest.

Also added PvR, which I don't 100% understand yet, but the results seemed good.

Note: the cash return is basically the same as when running buys/sells concurrently. % return is just somewhat lower because I upped the initial cash a bit to have a little cushion.

Clone Algorithm
112
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 58927abb7dcf1c5e41b816ed
There was a runtime error.

@Caleb

How come you removed TLT? Maybe it would lower drawdowns having some sort of allocation between TMF & TLT like the past algos.

Great results and discussions folks. thanks for sharing .

If I am not wrong, it's essentially a min-var strategy. it's little bit tricky (and interesting) when thinking adding volatility based ETF into the porfililo since volatility (variance) is what the core algo mean to minimize.

Now those without margin accounts can make use of this code too, really great, Caleb Sandfort, that's some magic in your code above.

This was a start toward adding TLT in zero-beta targeting, in case anyone wants to work with it. It does reduce Beta however then creeps upward with only a few shares being traded and cash drifts downward. Also in the example code/link most of the profit came from TLT so it should not be necessary to lose this much in returns IMHO. Note that ideally one would dynamically adjust stock picks coming in from pipeline based on their Beta values instead I think. Pardon all the vertical alignment going on, I just have trouble reading code without it.

Clone Algorithm
40
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5892c41d9b82845e3ab16fce
There was a runtime error.

Ran Blue's latest version with $100k. Impressive CAGR: 45.5%.

Here is the backtest. No other change than the initial trading capital.

For those that don't like being on margin, this is great. It can put anyone in the top 0.1% of portfolio managers where all you will live by is your CAGR on the total initial capital that was put in your care.

Clone Algorithm
28
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 58935ec3024c7e61fa0c0101
There was a runtime error.

I haven't yet had the time to study this algorithm, but I only see backtests going back to 2011. Has anyone found any appropriate substitutions to backtest this algo against data prior to 2011? The returns everyone is posting seem too good to stand the test of time. Looking forward to digging into it and understanding it better...

Jake this was discussed earlier just search the thread for '2008'. Part of the issue is that some of the ETFs used here didn't exist long enough. Some people did try to create simulations which were interesting. Search for Takis Mercouris for his insightful post.

@blue @elsid do you think it would be more conservative to set slippage to .02 for these etfs?

@Jake @qqt

I think to get a proper pre 2008 backtest we need to get synthetic VXX/XIV data, you can then play around with the ETF's such as using none leveraged ones like just plain ol SPY and TLT then just apply Margin to see how a 2x 3x fund might of performed.

Everyone should read through and thoroughly understand any algo before trading it.

Reading through the lastest one, I see lines of code like this with no comments:

    if is_date(2013, 12, 3) or get_open_orders():  
        return

    for i,stock in enumerate(context.stocks):  
        if stock in [context.spyish, context.tltish]: continue  
        if is_date(2011, 3, 1) and stock is context.mid_cap_stock:  
            ...  

When you are altering algo logic based on dates, it means that it has look-ahead bias.

@Mohammed

The first date check is just skipping a weekly rebalance because XIV order wouldn't fill at all no matter what on that day.

Second date check is just switching what mid-cap stock is used because the first one wasn't available before that date.

Thanks for clarifying Caleb. I have two issues with this:

  1. Why isn't the code commented for this? This is programming 101.
  2. This is still look ahead bias. "I can't order XIV so I'm going to exclude other orders too" - that is not real world trading. There may be times that your orders wont fill - that is something you have to live with.
    Also, switching mid-cap stocks part way through a backtest is basically using hindsight - i.e. look-ahead bias. Wouldn't you agree?

After running Blue's latest version of this program, I notice that slippage was set to zero. Therefore, had to redo the test. Put it on Q defaults by commenting out the slippage line of code.

Here are the results. They are more modest having a 25.0% CAGR. The difference in these two simulation has to be due to the commissions and slippage charges, since I did not change any other line of code.

The impact is considerable.

I do have a question. Why did it take hours to run this test?

Clone Algorithm
28
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 58936a78e8d6485e354bca39
There was a runtime error.

Why did you comment out the slippage?

The default slippage does not account for these highly liquid ETFs. There is no way it would take all day to fill 1,000 shares of TMF.

@Tyler

Just Ignore him, tried explaining this to him like 10 times, he also calculates CAGR wrong. Let him be.

@Mohammed

  1. I'm used to working on code that only I work on and am intimately familiar with, so sometimes my comments are lacking since I know what is going on and don't have to worry about other people trying to figure it out. But you're right, if I'm going to share it, comments should be added.

  2. I agree in general. With this particular trade though, XIV traded nearly 8M shares that day and it couldn't fill a 800 share order, didn't do a partial fill or anything. Seemed like a bug with Quantopian and it was messing up my overall max leverage tracking which is something I was spending a lot of time trying to keep under 1. The change in returns is miniscule when commenting the check out.

With the mid-cap stock switch, it happens only 2 months into a 6 year backtest. SCHM, the etf it switches to, was from my mid-cap etf research the mid-cap etf I wanted to use, wasn't available until mid Jan, so I just gave it a month to build up it's history so it would function properly in the allocation code. If the switch had occurred at a specific time in the backtest when I had determined they should be switched on based on past/future performance then I agree that would definitely be an issue.

And as covered earlier, all of this could have been explained with comments:)

@Mohammed,

I don't think the date plays an important role it was just excluding that one date, and allocation to midcap exist anyway in the code, not like the date matters since, 2011 is basically when most of the ETFs started trading anyway.

Lastly, these are the newest versions of the algo that might have these potential issues the nguyen & subsequently Maxim's versions don't, and if you see my last backtest I am using Maxim's version, even though it's less effective in order management with the 1-2 share rebalancing, but has better performance per DD levels.

Elsid,

The equation for CAGR is simple.

CAGR = (A(t)/A(0))^(1/t) – 1

Nobody can get this wrong. Nobody. If some would like to analyze it using other numbers, well, they better put their definition, and equation on the table.

Just in case, they can look up: https://en.wikipedia.org/wiki/Compound_annual_growth_rate

Whatever you trade, there will be commissions. You can set aside slippage only if you use limit orders only. Otherwise, you are bound to have slippage. You are bound to have partial fills, especially if you can have only 2.5% of the available volume on a minute bar. So, these expenses need to be included in any backtest. Otherwise, again, the simulation done will not reflect reality.

And if a trading strategy does not reflex reality, it is not worth so much. Because when you will put that trading strategy live, it will certainly hit you in the face.

I generally agree with you Guy. Commissions should always be included. Setting it to the IB commission structure probably makes most sense:

    set_commission(commission.PerShare(cost=0.005, min_trade_cost=1))  

I also agree regarding slippage. Slippage obviously varies depending on the trade size. Placing 7 figure market orders will often lead to slippage, no matter how liquid the asset. Placing 4 figure market orders on a liquid asset will probably not experience much slippage, if at all.

I think many of these algos are catering for people trading on Robin Hood with small accounts - so they assume no commission and no slippage.

@Guy

Unless you are using wrong inputs, or unless Investopedia is using the wrong formula in their calculator, which they probably haven't since they have a whole section with the same formula, then I have no Idea how you get the CAGR number you do, probably from the number you are taking? In the Daily Positions Gains, you have the starting and Ending Value, that's the values I use and get a different CAGR from you.

Feel free to add commissions, but to add partial fill data is again pretty useless unless you are trading MULTI MILLION DOLLARS, I'm trading this live and have no issues with partial fills on my low amounts of 100-300 shares, because again these instruments trade millions of shares a day.

And nobody is talking about partial fills for the minute, and then it fills next minute, we are talking about partial fills for the whole day that don't fill the whole day, such as couldn't fill 300 TMF shares all day. WHAT??? which again is impossible unless trading 50MM+ if even that, some of these ETFs have over a Billion dollars traded each day.

You can argue about large size orders moving your fill price, that's where there will be slippage, but the current partial fill order canceled for the whole day is utterly meaningless and downright misleading.

@ Elsid what version are you trading live? There are now many versions of this algo. Thanks!

You can mess around with this to simulate somewhat of realistic slippage model, even with this given that the Algo is trading at the most volume intense time periods of 5-15m at opening and 15m at closing, you will probably never have 25% of the bars total volume, again Unless trading million dollar orders, if that. And what will your price impact be for a highly liquid ETF 1-2 cents?
With a 2 cent impact on price, results are so small not even worth talking about, even 5 it still performs well, again assuming you ever hit the 25% minute volume limit.

set_slippage(slippage.VolumeShareSlippage(volume_limit=.25, price_impact=.02))  

@ Tyler

Maxim's version with some changes to take extra leverage, and my ETF changes, the last backtest I posted is what I'm trading live. Clone it and trade it if you like.

Tyler, true. However, that is the trading environment provided.

Take your example of TMF for instance. On the last test, on November 8, 2016, there were 189 TMF trades spattered all over the trading day. 70 trades for over 20 shares at a time, the rest (119 trades) were for 20 shares or less.

Some might not want to consider slippage, or commissions, but they do have an impact. And it is higher than they think. Trades were occurring about every two minutes, at whatever price there was. Sure, you will get a day's average price of some kind at the end of day. It could be close to the first taken trade of the day, but then again, it might not. From what the trade report gives for that day, trades were taken from 23.33 to 24.00 per share. This is more than a penny per share of slippage. This is more than a penny per share of commissions.

Some might not like to look at this, but that is fine with me. I will continue putting commissions and slippage in my tests. It gives a more realistic output.

From the two test made, one could get an estimate on commissions and slippage charges simply by comparing the two tests.

Formula: CAGR = (A(t)/A(0))^(1/t) – 1

Test 1: CAGR = (2381204/100000)^(1/6) – 1 = 0.455 = 45.52%

Test 2: CAGR = (659900/100000)^(1/6) – 1 = 0.2502 = 25.02%

Cost of slippage and commissions: Test 1 – Test 2 = 1,721,304

Those are the numbers, some might like it, others not. But, those are the numbers.

Guy

You seem like a pretty smart guy, get your head out of the numbers for a second, take a breath and really think about this statement from a common sense standpoint.

"Take your example of TMF for instance. On the last test, on November 8, 2016, there were 189 TMF trades spattered all over the trading day. 70 trades for over 20 shares at a time, the rest (119 trades) were for 20 shares or less."

Do you really think it will take all day to fill 189 TMF shares? Which has a volume of 500,000? Clearly this should tell you that there is something wrong with Q backtest especially when filling criteria is applied.

Yesterday in my live account it filled 132 shares of TQQQ instantly, not all day, yes it sold TQQQ which a different version of this algo bought, before i replaced it. All Instant fills.

http://i65.tinypic.com/29n6tz4.png

Please use your common sense

Elsid, I do not design trading strategies for small accounts such as yours.

As part of my tests, if I wanted to see something like you said, I would increase the 2.5% allocation of available volume to something like 75%. It would take at most a few minutes to get a fill.

But, you are not alone trading. And that is the point Q is making. The volume you want might not be available on the very minute you issue your order, there might be slippage. And that is common sense too.

Anybody on Q should be looking at a future, and test outcomes to be as realistic as possible. Even if it is under adverse conditions as the last test provided, the better. That is what you want to know. What are the limits of this trading strategy? Can it do well under adverse conditions. Can it last? Does it scale well or not? Will it flop on year 15?

It is a pity that we can not test for longer than 6 years on this one. I usually take 20-year testing intervals. I want to see if a trading strategy can survive over a 20-year period. It will also reveal strengths and weaknesses. It will give a better image.

For instance, if a trading strategy can not scale up, where do you want to go with it? Play peanuts for peanuts for 20 years? That too can be a matter of choice. But, it is not mine.

I see a diamond in the rough in this trading strategy. I'm still not familiar enough with all the code to isolate it. But, I know it is there just by looking at the net liquidating value chart generated by Q. So, I will be making more tests in order to isolate what makes it tick. Call it forensic strategy investigating.

Ok Guy,

Again do you what you like Quantopian admits themselves that there filling model sucks, and they are working to improve it. You honestly think you can't fill 1000-10000 shares in 390 minutes? Yes I understand you trade large accounts, whats large to you? The largest backtest I've seen you run is $100,000, and in real life you will have no problem getting filled.

The issue is I ran a backtest and got insane results because orders weren't filling by end of day and it gave over optimistic results, not filling works both ways, it can make results more optimistic and seem worst.

https://blog.quantopian.com/accurate-slippage-model-comparing-real-simulated-transaction-costs/

Here is a comparison of default slippage showing better results than, slippage turned off: Both of them have commissions on.

Clone Algorithm
130
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5893f90bd4ee0461a3a3ec9c
There was a runtime error.

Now with slippage off worst results:

Clone Algorithm
130
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5893f8ef16e95b5e1f6adfe0
There was a runtime error.

Also, updating my live IB account to trade the above.

Hi Aliaj,

One can see the leverage is about 1.38 (almost all the time). This means you borrow 38% of your own capital and you have to pay the interest. Right?

If you realize this point and don't worry about that, why not increase the leverage to 1.5 or even more? :-)

Because the rebalance was never changed. So Elsid's latest algo hits a total leverage of just under 2, which is the max from IB.

And yes you would pay interest but it is normally 2% or less - so if you can return ~$2K per year you cover your interest - risky

Yes Thomas you pay interest but it's worth it for example over that 6 year period you get about 500% more, and you pay only 2%/y , even better sign up with Robinhood Gold and get Margin without %. Hey Tyler also where can you see total leverage? Isn't it 1.4 Max?

Lastly, Thomas I didn't increase it more because I didn't want to increase my DD more, but feel free to do it, if you don't mind a higher DD.

@Elsid this is your latest algo with only the PvR routine added. The issue is that your record.leverage only takes the leverage at the day close. The PvR routine takes it by the minute. As you can see max leverage = 1.97 while day close leverage hovers around 1.3-1.4

Clone Algorithm
40
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 58947c3f3e2d8d61e10d1b11
There was a runtime error.

@Tyler

Got it thanks, also what is cash low? The amount of leverage being used?

Welcome. Yes, cash low is the most cash you would have borrowed. But it does not mean you continued to borrow that entire amount. It normalizes back to ~1.37-1.40 after rebalancing is completed.

Got it Thanks. I was hoping Robinhood provided enough margin but they don't they haven't even updated their description of gold, which really makes me lose all credibility trusting these morons with my money.

I think Caleb's algo will work best with Robinhood as long as you stay under 100K and your latest algo would work best in IB since they provide margin (and update it) automatically as your account grows.

Might deploy them that way, but would hate to put all my eggs in 1 basket so to say

Yeah same but I haven't found anything comparable to this performance risk level. The way I'm running it, at least with my version is, if it hits above 20% DD I will stop it, given that the last 6 years the most it's ever been is like 16%.

The following notebook makes a case for this trading strategy.

It is not mine, meaning I am not the author. All I did was make some changes in the parameter values, added a couple of stocks, and that's it.

Hope it is helpful.

Loading notebook preview...
Notebook previews are currently unavailable.

Hi Elsid,

How about if you take out the IJR, SSO and IJH from the context.stocks and just keep the TMF and XIV?

context.stocks = [sid(32270),  #SSO  
                  sid(38294),  #TMF  
                  sid(21519),  #IJR  
                  sid(21507),  #IJH  
                  sid(40516)]  #XIV  ]

The SSO, IJH and IJR are more or less similar, right?

Cheers

I felt like this algo had been overoptimized to the extreme, baking in a lot of hindsight. So I decided to try to get some out-of-sample data to try to test this theory.

I change the leveraged ETFs to trade 3 times the standard ETFs, e.g.
TMF becomes 3 x TLT
TQQQ becomes 3 x QQQ
also, XIV becomes -1 * VXX

This allowed me to run this algo from 2009 to 2011 - i.e. out of sample data.
The result is below. Notice how it is not like the curve of 2011 onwards.

Clone Algorithm
32
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 58961922c418e75e2ba3959b
There was a runtime error.

Here is the exact same algo as above but from 2011 onwards.

Clone Algorithm
32
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 58960aa62504dc47f93d2359
There was a runtime error.