Рекурсивный метод оптимизации графика торговPython

Программы на Python
Anonymous
Рекурсивный метод оптимизации графика торгов

Сообщение Anonymous »

У меня есть задача по оптимизации графика торговли акциями, которую я смог решить с помощью жадного метода, но меня попросили решить ее для достижения глобального оптимума рекурсивно. Хотя я пытался создать функцию рекурсии, ее запуск занял целую вечность, поскольку в качестве тестового примера у меня очень большое N. Есть ли способ решить эту проблему? Любое предложение приветствуется!!

Код: Выделить всё

# Memoization dictionary to store results of subproblems
memo = {}

# Recursive function to maximize trades
def maximize_trades_recursive(t, n, M, alpha, pi, T):
# Base case: At the last period, we must trade all remaining shares
if t == T - 1:
return math.ceil((1 - alpha * M**pi) * n)

# If the result for this state is already computed, return it
if (t, n, M) in memo:
return memo[(t, n, M)]

# Recursive case: Try trading different amounts of shares and maximize the result
max_traded_shares = 0
optimal_n_t = 0

# Iterate over all possible amounts of shares to trade at this period (0 

Подробнее здесь: [url]https://stackoverflow.com/questions/79019902/recursive-method-to-optimize-trading-schedule[/url]

Вернуться в «Python»