Jump to content


0

Code for Monetary System Models


5 replies to this topic

#1 Steve Netwriter

Steve Netwriter

    Tri-Millennium Guru

  • Super Admins
  • PipPipPipPipPip
  • 5,856 posts
  • Gender:Male
  • Location:Christchurch, New Zealand

Posted 21 November 2008 - 01:51 AM

This thread is intended for posting code for models.

The discussion thread is here:

Monetary System Models, Ours and other people's
http://www.greenenergyinvestors.com/index.php?showtopic=5115

Fiat: What starts becoming worth less eventually becomes worthless.

Notable Threads Notable Posts

#2 Steve Netwriter

Steve Netwriter

    Tri-Millennium Guru

  • Super Admins
  • PipPipPipPipPip
  • 5,856 posts
  • Gender:Male
  • Location:Christchurch, New Zealand

Posted 21 November 2008 - 01:53 AM

Originally from: http://www.greenenergyinvestors.com/index....ost&p=77645
Now from here: http://www.greenenergyinvestors.com/index....ost&p=77830
By: qwertyuiop

Consider the following model - you can run this on any java virtual machine.

import java.net.*;
import java.io.*;
import java.text.*;
import java.math.*;

public class interest_model
{
    // Program Variables
    public static double   bank_capital      = 2000;     // shareholders
    public static double   bank_reserves     = 3000;     // deposits from customers into vault
    public static double   money_supply      = 3000;     // bank liabilities - savers bank balances
    public static double   money_on_loan     = 0;        // bank assets
    public static double   interest_total    = 0;
    public static double   interest_received_period  = 0; // Interest payments made in a period
    public static double   principle_received_period = 0; // Principle payments made in a period

    public static int      current_period    = 1;        // Period Counter

    public static double[] loans1 = new double[2000];    // loan principle amount total
    public static double[] loans2 = new double[2000];    // loan interest portion total
    public static double[] loans3 = new double[2000];    // loan principle amount period
    public static double[] loans4 = new double[2000];    // loan interest amount  period
    public static double[] loans5 = new double[2000];    // loan outstanding
    public static String[] loans6 = new String[2000];    // loan retired?
    public static int[]    loans7 = new int[2000];       // payments left

    // Constants
    public static double   interest_percent  = 0.04;     // 4.5% additional to be paid back
    public static int      loan_period       = 10;       // 10 installments for all loans;
    public static double   reserve_ratio     = 0.05;     // 5%

    // Working Variables
    public static double   amount_to_loan;
    public static double   payment_amount;
    public static double   interest_charged;
    public static int      i;

    public static double   operating_costs;
    public static double   savers_interest;
    public static double   bankers_interest;


    // Start Of Program
    public static void main(String[] args) throws IOException
    {

initialize_array();

        boolean notbored = true;
        while (notbored)
        {

           System.out.println("P | Bank Capital | Bank Reserves | Money Supply | Money On Loan");
           System.out.println("--------------------------------------------------------------------");

           DisplayVariables();
           MakeNewLoans();

           current_period++;

           DisplayVariables();
           MakeLoanPayments();

           // Configurable for different scenarios

           UpdateBankBalanceSheets();

           Open_Market_Operations();

        }

        DisplayVariables();
    }


    public static void MakeNewLoans()
    {
      amount_to_loan   = round((bank_reserves) - (money_supply * reserve_ratio),0);
      interest_charged = round((amount_to_loan * interest_percent),0);

      {
          money_on_loan   = money_on_loan  + amount_to_loan;  // Bank Asset
          money_supply    = money_supply   + amount_to_loan;  // Bank Liabilites

          // Signifies removal of money from source bank into target bank - when loan is spent into economy
          bank_reserves   = bank_reserves  - amount_to_loan;
          bank_reserves   = bank_reserves  + amount_to_loan;

          interest_total  = interest_total + interest_charged;

          i               = getFreeElement();

          loans1[i]       = amount_to_loan;
          loans2[i]       = interest_charged;

          loans3[i]       = amount_to_loan / loan_period;
          loans4[i]       = interest_charged / loan_period;

          loans5[i]       = amount_to_loan + interest_charged;
          loans6[i]       = "N";
          loans7[i]       = loan_period;

          System.out.println("--> MAKING LOAN["+i+"] / Principle total: "+ amount_to_loan + "; Interest To Pay Total:" + interest_charged + "; Payments Total: " + loans7[i]);
      }
    }

    public static void MakeLoanPayments()
    {

      i=0;
      interest_received_period=0;
      principle_received_period=0;
      while (loans6[i] != "X")
      {

          if (loans6[i] == "N")
            {
              payment_amount   = loans3[i] + loans4[i];

              if (loans7[i] > 0)
              {
                    loans5[i]        = loans5[i] - payment_amount; // Reduced amount outstanding
                    loans7[i]--;
              }

              // Retire Loan
              if (loans7[i] == 0 ) { loans6[i]="Y"; System.out.println("--> FINAL PAYMENT COMING["+i+"]"); }

              // Update period totals
              interest_received_period  = interest_received_period  + loans4[i];                // Interest recevied in period
              principle_received_period = principle_received_period + loans3[i];                // Total principle received in period

              // Reduce interest required from economy variable
              interest_total            = interest_total            - loans4[i];                // Interest required from economy reduced

              System.out.println("--> MAKING PAYMENT["+i+"] / Principle Period: "+ loans3[i] + "; Interest Portion Period:" + loans4[i] + "; Payments Left: " + loans7[i]);

           }

           i++;
      }
    }

