#include "StopLossStrategy.h" #include "Stock.h" StopLossStrategy::StopLossStrategy( double minLoss ) : minLoss_( minLoss ) { } StopLossStrategy::~StopLossStrategy() { } long StopLossStrategy::buy( Stock* stock, double capitalAvailable, double buyPrice, long amount ) { double stockPrice = stock->price(); double gain = ( stockPrice - buyPrice ) / buyPrice; if ( -gain >= minLoss_ ) { price_ = stockPrice * 0.999; return - amount; } return 0; }