Can some one please tell me what am I doing wrong here:
import numpy as np
import pandas as pd
def initialize(context):
context.stock = sid(21508)
def handle_data(context, data):
prices = history(200, '1d', 'price')[context.stock]
I am attempting to get a time series of iShares Core S&P Small-Cap ETF.
history(200, '1d', 'price') returns a dataframe as a dictionary.
history(200, '1d', 'price'): DataFrame
dict{'2010-05-06 00:00:00+00:00': 59.64, '2010-12-16 00:00:00+00:00': 68.31, '2010-12-06 00:00:00+00:00': 66.79, '2010-09-10 00:00:00+00:00': 56.16, '2010-05-18 00:00:00+00:00': 60.68, ...}
2010-05-06 00:00:00+00:00: 59.64
2010-12-16 00:00:00+00:00: 68.31
2010-12-06 00:00:00+00:00: 66.79
2010-09-10 00:00:00+00:00: 56.16
2010-05-18 00:00:00+00:00: 60.68
2010-09-15 00:00:00+00:00: 57.59
2010-10-19 00:00:00+00:00: 61.11
2010-09-28 00:00:00+00:00: 59.2
Above dictionary object values seem correct.
BUT when I attempt to convert it to a timeseries structure by:
prices = history(200, '1d', 'price')[context.stock]
I get a timeseries with prices repeated periodically like this:
0_2010-03-23 00:00:00+00:00: 60.96
1_2010-03-24 00:00:00+00:00: 60.15
2_2010-03-25 00:00:00+00:00: 59.68
3_2010-03-26 00:00:00+00:00: 60.15
4_2010-03-29 00:00:00+00:00: 60.96
5_2010-03-30 00:00:00+00:00: 60.15
6_2010-03-31 00:00:00+00:00: 59.68
7_2010-04-01 00:00:00+00:00: 60.15
8_2010-04-05 00:00:00+00:00: 60.96
9_2010-04-06 00:00:00+00:00: 60.15
10_2010-04-07 00:00:00+00:00: 59.68
11_2010-04-08 00:00:00+00:00: 60.15
12_2010-04-09 00:00:00+00:00: 60.96
13_2010-04-12 00:00:00+00:00: 60.15
14_2010-04-13 00:00:00+00:00: 59.68
What am I doing wrong here?
Thanks!