    public static void UpdateBankBalanceSheets()
    {

        // Money Supply
        money_supply      = money_supply  - (interest_received_period + principle_received_period);

        // Bank Assets
        money_on_loan     = money_on_loan - principle_received_period;

        // Signifies movement of money from source bank into target bank - when loan is repaid
        bank_reserves     = bank_reserves  - principle_received_period;
        bank_reserves     = bank_reserves  + principle_received_period;

        // Signifies removal of Interest paid from source bank - when loan is repaid
        bank_reserves     = bank_reserves     - interest_received_period;
        // Interest paid allocated to savers / target bank
        savers_interest   = round(interest_received_period * 0.90,2);
        bankers_interest  = round(interest_received_period - savers_interest,2);

        System.out.println("--> BANKERS INTEREST PORTION: " + bankers_interest);
        System.out.println("--> SAVERS' INTEREST PORTION: " + savers_interest);
        bank_capital      = bank_capital             + bankers_interest;
        bank_reserves     = bank_reserves            + savers_interest;
        money_supply      = money_supply             + savers_interest;

        // Operating Costs, dividends etc
        operating_costs   = round((bankers_interest * 0.80),2);
        System.out.println("--> OPERATING COSTS SPENT INTO ECONOMY: " + operating_costs);
        money_supply      = money_supply      + operating_costs;     // Bank operating costs fed into economy...
        bank_reserves     = bank_reserves     + operating_costs;     // Customers deposit dividends, rent etc into bank
        bank_capital      = bank_capital      - operating_costs;     // Money spent by bank

    }

    public static void Open_Market_Operations()
    // Open Market Operations by Central Bank
    {
       bank_reserves = bank_reserves + (bank_reserves * 0.001);
    }

    public static void DisplayVariables()
    {

           System.out.print(current_period);
           System.out.print(" | ");
           System.out.print(round(bank_capital,2));
           System.out.print(" | ");
           System.out.print(round(bank_reserves,2));
           System.out.print(" | ");
           System.out.print(round(money_supply,2));
           System.out.print(" | ");
           System.out.print(round(money_on_loan,2));
           System.out.println("");
           //waitSecs(1);

           if (bank_reserves < 0)
           {
   System.out.println("**ERROR: NO DEPOSITORS HAVE ANY MONEY **");
   System.exit(0);
           }
    }


    // *************************
    // *** Program Functions ***
    // *************************
    public static int getFreeElement()
    {
       int x=0;
       while ((loans6[x] == "N")) { x++; }
       return x--;
    }

    public static void waitSecs(long s) {
     try {
       Thread.currentThread().sleep(s * 1000);
       }
     catch (InterruptedException e) {
       e.printStackTrace();
       }
     }

     public static double round(double d, int decimalPlace)
     {
          BigDecimal bd = new BigDecimal(Double.toString(d));
          bd = bd.setScale(decimalPlace,BigDecimal.ROUND_HALF_UP);
          return bd.doubleValue();
     }

     public static void initialize_array()
     {
        for (i = 0; i<2000; i++)
        {
            loans1[i]=0;
            loans2[i]=0;
            loans3[i]=0;
            loans4[i]=0;
            loans5[i]=0;
            loans6[i]="X";
            loans7[i]=0;
        }
     }
}
Fiat: What starts becoming worth less eventually becomes worthless.

Notable Threads Notable Posts

#3 qwertyuiop

qwertyuiop

    Tri-Centurion

  • Members
  • PipPipPip
  • 594 posts

Posted 22 November 2008 - 03:02 PM

Attached code for model:

interest_model1.class [cant upload with this extension - renamed to .txt - needs renaming back once downloaded]
interest_model2.class [cant upload with this extension - renamed to .txt - needs renaming back once downloaded]
interest_model.html

To run either download onto desktop or place on webserver. Click or URL to interest_model.html

Considerations:

1. Model is of the banking system as a whole - not an individual bank.
2. A loan or payment is not a single payment but ALL loans payments made in a period
3. Each loan/payment is given a number [1] to seperate them by period
4. Banks only lend from customer deposits - not from their own capital.
5. The reserve ratio is 5%
6. Interest amount in total on loan is 10% of principle.
7. Interest loan period is 10 period.
8. No defaults.




Attached Files



#4 qwertyuiop

qwertyuiop

    Tri-Centurion

  • Members
  • PipPipPip
  • 594 posts

Posted 22 November 2008 - 03:04 PM

wrong file loaded above.

interest_model2.class (renamed to interest_model2.txt)

Attached Files



#5 qwertyuiop

qwertyuiop

    Tri-Centurion

  • Members
  • PipPipPip
  • 594 posts

Posted 22 November 2008 - 03:06 PM

Source code for above

Attached Files



#6 qwertyuiop

qwertyuiop

    Tri-Centurion

  • Members
  • PipPipPip
  • 594 posts

Posted 22 November 2008 - 09:04 PM

Code can be run from

http://www.geocities.com/qwertgei/interest_model.html

Takes a few minutes for the model to run and the results to appear.

Some modifications made due to rounding problems. Updated code:

Attached Files






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users