我有供应和需求的离散步骤功能。我正在寻找一种算法来找到均衡价格,数据低于R
,但任何语言(或伪代码)都可以接受。
demand = data.frame(volume = c(8,2,3,1,1), price=c(1,2,3,4,5))
supply = data.frame(volume = c(3,2,4,2,3), price=c(5,4,3,2,1))
demand$volume <- cumsum(demand$volume)
supply$volume <- cumsum(supply$volume)
plot(demand, type="s")
lines(supply, type="s", col=3)
答案 0 :(得分:1)
您需要从价格范围的两端获取部分 cumsum
卷。
demand_cum = (15, 7, 5, 2, 1)
supply_cum = ( 3, 5, 9, 11, 14)
这会显示总累积需求&amp;每个价格供应。 现在你能发现均衡吗?
答案 1 :(得分:1)
我正在研究一个类似的问题,并发现了这个很好的描述:https://www.youtube.com/watch?v=FYfbM56L-mE&ab_channel=31761-Renewablesinelectricitymarkets
您可以针对您的问题进行类似的分析。考虑一个 LP 公式。给定双重解,您可以找到市场出清价格如下:
demand = data.frame(Type = "demand",Q = c(8,2,3,1,1), P=c(1,2,3,4,5))
supply = data.frame(Type = "supply",Q = c(3,2,4,2,3), P=c(5,4,3,2,1))
ds <- rbind(supply,demand)
通过代表 LP 的问题,执行以下操作:
ds[ds$Type == "demand","Q"] <- ds[ds$Type == "demand","Q"]
ds[ds$Type == "supply","Q"] <- ds[ds$Type == "supply","Q"]
P_s <- ds[ds$Type == "supply","P"]
P_d <- ds[ds$Type == "demand","P"]
Q_s <- ds[ds$Type == "supply","Q"]
Q_d <- ds[ds$Type == "demand","Q"]
c_vec <- c(P_s,-P_d)
A_mat <- diag(length(c_vec))
b_vec <- c(Q_s,Q_d)
dir_1 <- rep("<=",length(b_vec))
A2_mat <- c(rep(1,length(Q_s)),rep(-1,length(Q_d)))
b2_vec <- 0
A_mat <- rbind(A_mat,A2_mat)
b_vec <- c(b_vec,b2_vec)
dir_1 <- c(dir_1,"=")
library(lpSolve)
sol <- lp ("min", c_vec, A_mat, dir_1, b_vec, compute.sens=TRUE)
price_mc <- sol$duals[nrow(ds) + 1] # extracts the dual, which corresponds to the price
在您的示例中,市场出清价格为 2 美元。