Hi,
I wanted to keep a cumulative Pandas Series with indices from day to day (say day 1 there are 3 stocks in the list and next day another stock is added to the list to make it 4 in total). I was only able to pass a list object but not Pandas Series or Pandas Dataframes. It seems that Series or Dataframes could not be appended for some reason. Any suggestions? Thank you so much!
In the following code, the all_fetched_stocks (a python list) can be extended but not the case for portfolio_series (a Pandas Series object)...
import numpy as np
import pandas as pd
portfolio_series = pd.Series(['b'], index=[symbol('SPY')])
all_fetched_stocks = list()
def preview(df):
log.info(' \n %s ' % df)
return df
def initialize(context):
fetch_csv('https://docs.google.com/spreadsheets/d/1zuFXXidaZQHdz8tZrEwAFxmxWQf0YRkBfQENlUbH2as/pub?output=csv',
date_column='Date',
pre_func = preview,
date_format='%Y/%m/%d')
schedule_function(show_fetched_assets, date_rules.every_day(), time_rules.market_open(minutes=1))
def show_fetched_assets(context, data):
for stock in data.fetcher_assets:
all_fetched_stocks.append(stock)
temp_series = pd.Series(['n'], index=[stock])
portfolio_series.append(temp_series)
log.info(len(portfolio_series))
log.info(len(all_fetched_stocks))
Many thanks! It is driving me crazy...