//========================================================================== // Author: Joshua D. Jones // Created: 4/2/99 // Revised: 4/12/99 //========================================================================== #include "..\traders\jjones.h" // Header file for jjones classes #include // Header file for time(NULL) func #include // Header file for rand() func //========================================================================== // Trader: jjones1 // // Logic: This trader looks at all the stocks each time period and buys // $1000.00 ( if he has the money ) of whichever stock has the highest // PE Ratio... it then looks at all stocks already owned and sells if their // value has increased by 10% //========================================================================== //=========================================================================== // Constructor Function // Gets Broker, Initializes DayCount, and Initializes all Asset Data //=========================================================================== jjones1::jjones1( int TraderNum ) : Trader( TraderNum) { mybroker = GetBroker(); DayCount = 0; for( int i=0; i< NUM_STOCKS; ++i){ jjones1_ad[i]->NumShares = 0; for( int j=0; j < SIM_TIME; j++) { jjones1_ad[i][j].TimeOfPurchase = -1; jjones1_ad[i][j].TimeOfSale = -1; } } }; //============================================================================ // Think Function // Finds Stock w/ highest PE, and all stocks owned which have increased by 10% //============================================================================ void jjones1::Think() { int high_pe = 0; StockData high_sd; DayCount++; // find which stock has the highest PE for( int i=0; i< NUM_STOCKS; ++i){ mybroker->GetStockInfo(i,jjones1_sd); mybroker->GetStockInfo(high_pe,high_sd); if ( jjones1_sd.PE_Ratio > high_sd.PE_Ratio ) { high_pe = jjones1_sd.TickerNumber; } } // initialize to sell none for( i=0; iGetStockInfo( i, jjones1_sd ); jjones1_ad[i][lcv].CurrentPrice = jjones1_sd.CurrentPrice; // if increased value by 10% or more if ( jjones1_ad[i][lcv].CurrentPrice > ( jjones1_ad[i][lcv].PurchasePrice * 1.10 ) ) { // mark it to sell ToSell[i].Sell = 1; ToSell[i].PurchaseTime = lcv; } } } } }; //====================================================================================== // Trade Function // Goes through and buys all stocks marked to buy, and attempts to sell ones marked to // sell //======================================================================================= int jjones1::Trade() { double cost; for( int i=0; iGetBalance(); if ( cost != mybroker->Sell( i, -1 ) ) { // successfully sold stock jjones1_ad[i][ToSell[i].PurchaseTime].TimeOfSale = DayCount; } } } for( i=0; iGetBalance() - mybroker->Buy( i,1000.00); // set proper info about stock in asset portfolio jjones1_ad[i][DayCount].Ticker = i; jjones1_ad[i][DayCount].CurrentPrice = jjones1_sd.CurrentPrice; jjones1_ad[i][DayCount].PurchasePrice = jjones1_sd.CurrentPrice; jjones1_ad[i][DayCount].CostOfPurchase = cost; jjones1_ad[i][DayCount].TimeOfPurchase = DayCount; } } return 0; }; //=========================================================================== // Trader: jjones2 // // Logic: Trader2 views stock market investing to be the same as gambling, // which is against his religion. He chooses not to play the market and will // break even //============================================================================ jjones2::jjones2( int TraderNum ) : Trader( TraderNum) { mybroker = GetBroker(); }; void jjones2::Think() { } int jjones2::Trade() { return 0; } //=========================================================================== // Trader: jjones3 // // Logic: Trader3 is a gambler... he likes to pick a random stock and just go // with it... all or nothing. //============================================================================ jjones3::jjones3( int TraderNum ) : Trader( TraderNum) { mybroker = GetBroker(); DayCount = 0; }; void jjones3::Think() { DayCount++; } int jjones3::Trade() { if ( DayCount == 1 ) { srand( time(NULL) ); // Buy a $100,000.00 of a random stock and just hold on to it // It's interesting to note that in my test runs, he wins // 4 out of 5 times. Sorta like 20/20's special where they // paired the monkey against the broker in picking. mybroker->Buy( ( rand() % ( NUM_STOCKS ) + 1 ), 100000.00 ); } return 0; } //================================================================================