Exemple #1
0
    def __init__(self, symbols,
        start_date=dt.datetime(2008,1,1),           
        end_date= dt.datetime(2009,1,1)):

        self.dates_range = pd.date_range(start_date, end_date)
        self.check = 0
        self.cum_reward = 0

        # initialize portfolio's cash
        self.init_cash = 100000
        
        # value of each position (long or short)
        self.buy_volume = 8000
        
        self.cum_operations = 0
        self.cum_cash = self.init_cash
        self.date_start = 1

        #for visualization
        self.data_out = []

        # preprocessing time series
        # stock symbol data
        stock_symbols = symbols[:]

        # price data
        prices_all = util.get_prices(symbols, start_date, end_date)

        self.stock_A = stock_symbols[0]
        self.stock_B = stock_symbols[1]
        

        # first trading day
        self.dateIdx = 0
        self.date = prices_all.index[0]
        self.start_date = start_date
        self.end_date = end_date

        self.prices = prices_all[stock_symbols]
        self.prices_ibovespa = prices_all['ibovespa']

        # keep track of portfolio value as a series.
        #########################
        # the variables 'longA', 'longB' and 'longC' keep track of the number of opened positions on each stock. When a stock is 
        # bought, the variables are increased 1. When a stock is sold, the variables are decreased 1. When the variables' values are
        # zero, no positions are opened.
        #########################
        # variable 'a_vol' keeps track of the number of A shares traded (either bought or sold) in the form of a list. 
        # Whenever a position is opened, it is feeded. Whenever a position is closed, the respective register is deleted. The
        # positions are closed beginning with the last ones.
        #########################
        # variable 'a_price' is a list that keeps track of the price of the stock A when a trade occurs. Likewise, Whenever a 
        # position is opened, it is feeded. Whenever a position is closed, the respective register is deleted.
        #########################
        # The same observations apply to 'b_vol', 'c_vol', 'b_price' and 'c_price'. All those variables are needed for the 
        # computation of returns when the positions are closed.
        self.portfolio = {'cash': self.init_cash, 'a_vol': [], 'a_price': [], 'b_vol': [], 'b_price': [], 'longA': 0, 'longB': 0}
        self.port_val = self.port_value()
        self.port_val_market = self.port_value_for_output()
Exemple #2
0
def main():
    start_date = dt.datetime(2010, 1, 1)
    end_date = dt.datetime(2011, 12, 31)
    symbols = ['JPM']
    start_val = 100000
    benchmark_days = get_prices(symbols, pd.date_range(start_date, end_date))

    ps.usePossibleStrategy(benchmark_days, symbols, start_date, end_date, start_val)
    imps.useImpossibleStrategy(benchmark_days, symbols, start_date, end_date, start_val)
Exemple #3
0
        def show_search(a=""):
            print("done")
            self.steam1['text'] = ""
            self.instant1['text'] = ""
            self.g2a1['text'] = ""
            self.uplay['text'] = ""
            self.steam1['fg'] = "black"
            self.instant1['fg'] = "black"
            self.g2a1['fg'] = "black"
            self.uplay['fg'] = "black"

            self.instnat_label['text'] = "Instant-Gaming.com"
            self.steam_label['text'] = "Steam"
            self.uplay_label['text'] = "Uplay"
            self.g2a_label['text'] = "g2a.com"

            search_saved = self.search.get()


            result = get_prices(search_saved, self.search_for_dlc)
            #self.g2a2['text'] = search_saved

            for i in result:

                if i[2].lower() == "instant-gaming":
                    self.instant1['text'] =  self.instant1['text'] + i[0] + "\n(Price: " + str(i[1]) + ")" + "\n\n"
                elif i[2].lower() == "steam":
                    self.steam1['text'] = self.steam1['text'] + i[0] + "\n(Price: " + str(i[1]) + ")" + "\n\n"
                elif i[2].lower() == "g2a":
                    self.g2a1['text'] = self.g2a1['text'] + i[0] + "\n(Price: " + str(i[1]) + ")" + "\n\n"
                elif i[2].lower() == "uplay":
                    self.uplay['text'] = self.uplay['text'] + i[0] + "\n(Price: " + str(i[1]) + ")" + "\n\n"

            if self.instant1['text'] == "":
                self.instant1['fg'] = "red"
                self.instant1['text'] = " ERROR "
                tk.messagebox.showerror(title="ERROR", message="Couldn't connect to instant-gaming.com\nor couldn't find game")

            if self.steam1['text'] == "":
                self.steam1['fg'] = "red"
                self.steam1['text'] = " ERROR "
                tk.messagebox.showerror(title="ERROR", message="Couldn't connect to steam\nor couldn't find game")


            if self.g2a1['text'] == "":
                self.g2a1['fg'] = "red"
                self.g2a1['text'] = " ERROR "
                tk.messagebox.showerror(title="ERROR", message="Couldn't connect to g2a.com\nor couldn't find game")

            if self.uplay['text'] == "":
                self.uplay['fg'] = "red"
                self.uplay['text'] = " ERROR "

                tk.messagebox.showerror(title="ERROR", message="Couldn't connect to uplay\nor couldn't find game")

            print(result)
