-
Notifications
You must be signed in to change notification settings - Fork 127
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
4b627f0
commit 45a9c33
Showing
1 changed file
with
27 additions
and
22 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 |
---|---|---|
@@ -1,32 +1,37 @@ | ||
import sys | ||
import sys, os | ||
import nbformat | ||
from nbconvert.preprocessors import ExecutePreprocessor | ||
from nbconvert import HTMLExporter | ||
|
||
def tohtml(input, output=None): | ||
if output is None: | ||
output = input + ".html" | ||
def tohtml(working_directory, input, output=None): | ||
prevcwd = os.getcwd() | ||
try: | ||
os.chdir(working_directory) | ||
|
||
if output is None: | ||
output = input + ".html" | ||
|
||
print("Converting %s --> %s" % (input, output)) | ||
ep = ExecutePreprocessor(timeout=300, kernel_name='python3') | ||
print("Converting %s --> %s" % (input, output)) | ||
ep = ExecutePreprocessor(timeout=300, kernel_name='python3') | ||
|
||
with open(input) as f: | ||
nb = nbformat.read(f, as_version=4) | ||
|
||
ep.preprocess(nb, {'metadata': {'path': './'}}) | ||
with open(input) as f: | ||
nb = nbformat.read(f, as_version=4) | ||
ep.preprocess(nb, {'metadata': {'path': './'}}) | ||
|
||
#filename_output = input + ".executed.ipynb" | ||
#with open(filename_output, 'wt') as f: | ||
# nbformat.write(nb, f) | ||
#filename_output = input + ".executed.ipynb" | ||
#with open(filename_output, 'wt') as f: | ||
# nbformat.write(nb, f) | ||
|
||
exportHTML = HTMLExporter() | ||
(body, resources) = exportHTML.from_notebook_node(nb) | ||
exportHTML = HTMLExporter() | ||
(body, resources) = exportHTML.from_notebook_node(nb) | ||
|
||
with open(output, 'wt') as f: | ||
f.write(body) | ||
|
||
print("Done") | ||
with open(output, 'wt') as f: | ||
f.write(body) | ||
|
||
print("Done") | ||
finally: | ||
os.chdir(prevcwd) | ||
|
||
|
||
tohtml("binomial_option_pricing/binomial_option_pricing.ipynb") | ||
tohtml("black_litterman/black_litterman.ipynb") | ||
tohtml("binomial_option_pricing", "binomial_option_pricing.ipynb") | ||
tohtml("black_litterman", "black_litterman.ipynb") |