There is the VIX built-in factor from Q and I find it's better to use this native VIX than to get it from CBOE. What I am going to do is, I want to apply the RSI on it. I've tried but it fails. The following are my codes.
Cheers
Thomas
There is the VIX built-in factor from Q and I find it's better to use this native VIX than to get it from CBOE. What I am going to do is, I want to apply the RSI on it. I've tried but it fails. The following are my codes.
Cheers
Thomas
In order to attach my codes, I have to commend out the line where is makes error. The line number 67.
Your format for the RSI factor is not exactly correct. Should be:
vix_rsi = RSI(inputs = [cboe_vix.vix_close], window_length=14, mask = my_mask)
Attached is a backtest. I also replaced the custom factor SecurityInList with the built in StaticAssets filter (a better way to go).
Hi Dan,
Many thanks, your VIX factor is very nice.
Two questions:
1.
I have a feeling that your built-in factor RSI is not the same as that from Wilder's, correct?
Cheers
Thomas
Thomas
The source code for all the Quantopian factors can be found on GitHub (https://github.com/quantopian/zipline/blob/master/zipline/pipeline/factors/technical.py )
Here's the code for RSI
class RSI(CustomFactor, SingleInputMixin):
"""
Relative Strength Index
**Default Inputs**: [USEquityPricing.close]
**Default Window Length**: 15
"""
window_length = 15
inputs = (USEquityPricing.close,)
def compute(self, today, assets, out, closes):
diffs = diff(closes, axis=0)
ups = nanmean(clip(diffs, 0, inf), axis=0)
downs = abs(nanmean(clip(diffs, -inf, 0), axis=0))
return evaluate(
"100 - (100 / (1 + (ups / downs)))",
local_dict={'ups': ups, 'downs': downs},
global_dict={},
out=out,
)
I see you've already hit on one difference between the built-in RSI and other implementations (https://www.quantopian.com/posts/why-the-rsi-values-are-so-different-between-those-from-buil-in-factor-rsi-and-those-talib-dot-rsi). The custom factor alluded to in that post could probably be used in place of the built in RSI. Use 'inputs = [cboe_vix.vix_close]' and see what happens. One issue that could arrise is that the vix data is a single column data set. The custom factor should handle this ok but just something to watch for.
Hi Dan,
From the link you gave me I couldn't find the source code for VIX_. According to your code the VIX_ should be under "uantopian.pipeline.data." But here I couldn't find it too.
Cheers
Thomas,
I just used the standard RSI factor and gave it the vix_close boundcolumn as the input. RSI is the second factor class in the documentation.
Dan
Hi Dan,
Maybe there is a misunderstanding. I am looking for the source code of VIX_close etc, not the RSI. :-)
Thomas
Thomas,
The other factors for 'vix_open', 'vix_close', and 'vix_hist' are really the same custom factors in YOUR original algorithm you posted above.
class VIX_close(CustomFactor):
# Default inputs
inputs = [cboe_vix.vix_close]
window_length = 1
# Compute momentum
def compute(self, today, assets, out, vix):
out[:] = vix[-1]
They all just take the latest days data from the corresponding cboe_vix dataset and broadcast it to the factor's output. All returned securities will have this same output value. However, when I instantiated each factor I set 'mask=my_mask'. 'my_mask' was set previously to be SPY. So, because of this mask, the vix value only shows up in the row with SPY as the index. All other securities will have NaN in the vix value.
Note that I took a guess at what you wanted from the 'vix_hist' factor. I just set it to
class VIX_close_hist(CustomFactor):
# Default inputs
inputs = [cboe_vix.vix_close]
window_length = 5
# Compute momentum
def compute(self, today, assets, out, vix):
# not sure what was intended here
# this will return vix value 5 days ago
# originally was simply out[:] = vix which won't work
out[:] = vix[0]
That will return the FIRST or earliest data for the vix_close (ie vix[0]). Since the window_length is set to 5, this will return the vix data from 5 days ago. You may have intended this to be something different?
So, there really isn't anything to the source code. Set the output in the 'compute' method of the custom factor class to the cboe data you are looking for.
Am I still misunderstanding the question?