Question
T rading Simulator Lab using C++ 1- Note Trading stocks, currencies, futures etc involves substantial financial risk. This lab is an academic exercise and does
Trading Simulator Lab using C++
1- Note Trading stocks, currencies, futures etc involves substantial financial risk. This lab is an academic exercise and does not properly reflect many of the subtle aspects of these markets. Any strategy found or described in this lab may produce significant losses when traded on a live market.
2 - Introduction The domain concepts used in the lab will be introduced at the beginning of the lab session. You are given a handful of header files (most of them complete) and you must implement the missing methods described in those files. If the meaning of a method isnt clear from its name or brief comment, please just ask me about it. Here is a class diagram of the system:
3 - Data Files Several data files are included with this lab and more can be easily downloaded from Yahoo. Note that the data in these files is in reverse chronological order and must be revered before used in your simulator.
4 - Simulator This framework is capable of producing many different views of the results related to the simulation. For our purposes you need a simple main program that runs a simulation and displays an output like: Data file: data/rok.dat Start date: 2013-02-19 End date: 2016-03-16 Bars: 775 Trades: 18 Initial equity: 30000 Final equity: 30085 Percent profit: 4 - Simulator0.283469
5 - Strategies to Implement 5.1 - It Cant Go Any Lower, Can It? Look at one of the charts discussed in class (easily found on http://finance.yahoo.com/). It seems like a run of red (close open) bars. Implement and test a trading strategy that: Buys when flat if n (experiment with n = 1, 2, 3, 4) red bars are seen. Experiment with the number of shares to buy. When long, sells all shares after a fixed period of time (experiment with 1, 2, 4, 8, 16 days). 5.2 - Moving Average Cross Implement a strategy that buys when the 20 period simple moving average crosses above the 50 period simple moving average and sells when the reverse happens. Experiment with the number of shares. 5.3 - Your Own Implement at least 2 of your own custom trading strategies. Your strategies must be different than any other in the class.
6 - The Million Dollar Challenge Two custom strategies for each student will be tested against a pool of securities selected from the Information Technology Services and Diversified Machinery (particularly robotics-related) sectors. This sample data will include only day bars for 6-year periods starting in January 2011 and ending in December of 2016. Each strategy will be primed (process_bar without quantity_to_trade()) with one years data (January 2011 to December 2011) before trading will begin. The strategies will be allocated $100,000 (fictitious!) initial cash for the first security and the equity will be carried over to trade on the next security etc.
One winner will be selected from each CSIS3700 section. The winner will be the trading strategy that produces the greatest final equity across all of these securities. The strategy must report the correct result for get_holdings_equity() in order to be eligible for the competition. For this competition, strategies may only buy when flat and only sell when long (and must sell of their holdings when selling). No short-selling will be allowed.
7 To hand in Indicate in your submission comment which two strategies you want to include in the competition.
LAB CODE INCLUDED IN HANDOUT:
Header Files -
(#1) price_bar.h
#ifndef __CDS_PRICE_BAR_H #define __CDS_PRICE_BAR_H #include
namespace csis3700 { class price_bar { public: price_bar(std::string date_time, double open, double high, double low, double close, double adjusted_close) { this->date_time = date_time; this->open = open; this->high = high; this->low = low; this->close = close; this->adjusted_close = adjusted_close; } std::string get_date_time() const { return date_time; } double get_open() const { return open; } double get_high() const { return high; } double get_low() const { return low; }
double get_close() const { return close; }
double get_adjusted_close() const { return adjusted_close; }
private: std::string date_time; double open; double high; double low; double close; double adjusted_close; }; } #endif
(#2) simulator.h
#ifndef __CDS_SIMULATOR_H #define __CDS_SIMULATOR_H #include
namespace csis3700 { class simulator { public: /** * Create a simulator that makes trading decisions using the * supplied trading strategy. The simulator will start the * account with the specified balance of cash. */ simulator(const trading_strategy& s, double balance);
/** * Read price_bars from the supplied stream. Note that the first * line of the stream will be a header and should be ignored. * Subsequent lines will be formatted: * date/time open high low close volume adjusted_close * * Data in the stream will be in reverse chronological order. * * This method should populate the bars collection with the * contents of this stream but in forward chronological order. */ void read_bars(std::istream& is);
/** * Perform the simulation by iterating through each bar with the * following steps: * * 1) tell the strategy to process the bar * * 2) ask the strategy how many shares it wants to trade * * 3) if there is enough cash in the account and the trade matches the * current position (cannot sell more than you are holding) * 3a) create a trade object, * 3b) inform that strategy (trade_executed()) that a trade was executed, * 3c) update the cash available, * 3d) add the trade to the trades collection * */ void run();
std::vector
/** * Return the current account equity (cash plus holdings value). */ double get_equity() const;
/** * Return the number of shares held by this trading strategy. */ double get_quantity_held() const;
std::vector
#endif
(#3) trade.h
#ifndef __CDS_TRADE_H #define __CDS_TRADE_H #include
namespace csis3700 { class trade { public:
/** * A trade at the specified date/time, at the specified price, for * the specified quantity. If buy is true then this is a buy * trade, otherwise it is a sell. */ trade(std::string date_time, double price, double quantity, bool buy);
/** * Returns the price at which this trade was excecuted. */ double get_price() const { return price; }
/** * Return true if this is a buy (false otherwise). */ bool is_buy() const { return buy; }
/** * Return the number of shares bought or sold. */ double get_quantity() const { return quantity; }
/** * Return the net credit to account cash. For buy trades this * will be a negative number and for sell trades it will be * positive. */ double get_net_credit() const;
std::string get_date_time() const; private: std::string date_time; double price; double quantity; bool buy; }; }
#endif
(#4) trading_strategy.h
#ifndef __CDS_STRATEGY_H #define __CDS_STRATEGY_H #include "trade.h" #include "price_bar.h"
namespace csis3700 { class trading_strategy { public:
/** * Construct a new trading strategy. */ trading_strategy();
/** * Returns the number of shares this trading strategy currently * holds. This will be a positive number for a long position, a * negative number for a short position and zero when flat. */ double get_quantity_held() const { return quantity_held; }
/** * The simulation sends this message to tell the trading strategy * about a new bar. Each (simulated) day's bar is passed to this * strategy, one at a time, so that the stratgy can make * decisions. */ void process_bar(const price_bar& b);
/** * Return the number of shares this strategy wants to trade at the * current price. Positive number is a buy, negative is a sell (0 * for none, of course). The current cash available for trading * will be supplied as an argument. */ double quantity_to_trade(double cash) const;
/** * Once a strategy has indicated that it wants to trade (buy or * sell, see methods above), the simulation will try to execute * this trade. If the trade is successful, the strategy will be * notified by this executed method. The strategy should update * its quantity_held i-var and potentially any strategy-specific * variables. */ void executed(const trade& t);
/** * Return the equity of this strategies current holdings based on * the last adjusted close price seen. */ double get_holdings_equity() const;
/** * Return the profit made by the strategy ON ITS CURRENT HOLDINGS, * not throughout its existance. Should use the current price * (last price seen) and the price at which the shares were * purchased or sold short. */ double get_holdings_profit() const;
private:
double quantity_held; double current_unit_price; double purchase_unit_price; // You will need to add i-vars to support your strategy }; } #endif
trading strategy quantity held: double -current unit price: double -purchase unit price: double +trading strategy 0 +get quantity held0: double +process bar price bar): void +quantity to trace(double): double +executed (trade): void +get holdings equity0: double +get holdings profito: double price bar -date time: string -open: double -high: double -low: double -close: double -adjusted close: double +getters strategy bars trade -date time: string -price: double quantity: double -buy: bool +trade(string,double,double,bool) +get price0: double tis buy0: bool +get quantity 0: double +get net credito: double trades simulator -cash +simulator (trading strategy, double) tread bars (istream): boid +runo: void +get trades0: vectorStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started