Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 0 additions & 99 deletions Agent.java

This file was deleted.

114 changes: 0 additions & 114 deletions Economics_Template.tex

This file was deleted.

138 changes: 100 additions & 38 deletions Financial_Market.cpp
Original file line number Diff line number Diff line change
@@ -1,65 +1,127 @@
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <time.h>
#include <string>
#include <random>

class agent;

#include "trader.h"
#include "financial_intermediary.h"

using namespace std;

//In this program, we will model a financial market

class agent { //creates agent capable of possessing and trading assets
double wealth;
public:
agent(double x) : wealth(x){} //so far just has one public variable denoting total value of all assets
//double networth() { return wealth;}
double networth = wealth; //return wealth

};
//PODs (Possibly fold into class for additional functionality?)

/**
* Exchange wealth between two agents (know as the lender and lendee)
* @param lender - the agent giving the wealth
* @param lendee - the agent recieving the wealth
*/
void borrow_lend(agent* lender, agent* lendee);

/**
* Better Random number generator
* @param fMin Minimum nmuber on the range of possible randomly generated numbers.
* @param fMax Maximum number on the range of possible randomly generated numbers.
* @return A random number on the range of (fMin, fMax).
*/
double dRand(double fMin, double fMax)
{
std::default_random_engine generator;
std::uniform_real_distributon<double> distribution(fMin, fMax);
return distribution(generator);
}

class financial_intermediary { //creates an agent capable of possessing and trading assets, will also serve as a storage node
double wealth; //with more abilities down the line
public:
financial_intermediary(double x) : wealth(x){}
double networth = wealth;

};
int main(){
cout.precision(3); //set precision on output values....might need to retool this

void deposit(agent& A, financial_intermediary& B, double amount){ //function allowing an agent to deposit cash
double agent_wealth_init = A.networth;
double fin_wealth_init = B.networth;
srand(time(NULL)); //generate new sequence of random variables for each loop

A.networth = agent_wealth_init - amount;
B.networth = fin_wealth_init + amount;
int M, N; //number of financial intermediaries, number of nodes, respectively

}
cout << "Enter number of financial intermediaries: ";
cin >> M;

void withdraw(agent& A, financial_intermediary& B, double amount){ //function allowing an agent to deposit cash
double agent_wealth_init = A.networth;
double fin_wealth_init = B.networth;
vector<agent*> fin_int_vec {}; //placeholder for all financial intermediaries generated below

A.networth = agent_wealth_init + amount;
B.networth = fin_wealth_init - amount;
cout << "Enter number of agents: ";
cin >> N;

}
vector<agent*> trader_vec {}; //placeholder for all traders generated below

for (int i = 0; i < M; i++){
agent * bank = new financial_intermediary(i); //create new financial intermediary
fin_int_vec.push_back(bank); //add financial intermediary to storage vector
}

int main(){ //tests for me
for (int i = 0; i < N; i++){
agent * node = new trader(i); //create new trader
node->createPortfolio(); //create trader portfolio
trader_vec.push_back(node); //add trader to storage vector
}

agent spender(3.0);
financial_intermediary bank(30000.0);
for (int i = 0; i < N; i++){
fin_int_vec[0]->createAccount(trader_vec[i]); //create account for all nodes interacting with particular financial intermediary
} //leaving as separate loop so these values can change

cout << spender.networth << '\n';
cout << spender.networth + 20 << '\n';
cout << bank.networth << '\n';
for (int i = 0; i < fin_int_vec[0]->accounts.size(); i++){ //loop through accounts

deposit(spender, bank, 1);
cout << "Account pre-deposit " << fin_int_vec[0]->accounts[i].ID << ' ' << fin_int_vec[0]->accounts[i].value << '\n'; //display account information before deposit

cout << "Portfolio pre-deposit" << '\n';

cout << spender.networth << '\n';
cout << bank.networth << '\n';
for (int j = 0; j < trader_vec[i]->assets.size(); j++){ //loop through portfolio of account at hand
cout << trader_vec[i]->portfolio[j].type << ' ' //print out portfolio attribues
<< trader_vec[i]->portfolio[j].ID << ' '
<< trader_vec[i]->portfolio[j].title << ' '
<< trader_vec[i]->portfolio[j].value << '\n';
}

trader_vec[i]->deposit_cash(fin_int_vec[0], utils::dRand(0, trader_vec[i]->portfolio[0].value)); //deposit cash into account

withdraw(spender, bank, 1);
cout << "Account post-deposit " << fin_int_vec[0]->accounts[i].ID << ' ' << fin_int_vec[0]->accounts[i].value << '\n'; //display account information after deposit

cout << spender.networth << '\n';
cout << bank.networth << '\n';
cout << "Portfolio post-deposit" << '\n';

for (int j = 0; j < trader_vec[i]->assets.size(); j++){ //loop through portfolio of account at hand
cout << trader_vec[i]->portfolio[j].type << ' ' //print out portfolio attributes
<< trader_vec[i]->portfolio[j].ID << ' '
<< trader_vec[i]->portfolio[j].title << ' '
<< trader_vec[i]->portfolio[j].value << '\n';
}

trader_vec[i]->withdraw_cash(fin_int_vec[0], dRand(0, trader_vec[i]->portfolio[0].value)); //withdraw cash from account

cout << "Account post-withdrawl " << fin_int_vec[0]->accounts[i].ID << ' ' << fin_int_vec[0]->accounts[i].value << '\n'; //display account information after withdrawl

cout << "Portfolio post-withdrawl" << '\n';

for (int j = 0; j < trader_vec[i]->assets.size(); j++){ //loop through portfolio of account at hand
cout << trader_vec[i]->portfolio[j].type << ' ' //print out portfolio attributes
<< trader_vec[i]->portfolio[j].ID << ' '
<< trader_vec[i]->portfolio[j].title << ' '
<< trader_vec[i]->portfolio[j].value << '\n';
}

cout << '\n';

}

for (int i = 0; i < M; i++){
delete fin_int_vec[i]; //delete all objects
}

for (int i = 0; i < N; i++){
delete trader_vec[i]; //delete all objects
}

return 0;
}
}
Loading