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
::Matrix{Float64}
CCP1Mat::Matrix{Float64}
CCP2Mat::Matrix{Float64}
stateTransitionMat::Matrix{Float64}
equilibriumProfitFirm1::Matrix{Float64}
equilibriumProfitFirm2::Matrix{Float64}
expectedShockUnderBestActionFirm1::Matrix{Float64}
expectedShockUnderBestActionFirm2::Vector{Float64}
exanteV1::Vector{Float64}
exanteV2::Matrix{Float64}
updatedCCP1Numerator::Matrix{Float64}
updatedCCP2Numerator::Matrix{Float64}
CCP1MatUpdated::Matrix{Float64}
CCP2MatUpdated::Array{Float64, 3}
stateTransitionMatFirm2ActionSpecific::Array{Float64, 3}
stateTransitionMatFirm1ActionSpecific::Vector{Float64}
exanteV1Updated::Vector{Float64}
exanteV2Updatedend
mutable struct global_param_struct
::Float64
betaeulergamma::Float64
::Matrix{Int}
entryMat::Vector{Int}
numFirmsVec::Vector{Int}
economyVec::Array{Int, 3}
possibleActionArrayend
for 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";
= [0.7 0.3; 0.4 0.6]
TransitionMat
Random.seed!(123);
= 15; NumSimPeriods
= [
BaselineParameterValues 0.3,
-0.27,
0.45,
-0.15,
-2.10,
0.2,
-0.27,
0.45,
-0.15,
-2.10
];
= reshape(BaselineParameterValues, (5, 2)); BaselineParameterMat
= calculateFirmProfit(
profitFirm1
BaselineParameterMat,
global_param.entryMat,
global_param.numFirmsVec,
global_param.economyVec,
global_param.possibleActionArray,1
);= calculateFirmProfit(
profitFirm2
BaselineParameterMat,
global_param.entryMat,
global_param.numFirmsVec,
global_param.economyVec,
global_param.possibleActionArray,2
);
= createInitialDataStruct(
data_base_struct
profitFirm1,
profitFirm2,
TransitionMat,
global_param );
@time calculateMPE!(
data_base_struct,
TransitionMat,
profitFirm1,
profitFirm2,
global_param
);
= data_base_struct.CCP1Mat;
CCP1Matbase = data_base_struct.CCP2Mat;
CCP2Matbase = data_base_struct.exanteV1;
exanteV1base = data_base_struct.exanteV2; exanteV2base
1.587827 seconds (5.63 M allocations: 364.474 MiB, 6.94% gc time, 99.75% compilation time)
= simulateEntryFirms(
n1, n2
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
];
= reshape(
CounterfactualParameterMat
CounterfactualParameterValues, 5, 2)
(
);
= calculateFirmProfit(
profitFirm1_cf
CounterfactualParameterMat,
global_param.entryMat,
global_param.numFirmsVec,
global_param.economyVec,
global_param.possibleActionArray,1
);= calculateFirmProfit(
profitFirm2_cf
CounterfactualParameterMat,
global_param.entryMat,
global_param.numFirmsVec,
global_param.economyVec,
global_param.possibleActionArray,2
);
= createInitialDataStruct(
data_cf_struct
profitFirm1_cf,
profitFirm2_cf,
TransitionMat,
global_param
);
@time output = calculateMPE!(
data_cf_struct,
TransitionMat,
profitFirm1_cf,
profitFirm2_cf,
global_param
);
= data_cf_struct.CCP1Mat;
CCP1Matcf = data_cf_struct.CCP2Mat;
CCP2Matcf = data_cf_struct.exanteV1;
exanteV1cf = data_cf_struct.exanteV2; exanteV2cf
0.000297 seconds (3.65 k allocations: 392.828 KiB)
= simulateEntryFirms(
n1_cf, n2_cf
TransitionMat,
CCP1Matcf,
CCP2Matcf,
global_param,
NumSimPeriods );
= plot(
plot1 1:NumSimPeriods,
n1,= :dash,
linestyle = "企業1の店舗存在確率",
title = "現状維持"
label
);plot!(
1:NumSimPeriods,
n1_cf,= "新ブランド展開 "
label
);xlabel!("期間")
ylabel!("店舗存在確率")
= plot(
plot2 1:NumSimPeriods,
n2,= :dash,
linestyle = "企業2の店舗存在確率",
title = "現状維持"
label
);plot!(
1:NumSimPeriods,
n2_cf,= "新ブランド展開 "
label
);xlabel!("期間")
ylabel!("店舗存在確率")
plot(plot1, plot2, layout = (1, 2))
= exanteV1cf - exanteV1base;
diff_value_1
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 |