def IPO(self, tickerNumber, tickerID, initialPrice, outstandingShares,
            initial_div, mu, sigma):

        newAsset = security(tickerNumber, tickerID,
                            (initialPrice * outstandingShares),
                            outstandingShares, initialPrice, initial_div, mu,
                            sigma, self.dzMatrix, self.autoCorr,
                            self.crossSecCorr, self.clock)

        #We add the newstock to the stockInventory dataframe and update other dataframes accordingly
        #We set all dataframe entries prior to the IPO to zero to avoid missing entry errors

        self.stockInventory[tickerID] = [outstandingShares]
        self.stockPrice[tickerID] = [initialPrice]
        self.marketCapital[tickerID] = [outstandingShares * initialPrice]
        self.stockBid[tickerID] = [
            self.setBid(
                df.getColumn(tickerID, self.stockPrice, lastValueOnly=True))
        ]
        self.stockAsk[tickerID] = [
            self.setAsk(
                df.getColumn(tickerID, self.stockPrice, lastValueOnly=True))
        ]
        self.stockSpread[tickerID] = [
            self.stockAsk[tickerID] - self.stockBid[tickerID]
        ]

        #At IPO we assume the marketMaker/Underwriter spends money through purchasing all shares issued by the underlying company
        #We update the marketMaker's wealth at that date accordingly
        wealthUpdate = -(outstandingShares * initialPrice)
        self.balanceSheet = [wealthUpdate]

        self.assets.append(newAsset)
        return newAsset
예제 #2
0
    def demandMethod(self, argument, signal_i, wealth, cashFlow, t, tau):
        demand = []
        if (argument <= 1):
            #Maarten's Algorithm
            demand = [self.leverage * wealth * (np.tanh(signal_i) + 0.5)]

        elif (argument == 2):
            for x, tickerID in enumerate(self.numberofshares.columns):
                if (x < 1):
                    d1 = self.leverage * 0.6 * wealth * (1 / df.getColumn(
                        tickerID, self.stockPrice, False).values[tau]) * (
                            1 / (1 + np.exp(-(signal_i[0] - signal_i[1])))) + (
                                self.leverage * 0.6 * cashFlow *
                                (1 / df.getColumn(tickerID, self.stockPrice,
                                                  False).values[t]) *
                                (1 /
                                 (1 + np.exp(-(signal_i[0] - signal_i[1])))))

                    d2 = self.leverage * 0.6 * wealth * (1 / df.getColumn(
                        tickerID, self.stockPrice, False).values[tau]) * (
                            1 -
                            (1 /
                             (1 + np.exp(-(signal_i[0] - signal_i[1]))))) + (
                                 self.leverage * 0.6 * cashFlow *
                                 (1 / df.getColumn(tickerID, self.stockPrice,
                                                   False).values[t]) *
                                 (1 /
                                  (1 + np.exp(-(signal_i[0] - signal_i[1])))))

                    demand.append(d1)
                    demand.append(d2)

        else:
            print('Code not yet implemented')
            # #n stock world, investor picking one stock with highest signal;
            #demand_i = []
            # for x,tickerID in enumerate(self.numberofshares.columns):
            #     if (t==tau):
            #         #given we only invest in the stock that shows the maximum signal
            #         if np.abs(signalVT_i[x]) == max(
            #             np.abs(signalVT_i)):
            #             d  =  np.sign(
            #                 signalVT_i[x]) * self.leverage * W_t * (
            #                     np.tanh(signalVT_i[x]+np.log(2)))/self.stockPrice[tickerID].values[t]

            #         else:
            #             d = 0
            #     else:
            #         if np.abs(
            #             signalVT_i[x]) == max(np.abs(signalVT_i)):
            #             d  =  np.sign(
            #                 signalVT_i[x]) * self.leverage * self.cashFlow[-1]  * (
            #                     np.tanh(signalVT_i[x]+np.log(2)))/self.stockPrice[tickerID].values[t]
            #         else:
            #             d = 0

            #     demand_i.append(d)

        return demand
