Hi Guys, hope you guys are doing great!
It would be much appreciated if someone can guide me how to call the specific data from specific row and column. I have been trying to figure this out for more than 4 hours by reading the errors and google online. Tried multiple ways and still couldn't figure out why.
For example, i'm trying to call whether i'm holding long or short position for [GOOG], i want to call specifically to index[2], columns[0] to get the data saying that i'm holding a 'short' position on [GOOG].
I have tried multiple ways including:
context.stop_loss_df.xs(stock, 'long_short')
context.stop_loss_df.loc[stock, 'long_short']
context.stop_loss_df.get_value(stock, 'long_short')
context.stop_loss_df.get_level_values
and so on... I almost tried any method i could find online and it still doesn't return the string 'short' to me.
log.info(context.stop_loss_df) shows me this, replacing the data in the DataFrame seems fine, but retrieving seems to be a problem. Please help me. This is driving me crazy.
long_short current_price exec_price stop_loss
Equity(42950 [FB]) short 130.905 130.905 133.523
Equity(47208 [GPRO]) long 12.37 12.37 12.1226
Equity(46631 [GOOG]) short 783.53 783.53 799.201
Equity(3212 [GILD]) long 73.75 73.75 72.275
Equity(8554 [SPY]) long 210.42 210.42 206.212
this is how i label the dataframe
context.stocks = [sid(42950), sid(47208), sid(46631), sid(3212), sid(8554)]
context.stop_loss_df = pd.DataFrame(index=context.stocks, columns=['long_short','current_price', 'exec_price','stop_loss'])
this is how i replace the data within the dataframe (current_price) was defined
for stock in context.stocks:
context.stop_loss_df.loc[stock, 'long_short'] = 'long'
context.stop_loss_df.loc[stock, 'current_price'] = current_price
context.stop_loss_df.loc[stock, 'exec_price'] = current_price
context.stop_loss_df.loc[stock, 'stop_loss'] = current_price*0.98
this is how i try to retrieve my data
for stock in context.stop_loss_df:
if context.stop_loss_df.loc[stock,'long_short'] == 'long':
if data.current(stock, 'price') <= context.stop_loss_df.loc[stock, 'stop_loss']:
do_something