Version 0.1.0 Quantitative Analysis Framework

Overview of Created Modules

yggdrasil.py and strategy_helper.py will be explained in this and the next part while the rest are on GitHub.

Module: yggdrasil.py


import useful_methods
from market_analy import full_stocks
from strategy_analy import StockAnalyzer
from strategy_helper import StrategyHelper


 class Yggdrasil :
      def __init__(self, freq, strategy_, custom, shift_= 0, num_points= 500, stock_list=None):
       self.strat_list=[]
       self.cur_strat=StrategyHelper(freq, strategy_, custom=custom, shift=shift_, num_points=num_points)
       self.stock_universe=StockAnalyzer(stock_list, self.cur_strat )
       self.cur_strat.run_method(stock_list)
       self.analysis=None
       self.title=self.__set_title()

      def __set_title(self):
        title= ('freq: ' + self.cur_strat.freq + '_ ' + 'num of data points: '+ str(self.cur_strat.num_points)+
                 '_custom: '+ str(self.cur_strat.custom) + '_ shift: ' + str(self.cur_strat.shift)
                  '_start_date: '+ str (self.cur_strat.start) + '_end_date: ' + str (self.cur_strat.end)
                 + '_strategy: ' + str(self.cur_strat.strategy) + ' ')
        return title

# Generates the various parameters which can be tested
para_test= []
for shift in range (1):
    for roll in range (10,21, 5):
        for cutoff in range (11,13, 1):
            for stock in full_stocks [0:100]:
                para_test.append([stock , shift , roll , cutoff/ 10])

#Example which run the tests for various combinations of the parameters. Only two full stock iterations are ran below for brevity.
stock_pass_test= []
stock_pass_condition= False
for x in para_test:
    strategy= ['Mean Rev']+ x [2:4]
    ygg= Yggdrasil ('5m' , strategy , True , shift_=x[1], num_points= 250, stock_list= [x[0]])
      # Condition for stock classification to filter the backtests
    results= [ygg.cur_strat.results[x] for x in ['Profit', 'Number of Completed Trades']]
    if results [0] > 0 and results [1] > 30 :
        stock_pass_test.append(ygg.cur_strat.get_params())

# Data from all the tests is stored in a JSON file for easy viewing and extraction 
with open ('example_data.json', 'w' ) as pdf:
    json.dump(stock_pass_test, pdf, indent= 2)