def get_indicators(symbols, start_date, end_date):
    dates = pd.date_range(start_date, end_date)
    df_prices = get_prices(symbols, dates)

    # Get the Rolling Mean
    rm = get_rolling_mean(df_prices['JPM'], window=20)

    # Get the Rolling Standard Deviation
    rstd = get_rolling_std(df_prices['JPM'], window=20)

    # Get the Momentum
    mom = get_momentum(df_prices['JPM'])

    # Get the Upper and Lower Bollinger Bands
    df_bollinger_bands = get_bollinger_bands(rm, rstd)

    # Plot Raw Prices and Bollinger Bands
    plt.figure(1)
    plt.suptitle('Bollinger Bands', fontsize=20)
    plt.plot(df_prices.index, df_prices['JPM'], color='r', label='Raw Price')
    plt.plot(df_prices.index,
             df_bollinger_bands['Upper'],
             color='b',
             label='_nolegend_')
    plt.plot(df_prices.index,
             df_bollinger_bands['Lower'],
             color='b',
             label='Bollinger Bands')
    plt.legend(loc='best')
    plt.xticks(rotation=45)

    # Plot Raw Prices and Moving Average
    plt.figure(2)
    plt.suptitle('Moving Average', fontsize=20)
    plt.plot(df_prices.index, df_prices['JPM'], color='r', label='Raw Price')
    plt.plot(df_prices.index, rm, color='b', label='Moving Average')
    plt.legend(loc='best')
    plt.xticks(rotation=90)

    # Plot Raw Price and Momentum

    f, axarr = plt.subplots(2, sharex='all')
    axarr[0].plot(df_prices.index, df_prices['JPM'], color='r')
    axarr[0].set_title('Raw Price')
    axarr[1].set_title('Momentum')
    axarr[1].plot(df_prices.index, mom, color='b')
    plt.suptitle('Raw Price and Momentum', fontsize=20)
    plt.xticks(rotation=90)

    # plt.show(block=False)
    # plt.gcf().clear()

    return
Exemple #5
0
    def __init__(
            self,
            symbols,
            start_date=dt.datetime(2008, 1, 1),
            end_date=dt.datetime(2009, 1, 1),
            test_date=dt.datetime(2008, 8, 1),
    ):

        self.dates_range = pd.date_range(start_date, end_date)
        self.test_date = test_date
        self.check = 0
        self.tickers = symbols
        #self.cum_reward = 0

        self.date_start = 1

        # for visualization
        self.data_out = []
        self.costs = []
        self.cum_return = []

        # preprocessing time series
        # stock symbol data
        stock_symbols = symbols[:]

        # price data
        prices_all = util.get_prices(symbols, start_date, end_date)

        self.stock_A = stock_symbols[0]
        self.stock_B = stock_symbols[1]

        # first trading day start from day 100
        self.dateIdx = 100
        self.date = prices_all.index[0]
        self.start_date = start_date
        self.end_date = end_date

        self.prices = prices_all[stock_symbols]
        #        print (self.prices)
        #self.prices_ibovespa = prices_all['ibovespa']

        self.portfolio = {'longA': 0, 'longB': 0}

        print('========1.init environment===================')
Exemple #6
0
            print('\t{}Price: {:>6} \tWebsite: {:<20}{}'.format(
                bcolors.OKGREEN, e[1], e[2], bcolors.ENDC))
        else:
            print('\t{}Price: {:>6} \tWebsite: {:<20}{}'.format(
                bcolors.WARNING, e[1], e[2], bcolors.ENDC))
        last = e[0].lower()


if __name__ == '__main__':
    from util import get_prices
    import argparse

    parser = argparse.ArgumentParser(
        description=
        'Commandline tool to compare prices between different websites',
        usage='python3 cli.py <game> [options]')
    parser.add_argument('query', type=str, help='Game you\'re searching for')
    parser.add_argument('--dlc',
                        dest='dlc',
                        action='store_true',
                        help='Are you searching a dlc?')
    parser.set_defaults(dlc=False)
    parser.add_argument('--max',
                        type=int,
                        help='Max number of results per website',
                        default=3)

    args = parser.parse_args()

    print_data(get_prices(args.query, args.dlc, args.max))