-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85237f5
commit 31a47ff
Showing
4 changed files
with
44 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module mod_arrays | ||
|
||
! Utility functions that operate on arrays. | ||
|
||
implicit none | ||
|
||
private | ||
public :: mean, reverse | ||
|
||
contains | ||
|
||
pure real function mean(x) | ||
! Returns a mean of x. | ||
real, intent(in) :: x(:) | ||
mean = sum(x) / size(x) | ||
end function mean | ||
|
||
pure function reverse(x) | ||
! Reverses the order of elements of x. | ||
real, intent(in) :: x(:) | ||
real :: reverse(size(x)) | ||
reverse = x(size(x):1:-1) | ||
end function reverse | ||
|
||
end module mod_arrays |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,33 @@ | ||
program stock_prices | ||
|
||
use mod_arrays, only: mean, reverse | ||
use mod_io, only: read_stock | ||
|
||
implicit none | ||
|
||
character(len=4), allocatable :: symbols(:) | ||
character(len=10), allocatable :: time(:) | ||
real, allocatable :: open(:), high(:), low(:), close(:), adjclose(:), volume(:) | ||
integer :: i | ||
integer :: i, im, n | ||
|
||
symbols = ['AAPL', 'AMZN', 'CRAY', 'CSCO', 'HPQ ',& | ||
'IBM ', 'INTC', 'MSFT', 'NVDA', 'ORCL'] | ||
|
||
do i = 1, size(symbols) | ||
call read_stock('data/' // trim(symbols(i)) // '.csv', time,& | ||
write(*,*) 'Symbol, Open, Close, Average, Max. growth [%]' | ||
|
||
do n = 1, size(symbols) | ||
|
||
call read_stock('data/' // trim(symbols(n)) // '.csv', time,& | ||
open, high, low, close, adjclose, volume) | ||
write(*,*) symbols(i), maxval((close - open) / open * 100) | ||
|
||
open = reverse(open) | ||
close = reverse(close) | ||
|
||
im = size(close) | ||
|
||
write(*,*) symbols(n), open(1), close(im), mean(open),& | ||
maxval((close - open) / open * 100) | ||
|
||
end do | ||
|
||
end program stock_prices |