I'm working on a dynamic programming problem and the problem requires selling a product over T time periods and maximizing the total actual sale amount. The total number of products is N and I plan to sell some products over different periods n0,n1,⋯,nT−1 and ∑ni=N. But the actual sale amount Si and sale price Pi are based on the below formulas. Assume that α=0.001 and π=0.5
- Initialize P=0. Then for i=0,1,…,T−1
- Compute new Pi=⌈0.5∗(Pi+ni)⌉
- At time i we sell Si = ⌈(1−αP^π)*ni⌉ products
For example, assume we already know $n_i$ for all periods, the trading will be below
P = 0
T = 4
N = 10000
alpha = 1e-3
pi = 0.5
S = np.zeros(T,dtype='i')
n = np.array([5000,1000,2000,2000])
print(n)
total = 0
for i in range(T):
P = math.ceil(0.5*(P + n[i]))
S[i] = math.ceil((1 - alpha*P**pi)*n[i])
total += S[i]
print('at time %d, M = %d and we trade %d shares' %(i,M,S[i]))
print('total sold =', total)
My idea is that this problem is dealing with quantity instead of price. Therefore, we should focus on something related to quantity, such as the moving average of the quantity. I'm still considering how to program it. Could someone provide ideas about dynamic programming? Thank you very much. The below is some of my crude codes.
def DPcrude(N,T,alpha,pi,S):
for k in range(1, T):
t = T - k - 1
for n in range(0,N+1):
best = -1
for sell in range(0,n):
newprice =
salenow =
salelater =
candidate = salenow + salelater
if candidate > best:
best = candidate
S[t,a,n] = best
N = 1000
T = 10
pi = .5
alpha = 1e-2