answersLogoWhite

0

! Program to read tick data (dat file) of stock prices and output one second bars to the screen with an open blank line every second.

program one_second_bar

implicit none

! Declare the variables

integer, parameter :: maxSize = 30000 ! Maximum size of dat file

integer :: n, i, time_read ! n: number of elements in dat file ; i: loop index ; time_read: time of the last read element

real, dimension(maxSize) :: stock_price ! Array to store stock prices

real :: open_price, high_price, low_price, close_price ! variables to store open, high, low, close prices

! Read the data file and store data into array

open(unit=10, file='stock_price.dat')

read(10, *) n

do i = 1, n

read(10, *) stock_price(i)

end do

close(10)

! Iterate through the array and calculate open, high, low and close prices

time_read = 0

open_price = stock_price(1)

high_price = stock_price(1)

low_price = stock_price(1)

do i = 2, n

if (i > time_read + 1) then

  write(*,*) 'Open: ', open_price, ' High: ', high_price, ' Low: ', low_price, ' Close: ', close_price

  write(*,*)

  time_read = i

  open_price = stock_price(i)

  high_price = stock_price(i)

  low_price = stock_price(i)

else

  if (stock_price(i) > high_price) then

    high_price = stock_price(i)

  else if (stock_price(i) < low_price) then

    low_price = stock_price(i)

  end if

end if

end do

! Output the last bar

close_price = stock_price(n)

write(,) 'Open: ', open_price, ' High: ', high_price, ' Low: ', low_price, ' Close: ', close_price

end program one_second_bar

User Avatar

David Denton

Lvl 10
2y ago

What else can I help you with?

Related Questions

Which of the following comparisons best isolates the impact that changes in prices of inputs and outputs have on performance?

static planning budget and flexible budget


Was a new deal program that set prices of many products to ensure fair competition?

The National Industrial Recovery Act was a New Deal program that set the prices of many products to ensure fair competition.


What program regulated industry and raised wages and prices?

emergency banking act


What is the name of the TV program about the sale of repossessed self storage treasures for sometimes ridiculous prices?

The name of the television program about the sale of repossessed self storage treasures for sometimes ridiculous prices is Storage Wars. Storage Wars airs on the channel A&amp;E and is a popular American television program.


Is Static planning budget and flexible budget or Flexible budget and actual results comparisons that best isolates the impact that changes in prices of inputs and outputs have on performance?

flexible budget and actual results


What chain auto parts store has the lowest prices?

autozone has a money back program


What is the name of nordstrom liquidation program?

Nordstrom's liquidation program is called &quot;Nordstrom Rack.&quot; This program is designed to sell off excess inventory and items from Nordstrom stores at discounted prices. It allows customers to find high-quality merchandise at lower prices while helping the company manage its inventory effectively.


What was the average price of diesel in 2006?

In 2006, the average price of diesel in the United States varied throughout the year, but it was generally around $2.80 to $3.00 per gallon. Prices were influenced by factors such as crude oil prices, refinery outputs, and seasonal demand. The year saw significant fluctuations, particularly during the summer months when prices tended to rise.


When businesses combine to create a trust their goal is to?

reduce competition and regulate prices.


What was a new deal program that set prices of many products to ensure fair competition?

The National Industrial Recovery Act was a New Deal program that set the prices of many products to ensure fair competition.


How much does the leadership programs cost?

The cost of a leadership program depends on where the program is being conducted, the length of the program, and who is conducting it. Prices vary and programs should be compared before deciding on which one to attend.


If you are using cable broadband how do you connect your laptop to internet from another area in your home?

You purchase a wireless router and short ethernet cable (some routers include the cable) and connect it to the cable modem output with the short ethernet cable, then connect the ethernet cable that was connected to your modem outputs to the wireless router outputs. This will only work if your Laptop has WiFi capability The prices of wireless router vary greatly and many can be purchased less than for retail price. Review online prices before making a purchase to prevent overpaying.