예제 #3
0
    def passiveTrader(self):

        t = int(self.clock.time() * 1 / self.clock.dt)
        tau = np.int(self.rebalancingPeriod *
                     np.floor(t / self.rebalancingPeriod))

        #Where W_i_t is the wealth invested in asset i at time t
        #W_t is the total wealth at time t comprising of the sum of wealth invested in all individual assets plus
        # wealth in bonds plus interest on bonds and new wealth introduced at time t

        W_i_t = [
            self.numberofshares[tickerID].values[-1] *
            self.stockPrice[tickerID].values[-1]
            for tickerID in self.stockPrice.columns
        ]
        div_i_t = [
            self.numberofshares[tickerID].values[-1] *
            self.marketMaker.assets[x].computeDividend()
            for x, tickerID in enumerate(self.stockPrice.columns)
        ]

        div_t = np.sum(div_i_t)
        W_t = np.sum(W_i_t) + self.cashAccount[-1] * (
            1 + self.marketMaker.riskFreeRate) + (self.cashFlow[-1]) + (div_t)

        cashFlow_t = np.float(np.random.normal(0, 200))
        self.cashFlow.append(cashFlow_t)

        #Using the value, we then calculate the trading signal for each stock in the dataframe
        marketCapital_i = [
            df.getColumn(tickerID, self.stockPrice, False).values[tau] *
            df.getColumn(tickerID, self.marketMaker.stockInventory,
                         False).values[tau]
            for tickerID in self.numberofshares.columns
        ]

        signal_i = [
            tickerID / np.sum(marketCapital_i) for tickerID in marketCapital_i
        ]

        #n stock world, investor picking one stock with highest signal;
        demand_i = self.computeDemand(signal_i, W_t, cashFlow_t, t, tau)
        self.updateRecords(demand_i, W_t)

        return np.array(demand_i)
    def newIssue(self, tickerID, numberofshares):
        newShares = []
        for ticker in self.stockInventory.columns:
            if (ticker == tickerID):
                a = df.getColumn(columnName=ticker,
                                 dataFrame=self.stockInventory,
                                 lastValueOnly=True) + numberofshares
            else:
                a = 0
            newShares.append(a)

        return np.array(newShares)
예제 #5
0
    def noiseTrader(self):

        t = int(self.clock.time() * 1 / self.clock.dt)

        tau = np.int(self.rebalancingPeriod *
                     np.floor(t / self.rebalancingPeriod))

        #W_i_t is the wealth invested in asset i at time t
        W_i_t = [
            self.numberofshares[tickerID].values[-1] *
            self.stockPrice[tickerID].values[-1]
            for tickerID in self.stockPrice.columns
        ]

        #W_t is the total wealth at time t comprising of the sum of wealth invested in all
        # individual assets plus
        # wealth in bonds plus interest on bonds and new wealth introduced at time t

        W_i_t = [
            self.numberofshares[tickerID].values[-1] *
            self.stockPrice[tickerID].values[-1]
            for tickerID in self.stockPrice.columns
        ]
        div_i_t = [
            self.numberofshares[tickerID].values[-1] *
            self.marketMaker.assets[x].computeDividend()
            for x, tickerID in enumerate(self.stockPrice.columns)
        ]

        div_t = np.sum(div_i_t)
        W_t = np.sum(W_i_t) + self.cashAccount[-1] * (
            1 + self.marketMaker.riskFreeRate) + (self.cashFlow[-1]) + (div_t)

        cashFlow_t = np.float(np.random.normal(0, 200))
        self.cashFlow.append(cashFlow_t)

        #We calculate value of each stock using the trader's method of valuing the stocks and update the  stockValue dataframe
        value = [
            5 * df.getColumn(tickerID, self.stockValue, lastValueOnly=True)
            for tickerID in self.stockValue.columns
        ]
        df.appendNextRow(self.stockValue, value)

        dt = self.clock.dt
        dW = np.random.normal(0, self.rebalancingPeriod)
        rho = 0.104943177
        mu = 1
        sd = 0.12

        Xt = rho * (mu - self.X[-1]) * dt + sd * dW
        self.X.append(Xt)

        #Using the value, we then calculate the trading signal for each stock in the dataframe
        signal_i = [
            np.log2(
                np.abs(self.X[-1]) * self.stockValue[tickerID].values[tau]) -
            np.log2(self.stockPrice[tickerID].values[tau])
            for tickerID in self.stockValue.columns
        ]  #correct this line

        demand_i = self.computeDemand(signal_i, W_t, cashFlow_t, t, tau)
        self.updateRecords(demand_i, W_t)

        return np.array(demand_i)