Book Image

Python for Finance

By : Yuxing Yan
Book Image

Python for Finance

By: Yuxing Yan

Overview of this book

Table of Contents (20 chapters)
Python for Finance
About the Author
About the Reviewers

Outputting data to external files

In this section, we discuss several ways to save our data, such as saving data or estimating results to a text file, a binary file, and so on.

Outputting data to a text file

The following code will download IBM's daily price historical data and save it to a text file:

>>>from import quotes_historical_yahoo
>>>import re
>>>p = quotes_historical_yahoo(ticker, begdate, enddate,asobject=True, adjusted=True)
>>>x2= re.sub('[\(\)\{\}\.<>a-zA-Z]','', x)

Saving our data to a binary file

The following program first generates a simple array that has just three values. We save them to a binary file named tmp.bin at C:\temp\:

>>>import array
>>>import numpy as np
>>>outfile = "c:/temp/tmp.bin...