Install Wallstreet via pip
masterInstall the wallstreet library using pip to begin monitoring and analyzing real-time stock and option data.
$ pip install wallstreetrepository·master·Indexed 23 days ago
https://github.com/mcdallas/wallstreetA Python 3 library for real-time monitoring and analysis of stocks and options. It provides tools to retrieve quotes via Google Finance or Yahoo Finance, download historical data as pandas DataFrames, and calculate option Greeks (Delta, Gamma, Vega, Theta, Rho) and implied volatility using the Black-Scholes model and US Treasury risk-free rates.
Install the wallstreet library using pip to begin monitoring and analyzing real-time stock and option data.
$ pip install wallstreetThe Option hierarchy (base Option class with Call and Put subclasses) follows a specific lifecycle:
Option object initially contains the entire chain but no specific contract data. You must call .set_strike(val) to select a specific contract..set_strike() populates the contract-specific fields (bid, ask, volume, etc.) and initializes a BlackandScholes object used for calculating Greeks.AttributeError: Use set_strike() method first due to the @strike_required decorator.By default, Wallstreet uses the Google Finance API. You can switch to Yahoo Finance by passing source='yahoo' to the Stock or Call constructors. Note that Yahoo Finance quotes may be delayed.
from wallstreet import Stock, Call
apple = Stock('AAPL', source='yahoo')
call = Call('AAPL', strike=apple.price, source='yahoo')Stock class to retrieve real-time quotes for a specific ticker. Attributes include price, change (currency amount), and last_trade (timestamp).The Stock.historical() method allows you to download historical data as a pandas DataFrame. This requires the pandas library to be installed. Use days_back to specify the lookback period and frequency to set the interval (e.g., 'd' for daily).
from wallstreet import Stock
s = Stock('BTC-USD')
df = s.historical(days_back=30, frequency='d')
print(df)Use Call or Put classes to analyze option contracts. You can specify the ticker, expiration date (using d, m, y arguments), and strike.
Key features:
.underlying attribute..delta(), .gamma(), .vega(), .theta(), .rho()..implied_volatility()..set_strike() to update the strike price of an existing option object..expirations to see available expiration dates..strikes to see available strike prices.The following attributes and methods are available on Call and Put objects:
Attributes:
- strike
- expiration
- underlying (underlying stock object)
- ticker
- bid
- ask
- price (option price)
- id
- exchange
- change (in currency)
- cp (percentage change)
- volume
- open_interest
- code
Methods/Properties:
- expirations (list of possible expiration dates)
- strikes (list of possible strike prices)
- set_strike()
- implied_volatility()
- delta()
- gamma()
- vega()
- theta()
- rho()The following attributes are available on a Stock object:
ticker
price
id
exchange
last_trade
change (change in currency)
cp (percentage change)The Call and Put classes allow you to access option chain data for a specific underlying stock. When initializing, you must provide the ticker, and optionally the expiration date (day, month, year).
Important: After initializing an option, you must call .set_strike(strike_price) before accessing market data (bid, ask, price) or Greeks (delta, gamma, etc.). If a strike is not found, the class will attempt to use the closest available strike unless strict=True is passed.
The BlackandScholes class implements the Black-Scholes model to calculate option prices, implied volatility, and various Greeks (Delta, Gamma, Vega, Theta, Rho).
Initialization Parameters:
S: Current stock priceK: Strike priceT: Time to expiration (in years)price: Current market price of the option (used to calculate implied volatility)r: Risk-free interest rateoption: Either 'Call' or 'Put'q: Dividend yield (defaults to 0)Upon initialization, the class automatically calculates the impvol (implied volatility) attribute.
The Stock class provides real-time data for a specific ticker symbol. By default, it uses Yahoo Finance as the data source. You can access the current price, ticker name, and historical data.
To get historical data, use the .historical() method, which returns a pandas DataFrame. This requires pandas to be installed.
The wallstreet package provides high-level classes for interacting with stock and option data. You can import the core classes directly from the top-level package:
Stock: Represents real-time stock data and attributes.Call: Represents real-time call option data and methods.Put: Represents real-time put option data and methods.