Apr-08-2020, 11:58 PM
Hello everyone!
Still working on this problem. I manage to get an output: 4523.316192626953
based on some changes i made. Ideally, the function "enter" in my code will take a position when the function "momentum" is 1. That's where i struggle (and possibly in some other areas). These are the changes i made:
Still working on this problem. I manage to get an output: 4523.316192626953
based on some changes i made. Ideally, the function "enter" in my code will take a position when the function "momentum" is 1. That's where i struggle (and possibly in some other areas). These are the changes i made:
n_share = 50# Number of shares bought per batch cash = 10000 portfolio_portion = .5 # Max proportion of portfolio bet on any trade . . . def enter(direction): position = pd.DataFrame(index =data_values.index) position['Price'] = data_values['Adj Close'] for index, row in position['Price'].iteritems(): batches = np.floor(cash * portfolio_portion) // np.ceil(n_share * row) # Maximum number of batches of stocks invested in trade_value = batches * n_share * row # How much money is put on the line with each trade return trade_value if __name__ == "__main__": result = (enter(momentum(data_values, 2)))#direction = momentum(data_values, 5) print(result)