Just a toy example. Suppose we have 5 stocks and we want to find the best portfolio structure (linear weights) maximizing our PnL on history. Weights are used to build portfolio invested in equities.
weights = tf.Variable(np.random.random((5, 1)), dtype=tf.double)
returns = tf.placeholder(dtype=tf.double)
portfolio = tf.matmul(returns, weights)
pnl = portfolio[-1]
optimizer = tf.train.AdamOptimizer().minimize(-1*pnl)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
train_data = {returns: returns_data}
for i in range(100):
sess.run(optimizer, feed_dict=train_data)
I want to find the best decision on history with following constraints:
- each stock individual weight (min: 0.05, max: 0.5)
- weights vector sum = 1 (portfolio is always invested)
How can I implement weights constraints to the optimizer?