Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a Python program that solve each of the following problems by dynamic programming. You expect the price of a commodity to behave as follows
Write a Python program that solve each of the following problems by dynamic programming. You expect the price of a commodity to behave as follows over the next months:
Month
Price $unit
Your inventory capacity is units and you have units in inventory at the start of month In any given month, you can buy up to units or sell up to units. The prices per unit sold or bought are the same within each month. However, in each month that you buy or sell any units, you must pay a flat $ transaction charge. For example, if you were to buy units in month your cash flow for that month would be unitstimes $ per unit $ $ Conversely, if you were to sell units in month your cash flow for that month would be unitstimes $ per unit $ $ The only way to avoid the $ charge for a month is to neither buy nor sell. Your holding cost is $ per unit per month, assessed on the inventory at the end of each month. There is no residual value or cost associated with having any units of the commodity left over after month
You want to identify the trading pattern that maximizes your total profit over the month time span.
To aid your thinking, in this problem:
The time periods are the months
The state is how many units of the commodity you have in stock at the start of the month
The decision in each time period is how many units to buy or sell including for doing neither
The interpretation of the value function is fti is the largest profit you can obtain in months t through if you have i units of the commodity in stock at the start of month t
Hint: you may find it helpful to use the convention that a positive value of the inner loop decision variable d whose optimal choice you will store in xti denotes buying d units, a negative value of d denotes selling d units and a zero value denotes neither buying nor selling. For example,
If you have units in stock at the beginning, you may consider selling up to units, doing nothing, or buying up to so the decision loop variable d should have the range
If you have units in stock, you may consider selling up to units, doing nothing, or buying up to so the decision loop variable d should have the range
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started