Eccoti il codice della funzioni che dovrebbero produrre i due array:
void beta_learning_IB(){
if(t<theta){
for(j=0;j<Bk;j++){
betaI[j]=(ran2(&idum)*barrier);
betamatrix[j][t]=betaI[j];
borr_ib[j][t]=vicino[j];
supportmatrix[j][t]=profitB[j];
fprintf(out42,"%d %d %d %d %lf %d %lf\n", n_sim, t, j, betaI[j], profitB[j], vicino[j], fit[j]);
fflush(out42);
}
}
else if(t>=theta){
for(j=0;j<Bk;j++){
borr_ib[j][t]=vicino[j];
supportmatrix[j][t]=profitB[j];
if(borr_ib[j][t-2]==borr_ib[j][t-1]){
if(supportmatrix[j][t-1]>=supportmatrix[j][t-2]){
betaI[j]= 20 /*betamatrix[j][t-1]+5*/;
betamatrix[j][t]=betaI[j];
}
else{
betaI[j]= 20 /*betamatrix[j][t-1]-5*/;
betamatrix[j][t]=betaI[j];
}
}
else if(borr_ib[j][t-2]!=borr_ib[j][t-1]){
if(supportmatrix[j][t-1]>=supportmatrix[j][t-2]){
betaI[j]= 20 /*betamatrix[j][t-1]-5*/;
betamatrix[j][t]=betaI[j];
}
else{
betaI[j]= 20 /*betamatrix[j][t-1]+5*/;
betamatrix[j][t]=betaI[j];
}
}
if(betaI[j]<0){
betaI[j]=0;
betamatrix[j][t]=betaI[j];
}
if(betaI[j]>barrier){
betaI[j]=barrier;
betamatrix[j][t]=betaI[j];
}
fprintf(out42,"%d %d %d %d %lf %d %lf\n", n_sim, t, j, betaI[j], profitB[j], vicino[j], fit[j]);
fflush(out42);
}
}
}
///---------------------------------///
void beta_learning_Cre(){
if(t<theta){
for(i=0;i<N;i++){
betaC[i]=(ran2(&idum)*barrier);
betamatrix_cre[i][t]=betaC[i];
borr_cre[i][t]=amico[i];
supportmatrix_cre[i][t]=profitF_1[i];
fprintf(out43,"%d %d %d %d %lf %d\n", n_sim, t, i, betaC[i], profitF_1[i], amico[i]);
fflush(out43);
}
}
else if(t>=theta){
for(i=0;i<N;i++){
borr_cre[i][t]=amico[i];
supportmatrix_cre[i][t]=profitF_1[i];
if(borr_cre[i][t-2]==borr_cre[i][t-1]){
if(supportmatrix_cre[i][t-1]>=supportmatrix_cre[i][t-2]){
betaC[i]= 20 /*betamatrix_cre[i][t-1]+5*/;
betamatrix_cre[i][t]=betaC[i];
}
else{
betaC[i]= 20 /*betamatrix_cre[i][t-1]-1*/;
betamatrix_cre[i][t]=betaC[i];
}
}
else if(borr_cre[i][t-2]!=borr_cre[i][t-1]){
if(supportmatrix_cre[i][t-1]>=supportmatrix_cre[i][t-2]){
betaC[i]= 20 /*betamatrix_cre[j][t-1]-1*/;
betamatrix_cre[i][t]=betaC[i];
}
else{
betaC[i]= 20 /*betamatrix_cre[j][t-1]+5*/;
betamatrix_cre[i][t]=betaC[i];
}
}
if(betaC[i]<0){
betaC[i]=0;
betamatrix_cre[i][t]=betaC[i];
}
if(betaC[i]>barrier){
betaC[i]=barrier;
betamatrix_cre[i][t]=betaC[i];
}
fprintf(out43,"%d %d %d %d %lf %d\n", n_sim, t, i, betaC[i], profitF_1[i], amico[i]);
fflush(out43);
}
}
}
Gli array che mi interessano sono BetaC[N] e BetaI[Bk]. I due fprintf mostrano dei beta giusti.
Questa è la funzione in cui è richiamata BetaI[Bk], ma che nel fprintf di out44 mostra dei betaI[j] che sono tutti 0.
void Trade(){
int aa = 0;
bb = 0;
int nn = 0;
int kai = 0;
int zed = 0;
nano = 0;
int neno = 0;
int nino = 0;
int nuddu = 0;
int antenore = 0;
int buddha = 0;
int notin = 0;
int alreadyin = 0;
int nothanx = 0;
int maledizione = 0;
int checazzosuccede = 0;
int k = 0; int switching = 0; int jj = 0;
int intbkOn[Bk]/*, betaI[Bk]*/;
float ref = 0.;
float fact = 0.;
float prob = 0.;
float fitness = 0.;
for(i = 0; i < Bk; i++){
for(jj = 0; jj < Bk; jj++){
marketBank[i][jj] = 0;
marketBank[jj][i] = 0;
}
}
asked = 0.;
granted = 0.;
granted_interbank = 0.;
interest = 0.;
interestB = 0.;
for(i = 0; i < N; i++){
debito[i] = 0.;
kapital[i] = 0.;
for(j = 0; j < Bk; j++){
id_borr[j] = -1;
intbkOn[j] = 0;
credit[i][j] = 0.;
askI[i][j] = 0.;
if(total_debt[i][j] <= 0.)
total_debt[i][j] = 0.;
}
}
for(i = 0; i < Bk; i++){
for(j = 0; j < Bk; j++){
bankInteractiond[i][j] = 0.;
bankInteractionid[i][j] = 0.;
bankInteractionl[j][i] = 0.;
bankInteractionil[j][i] = 0.;
}
}
int flag2 =0;
double norm[Bk];
for(j = 0; j < Bk; j++){
size[j] = 0.;
norm[j] = 0.;
betaI[j] = 0;
norm[j] = (double)pot_incoming[j] / N;
size[j] = equityB[j];
}
printf("%d %d\n", t,j/*,betaI[j]*/);
for(j=0;j<Bk;j++){
fprintf(out44,"%d %d %d %d\n", n_sim, t, j, betaI[j]);
fflush(out44);
}
for(i = 0; i < N; i++){
notin = 1;
alreadyin = 0;
nothanx = 0;
buddha = 0;
asked += d_loan[i];
for(j = 0; j < Bk; j++){
///NON MARKETABLE ORDERS
if(d_loan[i] <= 0. && buddha != 1){
nothanx = 1;
d_loan[i] = 0.;
aa++;
}//dloan iniziale <= 0
///MARKETABLE ORDERS
else if(d_loan[i] > 0. && dMarketMatrix[i][j] == 1 && total_debt[i][j] <= 0. && liquidity[j]>0. /*&& leverageB[j] < leverage_target*/){
credit[i][j] = 0.;
notin = 0;
alreadyin = 1;
buddha = 0;
bb++;
// printf("INIZIO %d %d %d %lf %lf %lf\n",t,j,i,liquidity[j],equityB[j],d_loan[i]);
if(d_loan[i] < liquidity[j]*0.2/*(1-norm[j])*/){
liquidity[j] -= d_loan[i];
loans[j] += d_loan[i];
credit[i][j] = d_loan[i];
d_loan[i] = 0.;
buddha = 1;
nn++;
}//dloan <= liquidity
else{
d_loan[i] -= (liquidity[j]*0.2/*(1-norm[j])*/);// *prud
loans[j] += (liquidity[j]*0.2/*(1-norm[j])*/);// *prud
credit[i][j] = (liquidity[j]*0.2/*(1-norm[j])*/);// *prud
liquidity[j] -= (liquidity[j]*0.2/*(1-norm[j])*/)/*= 0.*/;// *prud
int candoit = 0;
int entra = 0;
int porco = 0;
int mannaggia = 0;
askI[i][j] = d_loan[i];
kai++;
///CREO LA RETE INTERBANCARIA SOLO PER BORROWER ATTIVI///
while(intbkOn[j] == 0){
intbkOn[j] = 1;
id_borr[j] = j;
jj = j;
k = 0;
while(jj == j)
jj = ran2(&idum)*Bk;
k = vicino[j];
prob = ran2(&idum);
fitness = (fit[jj] - fit[k]);
ref = /*T_inv*/betaI[j]*fitness;
fact = (float)1./(1+exp(-ref));
if(prob < fact && j != jj){
switching ++;
marketBank[j][k] = 0;
marketBank[j][jj] = 1;
vicino[j] = jj;
}
else{
marketBank[j][jj] = 0;
marketBank[j][k] = 1;
vicino[j] = k;
}
}