#include "Stock.h" #include "SimpleBuyStrategy.h" #include "SmartBuyStrategy.h" #include "RandomBuyStrategy.h" #include "RandomSellStrategy.h" #include "SimpleSellStrategy.h" #include "StopLossStrategy.h" #include int main() { Stock msft( "MSoft", 5.0 ); msft.setPrice( 5.5 ); { const unsigned int time = 1; double gain = msft.gain( time ); double price = msft.price(); cout << time <<" day gain: " << gain << endl; SimpleBuyStrategy s( time, gain-0.001, 1.0 ); long amount = s.buy( &msft, 100, 5.0, 10 ); double buyPrice = s.price(); cout << " simple buy: buy: " << amount << " at $" << buyPrice << " ($" << price << ")" << endl; } msft.setPrice( 5 ); { const unsigned int time = 1; double gain = msft.gain( time ); double price = msft.price(); cout << time <<" day gain: " << gain << endl; SmartBuyStrategy s( time, -gain -0.001, 1.0 ); long amount = s.buy( &msft, 100, 5.0, 10 ); double buyPrice = s.price(); cout << " smart buy: buy: " << amount << " at $" << buyPrice << " ($" << price << ")" << endl; } msft.setPrice( 5 ); { const unsigned int time = 1; double gain = msft.gain( time ); double price = msft.price(); cout << time <<" day gain: " << gain << endl; RandomBuyStrategy s( 1.0, 0.1, 1.0 ); for ( int i = 0; i < 5; i++) { long amount = s.buy( &msft, 100, 5.0, 10 ); double buyPrice = s.price(); cout << " random buy: buy: " << amount << " at $" << buyPrice << " ($" << price << ")" << endl; } } msft.setPrice( 5 ); { const unsigned int time = 1; double gain = msft.gain( time ); double price = msft.price(); cout << time <<" day gain: " << gain << endl; RandomSellStrategy s( 1.0, 0.1, 1.0 ); for ( int i = 0; i < 5; i++ ) { long amount = s.buy( &msft, 100, 5.0, 10 ); double buyPrice = s.price(); cout << " random sell: buy: " << amount << " at $" << buyPrice << " ($" << price << ")" << endl; } } msft.setPrice( 6 ); { const unsigned int time = 1; double gain = msft.gain( time ); double price = msft.price(); cout << time <<" day gain: " << gain << endl; SimpleSellStrategy s( 0.1 ); long amount = s.buy( &msft, 100, 5.0, 10 ); double buyPrice = s.price(); cout << " simple sell: buy: " << amount << " at $" << buyPrice << " ($" << price << ")" << endl; } msft.setPrice( 4 ); { const unsigned int time = 1; double gain = msft.gain( time ); double price = msft.price(); cout << time <<" day gain: " << gain << endl; StopLossStrategy s( 0.1 ); long amount = s.buy( &msft, 100, 5.0, 10 ); double buyPrice = s.price(); cout << " stop loss: buy: " << amount << " at $" << buyPrice << " ($" << price << ")" << endl; } msft.printHistory(); }