using Plots
using JLD2
using Random
using LinearAlgebra
using DataFrames
ENV["GKS_ENCODING"] = "utf8"
gr(fontfamily="IPAMincho")Plots.GRBackend()
using Plots
using JLD2
using Random
using LinearAlgebra
using DataFrames
ENV["GKS_ENCODING"] = "utf8"
gr(fontfamily="IPAMincho")Plots.GRBackend()
mutable struct array_struct
CCP1Mat::Matrix{Float64}
CCP2Mat::Matrix{Float64}
stateTransitionMat::Matrix{Float64}
equilibriumProfitFirm1::Matrix{Float64}
equilibriumProfitFirm2::Matrix{Float64}
expectedShockUnderBestActionFirm1::Matrix{Float64}
expectedShockUnderBestActionFirm2::Matrix{Float64}
exanteV1::Vector{Float64}
exanteV2::Vector{Float64}
updatedCCP1Numerator::Matrix{Float64}
updatedCCP2Numerator::Matrix{Float64}
CCP1MatUpdated::Matrix{Float64}
CCP2MatUpdated::Matrix{Float64}
stateTransitionMatFirm2ActionSpecific::Array{Float64, 3}
stateTransitionMatFirm1ActionSpecific::Array{Float64, 3}
exanteV1Updated::Vector{Float64}
exanteV2Updated::Vector{Float64}
end
mutable struct global_param_struct
beta::Float64
eulergamma::Float64
entryMat::Matrix{Int}
numFirmsVec::Vector{Int}
economyVec::Vector{Int}
possibleActionArray::Array{Int, 3}
endfor file in readdir("functions/dynamic_game/")
include("functions/dynamic_game/" * file)
end@load "tmp/dynamic_game/data_workspace.jld2";
@load "tmp/dynamic_game/estimates_1.jld2";TransitionMat = [0.7 0.3; 0.4 0.6]
Random.seed!(123);
NumSimPeriods = 15;BaselineParameterValues = [
0.3,
-0.27,
0.45,
-0.15,
-2.10,
0.2,
-0.27,
0.45,
-0.15,
-2.10
];
BaselineParameterMat = reshape(BaselineParameterValues, (5, 2));profitFirm1 = calculateFirmProfit(
BaselineParameterMat,
global_param.entryMat,
global_param.numFirmsVec,
global_param.economyVec,
global_param.possibleActionArray,
1
);
profitFirm2 = calculateFirmProfit(
BaselineParameterMat,
global_param.entryMat,
global_param.numFirmsVec,
global_param.economyVec,
global_param.possibleActionArray,
2
);data_base_struct = createInitialDataStruct(
profitFirm1,
profitFirm2,
TransitionMat,
global_param
);@time calculateMPE!(
data_base_struct,
TransitionMat,
profitFirm1,
profitFirm2,
global_param
);
CCP1Matbase = data_base_struct.CCP1Mat;
CCP2Matbase = data_base_struct.CCP2Mat;
exanteV1base = data_base_struct.exanteV1;
exanteV2base = data_base_struct.exanteV2; 1.587827 seconds (5.63 M allocations: 364.474 MiB, 6.94% gc time, 99.75% compilation time)
n1, n2 = simulateEntryFirms(
TransitionMat,
CCP1Matbase,
CCP2Matbase,
global_param,
NumSimPeriods
);CounterfactualParameterValues = [
0.6,
-0.27,
0.45,
-0.15,
-2.10,
0.2,
-0.27,
0.45,
-0.15,
-2.10
];
CounterfactualParameterMat = reshape(
CounterfactualParameterValues,
(5, 2)
);
profitFirm1_cf = calculateFirmProfit(
CounterfactualParameterMat,
global_param.entryMat,
global_param.numFirmsVec,
global_param.economyVec,
global_param.possibleActionArray,
1
);
profitFirm2_cf = calculateFirmProfit(
CounterfactualParameterMat,
global_param.entryMat,
global_param.numFirmsVec,
global_param.economyVec,
global_param.possibleActionArray,
2
);data_cf_struct = createInitialDataStruct(
profitFirm1_cf,
profitFirm2_cf,
TransitionMat,
global_param
);
@time output = calculateMPE!(
data_cf_struct,
TransitionMat,
profitFirm1_cf,
profitFirm2_cf,
global_param
);
CCP1Matcf = data_cf_struct.CCP1Mat;
CCP2Matcf = data_cf_struct.CCP2Mat;
exanteV1cf = data_cf_struct.exanteV1;
exanteV2cf = data_cf_struct.exanteV2; 0.000297 seconds (3.65 k allocations: 392.828 KiB)
n1_cf, n2_cf = simulateEntryFirms(
TransitionMat,
CCP1Matcf,
CCP2Matcf,
global_param,
NumSimPeriods
);plot1 = plot(
1:NumSimPeriods,
n1,
linestyle = :dash,
title = "企業1の店舗存在確率",
label = "現状維持"
);
plot!(
1:NumSimPeriods,
n1_cf,
label = "新ブランド展開 "
);
xlabel!("期間")
ylabel!("店舗存在確率")
plot2 = plot(
1:NumSimPeriods,
n2,
linestyle = :dash,
title = "企業2の店舗存在確率",
label = "現状維持"
);
plot!(
1:NumSimPeriods,
n2_cf,
label = "新ブランド展開 "
);
xlabel!("期間")
ylabel!("店舗存在確率")
plot(plot1, plot2, layout = (1, 2))diff_value_1 = exanteV1cf - exanteV1base;
DataFrame(
exanteV1base = exanteV1base,
exanteV1cf = exanteV1cf,
diff_value_1 = diff_value_1
)| Row | exanteV1base | exanteV1cf | diff_value_1 |
|---|---|---|---|
| Float64 | Float64 | Float64 | |
| 1 | 4.6568 | 5.33943 | 0.682633 |
| 2 | 4.58732 | 5.25026 | 0.662943 |
| 3 | 6.56876 | 7.74226 | 1.17349 |
| 4 | 6.15887 | 7.31875 | 1.15988 |
| 5 | 4.61238 | 5.28217 | 0.669785 |
| 6 | 4.54617 | 5.19667 | 0.650505 |
| 7 | 6.01581 | 7.18105 | 1.16524 |
| 8 | 5.6088 | 6.7599 | 1.1511 |