Question
Day trading involves buying and subsequently selling financial instruments (Links to an external site.)Links to an external site. (e.g. stocks (Links to an external site.)Links
Day trading involves buying and subsequently selling financial instruments (Links to an external site.)Links to an external site. (e.g. stocks (Links to an external site.)Links to an external site., options (Links to an external site.)Links to an external site., futures (Links to an external site.)Links to an external site., derivatives (Links to an external site.)Links to an external site., currencies (Links to an external site.)Links to an external site.) within the same trading day (Links to an external site.)Links to an external site., such that all positions will usually be closed before the market close of the trading day. Depending on one's trading strategy, it may range from several to hundreds of orders a day. The following is a typical instrument chart showing the daily pricing of gold (per oz) back in 2012. The Y axis represents the value gold in USD ($) and the X axis, time, on 3 particular days (9/14. 9/16, and 9/17):
Write the following function taking in an integer vector (vector
int getMaxProfit(vector&prices)
Examples:
input: {1,2,4}
output: 3
note on output: buy $1, sell $2, buy $2, sell $4 => $1+$2 = $3 profit
input: {4,2,1}
output: 0
note on output: you will not be able to buy low, sell high in this pricing order => no buy, no sell => $0 profit
input: {1}
output: 0
note on output: this may be the time slice at the end of the trading day; if you buy in at $1 you lose money since you won't be able to sell it before market closes
input: {1,2,5,1,6}
output: 9
note on output: buy $1, sell $2, buy $2, sell $5, buy $1, sell $6 => $1 + $3 + $5 = $9 profit
input: {3,1,5,2,4}
output: 6
note on output: buy $1, sell $5, buy $2, sell $4 => $4 + $2 = $6 profit
You are a software engineer working for PCC, Inc. specializing in advising day traders with predicative triggers telling them when it's best time to buy/sell in a given day based on an instrument's historic data. This is a complex predicative system you are working on. All of the pricing data for this instrument are stored chronologically in a vector.
USD/oz 1785.0 24 Hour Spot Gold (Bid) Septenber 17, 2012 17:49 Sep 14 NY close 1770.50 - Sep 16 Sunday -Sep 17 Last 1762.50 www.kitco.com 1788.0 1775.0 1770.8 1765.0 1768.0 1755.0 Hong Kon on on ondon New York Globex New York Globex 1758.0 NY Time 80:00 GMT 04 88 04:00 08:00 12 00 16:00 20:00 23:59Step 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