/vix_strategy_backtest

Vix index is implemented in S&P500 historical data.

Primary LanguagePython

vix_strategy_backtest

Logo

Fearful when others are greedy, and greedy when others are fearful.

Contents

What is Vix strategy?

The VIX index, also known as the “fear index” is reported by the Chicago Board Options Exchange and provides investors and traders valuable insight into current greed and fear levels in the market. The Cboe Volatility Index (VIX) is a real-time index that represents the market's expectations for the relative strength of near-term price changes of the S&P 500 index (SPX).

The strategy I have used

First of all I have plotted both the graph of s&p500 and vix index. According the the plotted graph, I have decided that whenever vix index hit 35 or more i will buy the shares as fear is in market. Then I have tested by selling the shares whenever vix index hit 10. But result was not so good. Then I have created a strategy where I will add 5000$ of cash to the broker at every 20 days or one market month. And buy stocks only when vix index hit 35. This gave a preety nice result.

Libraries

  • backtrader - It is an open-source framework that allows for strategy testing on historical data.
  • pandas - the most powerful and flexible open source data analysis / manipulation tool.
  • os - The OS module in Python provides functions for interacting with the operating system.
  • DateTime - This module supplies classes for manipulating dates and times.

Description of each file

  1. main.py - This is the main method of the project where strategy is being executed with the help of backtrader's cerebro method.
  2. VIXStrategy.py - Here I have created the strategy to implement the VIX index in S&P500.

Datasets

I have downloaded the S&P500 and VIX datasets and combine them to use my strategy as SPY_VIX.csv. Other stocks historical data also can be downloaded from yahoo finance.

How to use?

Finally one can run the project by typing as bellow:

$ python main.py