def pf(self, dataframe, skipdays):
        dataframe = ff.filtered_frame(dataframe,
                                      skipdays)  # Get df wihout nan, outliers

        dpro_obj = rn.ml_dpmodels(
            self.predict_days, self.symbol,
            self.flag)  # Create object for preprocess Data
        build_pm = gm.build_predictmodel(
        )  # Create object forbuildpredictmodel
        predict_visulaise = pv.pv_visualise(
            self.predict_days, self.symbol, self.flag
        )  #Create Object for prediction , forcasting and Visualisation

        #Preprocess Data and Get model
        X_train, X_test, y_train, y_test, forcast_ip_scaled, header = dpro_obj.data_preprocessing(
            dataframe, self.def_fea)

        #Build Models
        regressor, X_train, X_test, y_train, y_test, forcast_ip_scaled, header,self.report_dict= \
            build_pm.build_predictmodel(X_train, X_test, y_train, y_test, forcast_ip_scaled, header)

        # Predict Forcast and Visualise Models

        sc, sc_y, y_test_df = dpro_obj.sc, dpro_obj.sc_target, dpro_obj.target_testDF
        predict_visulaise.predict_forcast(dataframe, sc, sc_y, y_test_df,
                                          regressor, X_train, X_test, y_train,
                                          y_test, forcast_ip_scaled, header,
                                          self.report_dict)
示例#2
0
def get_year_data(year, Flag=False, Start=date(2018, 1, 1)):
    """
    :param year: year of Data
    :param Flag: if True then append data and skip downloading complete Data
    :param start: if Flag is true, then start date of data
    :return: None. It directly writes data to csv
    """
    now = datetime.now()
    if Flag:
        m = range(Start[2], now.month + 1)
        start = date(Start[0], Start[2], Start[1])
    else:
        m = range(1, 13)
    for i in m:
        if Flag == False:
            start = date(year, i, 1)
        if year < now.year:
            end = date(year, i, monthrange(year, i)[1])
        elif (year == now.year and i <= now.month):
            end = date(year, i, monthrange(year, i)[1])
        if start == end:
            start += timedelta(days=1)
            continue
        tradingDay = get_tradingDay(start, end)
        print(tradingDay)
        fname = str("prices_") + str(year) + "_" + str(i) + ".csv"
        fname = os.path.join(p.optiondata, fname)
        price = []
        if Flag and os.path.isfile(fname):
            old_prices = pd.read_csv(fname)
            old_prices = filterframe.filtered_frame(old_prices, Options=True)
            price.append(old_prices)

        def concat_Data(x):
            print(x)
            price.append(
                filterframe.filtered_frame(get_price_list(dt=x), Options=True))

        try:
            tradingDay.apply(concat_Data)
        except Exception as e:
            print(e)
        finally:
            prices = pd.concat(price)
            prices = filterframe.filtered_frame(prices, Options=True)
            prices.to_csv(fname)
示例#3
0
 def concat_Data_csv(x):
     print(x)
     price_df = get_price_list(dt=x)
     if not price_df.empty:
         price_df = filterframe.filtered_frame(price_df, Options=True)
         price_df.to_csv(fname,mode='a')
         #save_data(dbq, con, price_df, tb_DerivativeData, fname, fname_day)
        # implobj = ImpliedVolatility(Dframe=price_df, DfFlag=True, dbq=dbq, conn=con)
         #implobj.getStrike()
     else:
         print("no data to recieve for ",x)
示例#4
0
    def ma_cross(self, dataframe, skipdays):
        dataframe = ff.filtered_frame(dataframe,skipdays)  # Get df wihout nan, outliers
        '''dpro_obj=rn.ml_dpmodels(self.predict_days,self.symbol,self.flag) # Create object for preprocess Data

        build_pm=gm.build_predictmodel()                                        # Create object forbuildpredictmodel
        predict_visulaise = pv.pv_visualise(self.predict_days,self.symbol,self.flag) #Create Object for prediction , forcasting and Visualisation


        #Preprocess Data and Get model
        X_train, X_test, y_train, y_test, forcast_ip_scaled, header = dpro_obj.data_preprocessing(dataframe,self.def_fea)
        '''
        '''
        #Build Models
        regressor, X_train, X_test, y_train, y_test, forcast_ip_scaled, header,self.report_dict= \
            build_pm.build_predictmodel(X_train, X_test, y_train, y_test, forcast_ip_scaled, header)

        # Predict Forcast and Visualise Models

        sc,sc_y,y_test_df=dpro_obj.sc,dpro_obj.sc_target,dpro_obj.target_testDF
        predict_visulaise.predict_forcast(dataframe,sc,sc_y,y_test_df,regressor,X_train, X_test, y_train, y_test, forcast_ip_scaled, header,self.report_dict)
        '''
        #("-".join(str(i) for i in DF.columns.tolist()))
        header=dataframe.columns.tolist()#[-1::-1]
        malist = []
        for i in range(len(header)):
            h = header[i]
            if h.startswith('MA'):
                malist.append(int(h[2:]))
        malist = sorted(malist,reverse=True)
        bars = dataframe
        mac = btmc.MovingAverageCrossStrategy(self.symbol, bars, short_window=malist[1], long_window=malist[0])
        signals = mac.generate_signals()
        #signals.to_csv('signals.csv')
        portfolio = btmc.MarketOnClosePortfolio(self.symbol, bars, signals, initial_capital=100000.0) #10 lacs
        returns = portfolio.backtest_portfolio()
        signallist,signaldict=portfolio.signallist,portfolio.signaldict

        reportname = str(date.today())+'_'+'ma_cross'
        repostring = (self.symbol,int(returns['total'][-1]),malist[0],malist[1],len(signallist))
        #        print(repostring)

        #Reporting
        report=mcrv.mac_reporting(repostring,reportname)

        # Plot two charts to assess trades and equity curve
        imgname = reportname+'_'+str(repostring)[1:-1].replace(',','_').replace("\'",'')
        #mcrv.mac_visualise(bars,signals,returns,imgname)

        # print the best result
        return report
示例#5
0
 def concat_Data(x):
     print(x)
     price.append(
         filterframe.filtered_frame(get_price_list(dt=x), Options=True))
import talib
import pandas as pd
from utility import Load_Csv as lcsv
from utility import filterframe
from seaborn import palplot

ld = lcsv.Load_csv()
df = ld.LoadData(filename='BANKNIFTY.csv')

df_new = filterframe.filtered_frame(df, 0)

o = df_new["Open"].values
h = df_new["High"].values
l = df_new["Low"].values
c = df_new["Close"].values

df_candle = pd.DataFrame(index=df_new.index)
df_candle["Invertedhammer"] = talib.CDLINVERTEDHAMMER(o, h, l, c)
df_candle["Kicking"] = talib.CDLKICKING(o, h, l, c)
df_candle["Hammer"] = talib.CDLHAMMER(o, h, l, c)
df_candle["shootingstar"] = talib.CDLSHOOTINGSTAR(o, h, l, c)
print(pd.DataFrame(talib.CDLINVERTEDHAMMER(o, h, l, c)))

df_candle.to_csv("candleresult.csv")