"to overcome VXX" - I meant the price of VXX during 2009 was in thousands, so you don't want your strategy to buy 5 shares...
0
Michael Handschuh
50.5k
Pro
,
Thanks for sharing nik milev! It's a shame VXX only started in 2009, it'd be interesting to see how it performs through an overall market crash.
0
Could you explain the position sizing? Also, how did it make so much money on Jan1, 2015? My backtest generated 17% return on that day. Thanks.
0
Nothing special in allocation - buying all possible shares every time.
I dont see trade on Jan 1st, I see Jan 2nd with gain 5.4%
Perhaps you made some changes in the algo...
The trades I see are below:
2014-12-31T09:32:00 VXX 29.08 263788 Market
2014-12-31T10:46:00 VXX 29.279 -263788 Market
2015-01-02T09:32:00 VXX 30.49 253225 Market 4 7720830.25
2015-01-02T10:46:00 VXX 32.27 -253225 Market 4 -8171570.75
gain=32.27-30.49=1.78 which is 5.838%
So, unless I am mistaken somewhere, the gain is 5.4% that day
According to BigCharts open=30.47 high=32.82, so this day was volatile, it seems that around 10:36 price was hoovering around the high, and 32.27 seems achievable.
2
sweet algo. I have a few questions though:
1. Why do you add the last trading minute to the rollingwindow? Then you have a duplicate of the last minute in the rolling window, correct? As far as I can tell it doesn't even matter?
2. What's up with the seemingly random days of the n week for checking for long/short position? (M-W-T-F for long and T-F for short) It does do better in the backtest using these days as constraints.
3. Why only sell at 10:45? (IsExit method)
4. it usually gives me the error:
OnData: 'VXX' wasn't found in the TradeBars object, likely because there was no-data at this moment in time and it wasn't possible to fillforward historical data. Please check the data exists before accessing it with data.ContainsKey("VXX") at QuantConnect.Data.Market.DataDictionary`1[QuantConnect.Data.Market.TradeBar].get_Item (System.String key) [0x00000] in :0 at QuantConnect.Algorithm.Examples.VIXIntraDay.OnData (QuantConnect.Data.Market.TradeBars data) [0x00000] in :0 (Open Stacktrace)
when I start the backtest, usually it keeps running, but sometimes it gets stuck. Haven't been able to figure out where/why this is happening.
0
Michael Handschuh
50.5k
Pro
,
The error above is from the code not checking the dictionary to see that VXX data exists. This probably happening at midnight when the daily data gets emitted, but there is no VXX minute data since we're outside of market hours.
0
Let me try to answer the questions.
I would be careful with conclusions since the algo has not ran on bear market (even it has long/shorts trades), so we may have data snooping issue here.
1. My understanding is that the algo itself builds the history, so this should be the only place to add last bar.
2. It seems that Tuesdays are not good for short - no predictability. I ran it by itself and did not like the result. Also for shorts, my general observation is that Thu/Fri markets are not that good and if the set up happened, it is more powerfull and predictable for shorts.
3. The 10:45 exit is based on observation that after 1-2 hours of trading VXX tends to go down (again careful, might be data snooping too :) )
4. This is just an example and there is leftover code - you can play with weekday exit time , entry time and etc to improve it. The error happens in the beginning and i did not bother to fix it since should not affect the result much.
What I particularly like is the CAGR/DD >2, so you can use half of your portfolio and reach 20% CAGR with 10% drawdown (if the algo really works of course, since it was not tested in bear market :) as MichaelH pointed out )
1
I see thanks. So is checking the dict to see if VXX data exists should ideally be done in the algo, or LEAN engine?
0
Try running it starting in 2010, without the days restriction for buy/sell. Sharpe of 2.1
0
Michael Handschuh
50.5k
Pro
,
I'm not sure the engine could perform that check, also, we always want to call the OnData method even if there is no data since it acts as the heartbeat for the algorithm.
0
to avoid the exception, you could do something like this
TradeBar b = null;
data.TryGetValue(Symbol, out b);
and then put b!=null on the main "ifs" so execution passes them
For longs only including Tuesdays did not deliver good results for me, so I think it is better to exclude them
Total Trades 766
Compounding Annual Return 23.481%
Drawdown 13.700%
Sharpe Ratio 1.551
For shorts only removing check for the days and it looked good and it is as below
Total Trades 912
Compounding Annual Return 13.438%
Drawdown 14.600%
Sharpe Ratio 1.121
This brings another point:
It seems to me that would be valuable addition to have some stats for long and shorts separately:
Long win rate, Long loss rate, Long avg bars in trade, Long P/L, max loss (%), max gain (%) - and same for shorts
After the algo finishes, looking at the stats I can see if algos is hanging too long on the losers and sells winers quicker, or that I need to tighten my stop loss since max loss is too big and etc.
0
Here is an example of how TrailingStop might improve the return: the algorithm uses TrailingStop for shorts. Sharpie is higher and CAGR/Drawdown is better than 4:1 !
Also since expectancy is 0.46% you can start trading with 10-20k in your account.
You can play with different entry times, percent below open and etc. and can easily get better results.
When you get rich, don't forget to send a "thank you" letter :))
5
Have you attempted to trade this yet with success??
0
No, not yet - I was attempting other ideas (autotrading only). But in near future I plan to trade it (manually) on paper first. If you play with different parameters you can easily get better numbers. Just make sure you are not "over-fitting the curve".
0
Yeah, it's interesting. I would love to hear your outcomes if/when you start trading it on paper. I am going to mess with it a little, and see how the new vol approaching will affect it perhaps.
0
Just to get a better idea...is this a simple Long/Short strategy utilizing the VIX and VXX, or are you utilizing some exact parameter? Can you explain? ..apologies for all of the questions ha
0
Yes, it is simple long/short and only uses current VXX price compared to prices from 1-2 days ago. The entire logic for entering is in IsEntry() method . The IsExit() determines if we need to close the trade. One important thing to add - the strategy does not account for slippage!
0
@nik - i am still a nube at c++...how can we add a slippage control?
0
You can search the forum by typing slippage" and might be able to fins few more examples. Here is a simple one:
Assuming you want to trade SPY, somewhere in your Inititalization() method you need to have a line like below.
Securities["SPY"].TransactionModel = new ConstantSlippageModel (SlippagePr);
Where SlippagePr is decimal value of the slippage, e.g.: 0.001 (would mean 0.1%)
Here is a sample implementation for ConstantSlippageModel class - got it from Lean source:
public class ConstantSlippageModel : SpreadSlippageModel
{
private readonly decimal _slippagePercent;
///
/// Initializes a new instance of the class
///
///
The slippage percent for each order. Percent is ranged 0 to 1.
public ConstantSlippageModel(decimal slippagePercent)
{
_slippagePercent = slippagePercent;
}
///
/// Slippage Model. Return a decimal cash slippage approximation on the order.
///
public override decimal GetSlippageApproximation(Security asset, Order order)
{
var lastData = asset.GetLastData();
if (lastData == null) return 0;
return lastData.Value*_slippagePercent;
}
}
Good luck
0
Michael Handschuh
50.5k
Pro
,
Here's the
link to the built in lean slippage models as an example.
0
Stephen Oehler
8.1k
Pro
,
Hi nik,
Fantastic algorithm, thanks for sharing it with us :-)
I'm going over the code and wondering what the underlying logic is, though. I see you've employed trailing stops, and are taking long/short positions based on (I think) the spy moving average. However many people employ these features in their algos and don't get results as good as these. Is there any reason this should work for VIX and not, say, for another security? Are the parameters calibrated to VIX in this particular case?
Thanks again for the showcase!
-Stephen
0
Hi Stephen,
Disregards the SPY moving average. It was a left over while I was experimenting. IsEntry() and IsExit() determine the entry and exit. You can tweak and play with difference closes one or two days back for VXX for long/shorts and you may get better/similar results.
This algo is just from my observations - you can try with different ETFs and it may work for few of them, but I don't think you can generalize that it is true for all. We would have had a lot of rich guys by now ... :))
Thanks Nik
0
Stephen Oehler
8.1k
Pro
,
Awesome, thanks nik. Very impressive!
0
Just wanted to add my thanks for sharing this algorithm. I've been running it on a Live IB paper account since Jan 29th and have a 4.5% return. Thought I would share the screenshot.
More importantly I decided to go ahead and take it live on a real money account as of tonight. Here we go!

1
Stephen Oehler
8.1k
Pro
,
You know, I was wondering at that myself: would this hold up during the market turmoil that we're seeing currently? Seems it is.
We may owe you thank you cards after all, Nik.
0
Stephen Oehler
8.1k
Pro
,
Ray, if you don't mind me asking, what is the average number of trades you're seeing? Tempted to throw some money into Tradier, but not sure if I'd be eaten alive by the fees :-P
0
Thank you all for these comments, but don't forget the drawdown - few days are encouraging but not enough.
@Ray, are you running LEAN engine locally on your computer or you are using QC web site to connect to IB paper account?
In my experience, IB sometimes disconnects during the night and I needed to restart the algorithm.
0
Stephen Oehler
8.1k
Pro
,
Nik, thanks for the cautionary statement. This looks like an incredibly robust algorithm, however I've held off putting real money in it due to its recent performance (see last few months in attached backtest). I wonder if the observations you've made about trading on certain days (i.e. selective deactivation of the algorithm certain days of the week) has changed in the past few months? Do you think it requires an occasional re-calibration, especially now that we're no longer in a trending market?
This is not to say that the recent drawdown is out of the norm. It's not even that particularly severe; however given the particularly volatile environment, I wonder if some of the day-driven behavior has changed.
0
Trade log can be found here
https://www.dropbox.com/s/24teq3q9qxyr34j/Last_30_Days.csv?dl=1
Looks to be 6 Orders executed across 19 actual fills
I've using the QC site. I believe the IB disconnect issue was significantly improved in the latest version of LEAN. Disconnects are reported overnight however it reconnects automatically. I made the suggestion to Jared that the reconnects should also be added to the logs and/or an explicit connection status indicator should be made.
0
Stephen, it is difficult to say if optimization is needed. This may easily lead to over-fitting. If you compare the chart Dec 2012 - Jul 2014 it resembles what we have now. You can play with different parameters and I am sure you can find something better.
The algo was not "properly" created - instead of dividing of windows of data and walk through them comparing algo's results, i just used entire data set available. So, may be these are not best parameters and may be they is overfitting - difficult to say. Just use the algo as workable idea and you may share better results if/when you get them.
@Ray - it is no surprise Lean is better and stable now. The QC team put a lot of hours there...
1
Stephen Oehler
8.1k
Pro
,
I see your point. Attempting to optimize the days of trade would likely improve the method's usefulness in the current economic climate, potentially at the expense of others.
You say the strategy is currently based on observations you've made about trade trends over the following:
1.) Times of the day
2.) Days of the week
No doubt, there are definitely patterns that we're managing to exploit, however I think the real strength is your implementation of safe guards, smart direction-finding, etc. If we enabled all times of the day, and all days of the week, I wonder what we'd see. On my phone now, but I'll try this tomorrow :-)
1
Stephen Oehler
8.1k
Pro
,
Ray, thanks for sharing! Looking forward to seeing how you profit from this.
0
As a heads up Tradier identifies VXX as hard to borrow to I had to modify this to take long positions only.
In order to sell any security short, it must be available to borrow. We have an easy to borrow list that you can located by clicking the Trade button and then clicking the link for the Easy to Borrow list. VXX is not currently on the easy to borrow list. If a security is not on the easy to borrow list, you can give us a call and we can contact our clearing firm to find out if they can locate shares to short. Please be aware that if we locate shares that are not on the easy to borrow list, there could be daily fees to hold those shares short in your account.
0
Ray, you may want to try buying XIV (SVXY) instead of shorting VXX. It should give similar results
2
Still having trouble applying slippage...hate to ask..but any help would be appreciated! I tried using the Fixed Slippage model but after applying it, i get a runtime error..
0
Stephen Oehler
8.1k
Pro
,
Hi Daniel,
I had similar issues but Michael H. helped me figure it out. Make sure you have the following:
1.) Put this namespace at the top of the main class:
using QuantConnect.Orders.Slippage;
2.) Ensure the following is set for each security:
Securities["SPY"].SlippageModel = new ConstantSlippageModel(0.001m);
0
Apologies ahead of time as I'm as much of a beginner on this site and coding as possible, but how would I go about changing the code to go long XIV instead of short VXX? Thanks in advance!
0
Hi Bruce,
In the Initialize() method, you need to add data for XIV - e.g.:
AddSecurity(SecurityType.Equity, "XIV", Resolution.Minute);
And, then in OnData() for trading you can do something like this:
if ( IsLong == false)
SetHoldings("XIV", 1);
else
SetHoldings("VXX", 1);
Hope that helps.
Nik
1
AutomatedMachine
1.3k
Pro
,
Good stuff! Has anyone had any live success with this?
0
Edited by AutomatedMachine
Trying to break down the strategy, took the last version wih Trailing Stop, could not find any reference to RollingWin class, so removed it, now strategy works exactly the same way as before, but giving me an error about some uninitialized object.
Backtest Handled Error: OnData: Object reference not set to an instance of an object
at QuantConnect.Algorithm.Examples.VIXIntraDay.IsEntry (QuantConnect.Data.Market.TradeBar b, System.Decimal& entryPrice, System.Boolean& IsLong) [0x00138] in <b78b78d3d8794ad0ba18dea16b27e565>:0
at QuantConnect.Algorithm.Examples.VIXIntraDay.OnData (QuantConnect.Data.Market.TradeBars data) [0x000e5] in <b78b78d3d8794ad0ba18dea16b27e565>:0
Which makes me think that some condition in this algo is redundant. I removed the whole class and it still works as it did before...
0
There is leftover code in the algo from different experiments I did.
The important is what is checked in "If statements" in IsEntry and IsExit. You can try to simplify the code by removing unimportant code (as long as result is the same).
0
Hi Nik,
I am new to quant, may I ask you why select VXX for intraday trading?
Which kind of asset is most appropriate for intrady trading ?
Thanks very much :)
Kevin
0
Hi,
many thanks for sharing.
For a newbi like me extremely interesting.
Could i observe the ongoing performace of your trading system on my own on the platform?
Could i exchange the the chosen intreument VIX against other instruments (eg sp500, daxx30 or eurusd forex pair?
I appreciate your support.
Kind regards,
Frank
0
ForeverYoungNow
135
Pro
,
0
Loading...