0

I was wondering how someone would apply a for loop to a function that scrapes options prices?

from wallstreet import Stock, Call, Put
import pandas as pd

g = Call('CQP', d=17, m=7, y=2020, strike=40)

df = g.price

print(df)


0.2

I was hoping I could create a For Loop that iterates through this spread sheet: https://docs.google.com/spreadsheets/d/1NeejZFvExsnHeH-XLIgMU8gAf8iRQYD6-5pAiTSvkKY/edit?usp=sharing

So far I have something like:

from wallstreet import Stock, Call, Put
import pandas as pd

df = pd.read_excel('C:/Users/User/Downloads/Options List.xlsx', sheet_name='Sheet1')

tickers_list = df['Ticker'].tolist()

options = pd.DataFrame(rows=tickers_list)

for ticker in tickers_list:
options[ticker] = Call(Ticker, d=Day, m=Month, y=Year, strike=Strike).prices

print(options)

I know that this is wrong but for the life of me, I cant make sense of how to run multiple variables though this thing.

  • It does but that's the hard thing about learning to write all this code, it makes sense with the example, but it's so hard to implement on your own projects. – Jacob Steenhuysen Jun 29 '20 at 18:16
  • Try to emulate what you're seeing in the link, and if you get stuck update your question with the part you can't figure out and someone should help you! – Chris Jun 29 '20 at 18:17

1 Answers1

0

I don't have this wallstreet package available to me right now to test this, but you might just be able to use wallstreet.Call.price inside of pandas.DataFrame.apply here.

from wallstreet import Stock, Call, Put
import pandas as pd

df = pd.read_excel('C:/Users/User/Downloads/Options List.xlsx', sheet_name='Sheet1')

df['Call Price'] = df.apply(
    lambda x: Call(
        x['Ticker'],
        d=x['Day'],
        m=x['Month'],
        y=x['Year'],
        strike=x['Strike']
    ).price,
    axis=1,
)


Phillyclause89
  • 674
  • 4
  • 12