08.02.2015 Views

Sage Reference Manual: Quantitative Finance - Mirrors

Sage Reference Manual: Quantitative Finance - Mirrors

Sage Reference Manual: Quantitative Finance - Mirrors

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Sage</strong> <strong>Reference</strong> <strong>Manual</strong>: <strong>Quantitative</strong> <strong>Finance</strong>, Release 6.1.1<br />

sage: finance.Stock(’F’).google(’Jan+3,+1978’, ’Jul+7,+2008’)[:5] # optional -- internet<br />

[<br />

3-Jan-78 0.00 1.93 1.89 1.89 1618200,<br />

4-Jan-78 0.00 1.89 1.87 1.88 2482700,<br />

5-Jan-78 0.00 1.89 1.84 1.84 2994900,<br />

6-Jan-78 0.00 1.84 1.82 1.83 3042500,<br />

9-Jan-78 0.00 1.81 1.79 1.81 3916400<br />

]<br />

Note that when startdate is too far prior to a stock’s actual start date, Google <strong>Finance</strong> defaults to a<br />

year’s worth of stock history leading up to the specified end date. For example, Apple’s (AAPL) stock<br />

history only dates back to September 7, 1984:<br />

sage: finance.Stock(’AAPL’).google(’Sep+1,+1900’, ’Jan+1,+2000’)[0:5] # optional -- internet<br />

[<br />

4-Jan-99 0.00 10.56 10.00 10.31 34031600,<br />

5-Jan-99 0.00 10.98 10.38 10.83 50360400,<br />

6-Jan-99 0.00 11.03 10.25 10.44 48160800,<br />

7-Jan-99 0.00 11.27 10.53 11.25 51036400,<br />

8-Jan-99 0.00 11.72 11.00 11.25 24240000<br />

]<br />

Here is an example where we create and get the history of a stock that is not in NASDAQ or NYSE:<br />

sage: finance.Stock("OTC:NTDOY").google(startdate="Jan+1,+2007", enddate="Jan+1,+2008")[:5]<br />

[<br />

3-Jan-07 32.44 32.75 32.30 32.44 156283,<br />

4-Jan-07 31.70 32.40 31.20 31.70 222643,<br />

5-Jan-07 30.15 30.50 30.15 30.15 65670,<br />

8-Jan-07 30.10 30.50 30.00 30.10 130765,<br />

9-Jan-07 29.90 30.05 29.60 29.90 103338<br />

]<br />

Here, we create a stock by cid, and get historical data. Note that when using historical, if a cid is specified,<br />

it will take precedence over the stock’s symbol. So, if the symbol and cid do not match, the history based<br />

on the contract id will be returned.<br />

sage: sage.finance.stock.Stock("AAPL", 22144).google(startdate=’Jan+1,+1990’)[:5] #optional<br />

[<br />

2-Jan-90 0.00 9.38 8.75 9.31 6542800,<br />

3-Jan-90 0.00 9.50 9.38 9.38 7428400,<br />

4-Jan-90 0.00 9.69 9.31 9.41 7911200,<br />

5-Jan-90 0.00 9.56 9.25 9.44 4404000,<br />

8-Jan-90 0.00 9.50 9.25 9.50 3627600<br />

]<br />

load_from_file(file)<br />

Load historical data from a local csv formatted data file. Note that no symbol data is included in Google<br />

<strong>Finance</strong>’s csv data. The csv file must be formatted in the following way, just as on Google <strong>Finance</strong>:<br />

Timestamp,Open,High,Low,Close,Volume<br />

INPUT:<br />

•file – local file with Google <strong>Finance</strong> formatted OHLC data.<br />

OUTPUT:<br />

A sequence – OHLC data.<br />

EXAMPLES:<br />

25

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!