Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revise part 08 of the programmers' "workflows" tutorial.
- Loading branch information
1 parent
6ccdf93
commit 6c021fb
Showing
5 changed files
with
259 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#! /usr/bin/env python | ||
""" | ||
Make a line plot all price paths produced by `simAsset.R`, | ||
together with their average value at any given time. | ||
""" | ||
import csv | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
|
||
plt.style.use('ggplot') | ||
|
||
data = open('results.csv') | ||
rows = csv.reader(data) | ||
ys = [] | ||
max_y = 0 | ||
for row in rows: | ||
y = list(float(item) for item in row) | ||
max_y = max(max_y, max(y)) | ||
ys.append(y) | ||
|
||
fig = plt.figure() | ||
|
||
# plot "hairy" | ||
for y in ys: | ||
x = range(len(y)) | ||
plt.plot(x, y, linestyle='solid', color='chartreuse', alpha=(1.0/8)) | ||
|
||
avgs = [] | ||
ts = zip(*ys) | ||
N = len(ys) | ||
for t in ts: | ||
avg = sum(t) / N | ||
avgs.append(avg) | ||
plt.plot(x, avgs, linestyle='solid', linewidth=2, color='darkred', alpha=1.0) | ||
|
||
plt.ylim(0, max_y) | ||
#plt.show() | ||
|
||
fig.savefig("saplot.pdf") |
Binary file not shown.
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
Oops, something went wrong.