예제 #1
0
def preprocess(universe, from_date, to_date):
    scripts = list_dict_to_list(select_companies(universe))
    # scripts = ['MINDTREE']
    data = {}
    parent_price = adjust_values(parent_company, from_date, to_date)
    data["Parent Price"] = parent_price
    data["Price"] = {}
    data["High Low"] = {}
    data["Sma"] = {}
    data["Bar Width"] = {}
    data["Volume"] = {}
    data["Tmf"] = {}
    viable_scripts = []
    for script in scripts:
        try:
            data["Price"][script] = adjust_values(script, from_date, to_date)
            if len(data["Price"][script]) == 0:
                continue
            # TODO code 1, 2, 3 month 200 day offset to check upward slope
            # TODO volume data
            temp_sma_200 = price_sma(script, from_date, to_date, 200)
            temp_sma_150 = price_sma(script, from_date, to_date, 150)
            temp_sma_50 = price_sma(script, from_date, to_date, 50)
            data["Sma"][script] = pd.concat([
                temp_sma_200["Close"], temp_sma_200["200 MA"],
                temp_sma_150["150 MA"], temp_sma_50["50 MA"]
            ],
                                            axis=1)
            data["High Low"][script] = high_low(script, from_date, to_date)
            temp_bar_width = bar_width(script, from_date, to_date)
            bar_sma_50 = indicator_sma(temp_bar_width, 50)
            bar_sma_21 = indicator_sma(temp_bar_width, 21)
            bar_sma_10 = indicator_sma(temp_bar_width, 10)
            data["Bar Width"][script] = pd.concat([
                temp_bar_width["Indicator"], bar_sma_50["50 MA"],
                bar_sma_21["21 MA"], bar_sma_10["10 MA"]
            ],
                                                  axis=1)
            temp_sma_50 = volume_sma(script, from_date, to_date, days=50)
            temp_sma_10 = volume_sma(script, from_date, to_date, days=10)
            data["Volume"][script] = pd.concat([
                temp_sma_50["Volume"], temp_sma_50["50 MA"],
                temp_sma_10["10 MA"]
            ],
                                               axis=1)
            data["Tmf"][script] = tmf(script, from_date, to_date, days=21)
            viable_scripts.append(script)
            print(len(viable_scripts))
        except:
            input(script)
            raise
    scripts = viable_scripts
    return data, viable_scripts
예제 #2
0
from datetime import datetime
import pandas as pd
import _pickle as pickle
import os
# global

sl_multiplier = 0.85
slippage_multiplier = 0.01

from_date = datetime(2012, 1, 1)
to_date = datetime(2019, 1, 1)

family = 'nse500'
parent_company = 'LUPIN'
parent_price = adjust_values(parent_company, from_date, to_date)
scripts = list_dict_to_list(select_companies(family))

# scripts = ["ACC"]

########################################################################################


# these functions will be unique for strat. Need to work on how to do this
def hit_sl(pos, date):
    global data
    correct_date = get_closest_date(date, data["Price"][pos["Script"]])
    if (float(data["Price"][pos["Script"]].loc[correct_date, "Close"]) <
            pos["SL"]):
        return True
    return False