This thesis analyzes the commodity market and existing stochastic price models for the valuation of commodity futures contracts in two parts. The first part proposes a machine learning-based model for state prediction of agricultural commodity prices. Motivated by the strong dependence of these prices on external factors, the application of a clustering and classification algorithm allows the inclusion of these factors in the price determining process. Combined with a stochastic price model for agricultural commodity futures, the proposed model allows the generation of state-dependent price scenarios via Monte Carlo simulation. The second part solves an investor's portfolio optimization problem in a market with investment possibilities in the money market account and in commodity futures contracts. The price of the futures contract is derived from a one-factor stochastic price model that considers a stochastic market price of risk. Using stochastic control methods, a stochastic optimal portfolio strategy is derived. Two simulation studies follow - among others the optimal portfolio strategy is compared with deterministic strategies that are more practicable in their application.