def trade_by_strategy(self, omega): logging.info("the step is {}".format(self._steps)) logging.debug("the raw omega is {}".format(omega)) future_price = np.concatenate((np.ones(1), self.__get_matrix_y())) pv_after_commission = calculate_pv_after_commission( omega, self._last_omega, self._commission_rate) portfolio_change = pv_after_commission * np.dot(omega, future_price) self._total_capital *= portfolio_change self._last_omega = pv_after_commission * omega * future_price / portfolio_change logging.debug("the portfolio change this period is : {}".format( portfolio_change)) self.__test_pc_vector.append(portfolio_change)
def trade_by_strategy(self, omega): logging.info("the step is {}".format(self._steps)) logging.debug("the raw omega is {}".format(omega)) future_price = np.concatenate((np.ones(1), self.__get_matrix_y())) pv_after_commission = calculate_pv_after_commission(omega, self._last_omega, self._commission_rate) portfolio_change = pv_after_commission * np.dot(omega, future_price) self._total_capital *= portfolio_change self._last_omega = pv_after_commission * omega * \ future_price /\ portfolio_change logging.debug("the portfolio change this period is : {}".format(portfolio_change)) self.__test_pc_vector.append(portfolio_change)
def trade_by_online_strategy(self, omega): logging.debug("LAST OMEGA IS {}".format(omega)) real_output = self.__get_matrix_last_y() #print("Last Value : {} Shape : {}".format(real_output, real_output.shape)) future_price = np.concatenate((np.ones(1), real_output)) logging.info("FUTURE PRICE : {}".format(future_price)) pv_after_commission = calculate_pv_after_commission( omega, self._last_omega, self._commission_rate) portfolio_change = pv_after_commission * np.dot(omega, future_price) self._total_capital *= portfolio_change self._last_omega = pv_after_commission * omega * \ future_price /\ portfolio_change logging.debug("TOTAL PORTFOLIO CHANGE: {}".format(portfolio_change)) self.__test_pc_vector.append(portfolio_change)
def trade_by_strategy(self, omega): logging.info("the step is {}".format(self._steps)) logging.debug("the raw omega is {}".format(omega)) #vector of ones and the relative future price future_price = np.concatenate((np.ones(1), self.__get_matrix_y())) #returns a numerically calculated commission pv_after_commission = calculate_pv_after_commission( omega, self._last_omega, self._commission_rate) #portfolio change portfolio_change = pv_after_commission * np.dot(omega, future_price) self._total_capital *= portfolio_change #set the new last omega to be equal to the new portfolio after commission and price changes self._last_omega = pv_after_commission * omega * \ future_price /\ portfolio_change logging.debug("the new omega is {}".format(self._last_omega)) logging.debug("the portfolio change this period is : {}".format( portfolio_change)) self.__test_pc_vector.append(portfolio_change) self.__test_updated_omega.append(self._last_omega)
def trade_by_strategy(self, omega): #test # omega[0,] = np.clip(omega[0,],-1,1) omega[0, ] = np.tanh(omega[0, ]) logging.info("the step is {}".format(self._steps)) # test logging.info("omega is {}".format(omega)) # test logging.debug("the raw omega is {}".format(omega)) future_price = np.concatenate((np.ones(1), self.__get_matrix_y())) pv_after_commission = calculate_pv_after_commission( omega, self._last_omega, self._commission_rate) #test portfolio_change = pv_after_commission * np.dot( omega, future_price) + np.multiply( np.abs(np.clip(omega[0, ], -1, 0)), 0.645) self._total_capital *= portfolio_change self._last_omega = pv_after_commission * omega * future_price + np.abs( np.clip(omega[0, ], -1, 0)) * 0.645 / portfolio_change logging.debug("the portfolio change this period is : {}".format( portfolio_change)) self.__test_pc_vector.append(portfolio_change)
def trade_by_strategy(self, omega): # execute trade once, output the change of omega and portfolio logging.info("the step is {}".format(self._steps)) logging.debug("the raw omega is {}".format(omega)) future_price = np.concatenate( (np.ones(1), self.__get_matrix_y() )) # np.ones(1) as BCT, which is a baseline asset # the pv after paying commission fee pv_after_commission = calculate_pv_after_commission( omega, self._last_omega, self._commission_rate) turn_over = np.sum(np.abs(omega - self._last_omega)) self.__turn_over.append(turn_over) portfolio_change = pv_after_commission * np.dot( omega, future_price) # portfolio change ratio self._total_capital *= portfolio_change # * indicates dot product, np.dot indicates x product self._last_omega = pv_after_commission * omega * \ future_price /\ portfolio_change # to regularize the last_omega logging.debug("the portfolio change this period is : {}".format( portfolio_change)) self.__test_pc_vector.append(portfolio_change)